|
@@ -15,7 +15,7 @@ class Notify extends Api
|
|
|
protected $noNeedLogin = ['*'];
|
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
|
- // 定单支付回调
|
|
|
+ // 支付回调
|
|
|
public function notify() {
|
|
|
// require_once($_SERVER['DOCUMENT_ROOT'] . "/Plugins/WxPay/WxPay.php");
|
|
|
$wxPay = new wxpay\WxPay();
|
|
@@ -25,13 +25,13 @@ class Notify extends Api
|
|
|
//验证成功
|
|
|
if ($flag['status']) {
|
|
|
if ($flag['data']['return_code'] == 'SUCCESS' && $flag['data']['result_code'] == 'SUCCESS') {
|
|
|
- $total_fee = trim($flag['data']['total_fee']); //支付的金额, 单位:分
|
|
|
+ $total_fee = trim($flag['data']['total_fee']) / 100; //支付的金额, 单位:分转成元
|
|
|
$order_sn = trim($flag['data']['out_trade_no']);//商家订单号
|
|
|
|
|
|
- $PayResult = M('PayResult');
|
|
|
- $where['out_trade_no'] = $order_sn;
|
|
|
+ $PayResult = Db::name('rechar_order');
|
|
|
+ $where['order_no'] = $order_sn;
|
|
|
$order_info = $PayResult->where($where)->find();
|
|
|
- if ($order_info['total_amount'] != $total_fee) {
|
|
|
+ if ($order_info['money'] != $total_fee) {
|
|
|
$r_arr['return_code'] = 'FAIL';
|
|
|
$r_arr['return_msg'] = '回调失败';
|
|
|
echo $wxPay->arrayToXml($r_arr);
|
|
@@ -44,35 +44,112 @@ class Notify extends Api
|
|
|
die;
|
|
|
}
|
|
|
|
|
|
- //查询订单信息
|
|
|
- $order_time = M('Order')->field('shop_id, add_time, arrive_time')->where(['order_id' => $order_info['order_id'], 'user_id' => $order_info['user_id'], 'order_status' => 0])->find();
|
|
|
- $order_data = [
|
|
|
- 'order_status' => 1,
|
|
|
- 'add_time' => time(),
|
|
|
-// 'arrive_time' => $order_time['arrive_time'] + time() - $order_time['add_time']
|
|
|
- ];
|
|
|
-
|
|
|
- //验证成功, 修改订单状态
|
|
|
- $results = M('Order')->where(['order_id' => $order_info['order_id'], 'user_id' => $order_info['user_id'], 'order_status' => 0])->setField($order_data);
|
|
|
- if (!$results) {
|
|
|
- $_data['pay_status'] = $order_info['type'];
|
|
|
- } else {
|
|
|
- //给商家发消息
|
|
|
- $shop_user_id = M('Shop')->where(['shop_id' => $order_time['shop_id']])->getField('user_id');
|
|
|
+ //构建支付订单处理结果信息
|
|
|
+ $_data['transaction_id'] = trim($flag['data']['transaction_id']); //微信交易凭证
|
|
|
+ $_data['status'] = 1;
|
|
|
+ $_data['updatetime'] = time();
|
|
|
+
|
|
|
+ //支付订单类型
|
|
|
+ if ($order_info['purpose'] == 1) {
|
|
|
+ //查询订单
|
|
|
+ $active_order = Db::name('active_order')->find($order_info['relation_id']);
|
|
|
+ //开启事务
|
|
|
+ Db::startTrans();
|
|
|
+ //修改报名订单状态
|
|
|
+ $active_order_rs = Db::name('active_order')->where(['id' => $order_info['relation_id'], 'status' => 0])->setField(['status' => 1, 'updatetime' => time()]);
|
|
|
+ //修改报名人员信息状态
|
|
|
+ $active_people_rs = Db::name('active_people')->where(['order_id' => $order_info['relation_id'], 'status' => 0])->setField(['status' => 1, 'updatetime' => time()]);
|
|
|
+ //给上级发送优惠券
|
|
|
+ $user_info = Db::name('user')->find($order_info['user_id']);
|
|
|
+ //发放优惠券状态
|
|
|
+ $invite_coupon_rs = true;
|
|
|
+ if ($user_info['pre_user_id']) {
|
|
|
+ //查询报名活动优惠券
|
|
|
+ $invite_coupon = Db::name('coupon')->where(['purpose' => 5, 'status' => 1])->order('weigh desc, id desc')->find();
|
|
|
+ if ($invite_coupon) {
|
|
|
+ $invite_coupon_data = [
|
|
|
+ 'user_id' => $user_info['pre_user_id'],
|
|
|
+ 'coupon_id' => $invite_coupon['id'],
|
|
|
+ 'title' => $invite_coupon['title'],
|
|
|
+ 'desc' => $invite_coupon['desc'],
|
|
|
+ 'type' => $invite_coupon['type'],
|
|
|
+ 'money' => $invite_coupon['money'],
|
|
|
+ 'minmoney' => $invite_coupon['minmoney'],
|
|
|
+ 'purpose' => $invite_coupon['purpose'],
|
|
|
+ 'starttime' => time(),
|
|
|
+ 'endtime' => time() + $invite_coupon['effectiveday'] * 86400,
|
|
|
+ 'active_id' => $active_order['active_id'],
|
|
|
+ 'order_id' => $active_order['id'],
|
|
|
+ 'createtime' => time()
|
|
|
+ ];
|
|
|
+
|
|
|
+ $invite_coupon_rs = Db::name('user_coupon')->insertGetId($invite_coupon_data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //活动标题
|
|
|
+ $active_title = Db::name('active')->where(['id' => $active_order['active_id']])->value('title');
|
|
|
+ //发送消息
|
|
|
$data = [
|
|
|
- 'user_id' => $shop_user_id,
|
|
|
- 'title' => '新订单',
|
|
|
- 'content' => '您有新的订单,请注意查看!',
|
|
|
- 'create_time' => time()
|
|
|
+ 'user_id' => $order_info['user_id'],
|
|
|
+ 'type' => 1,
|
|
|
+ 'title' => '活动通知',
|
|
|
+ 'content' => '您已成功报名' . $active_title . '活动',
|
|
|
+ 'createtime' => time()
|
|
|
];
|
|
|
- M('UserAuditNotice')->add($data);
|
|
|
- $extra['type'] = '6';
|
|
|
- jPushShop(C('WEB_TITLE'), '您有新的订单,请注意查看!', $shop_user_id, NULL, $extra);
|
|
|
+ $sys_rs = Db::name('sys_msg')->insertGetId($data);
|
|
|
+
|
|
|
+ if ($active_order_rs && $active_people_rs && $invite_coupon_rs && $sys_rs) {
|
|
|
+ Db::commit();
|
|
|
+ } else {
|
|
|
+ Db::rollback();
|
|
|
+ $_data['pay_status'] = 1; //回调状态: 1=支付订单回调失败,2=充值回调失败,3=开通会员回调失败
|
|
|
+ }
|
|
|
+ } elseif ($order_info['purpose'] == 2) {
|
|
|
+ //充值
|
|
|
+ //查询充值信息
|
|
|
+ $recharge = Db::name('recharge')->find($order_info['relation_id']);
|
|
|
+ //开启事务
|
|
|
+ Db::startTrans();
|
|
|
+ //增加用户余额
|
|
|
+ $rs = create_log($recharge['price'], '充值', $order_info['user_id'], 1, $order_info['id']);
|
|
|
+ //发放优惠券状态
|
|
|
+ $invite_coupon_rs = true;
|
|
|
+ if ($recharge['coupon_id'] && $recharge['couponnum'] > 0) {
|
|
|
+ //查询报名活动优惠券
|
|
|
+ $invite_coupon = Db::name('coupon')->where(['id' => $recharge['coupon_id'], 'purpose' => 0, 'status' => 1])->find();
|
|
|
+ if ($invite_coupon) {
|
|
|
+ $invite_coupon_data = [
|
|
|
+ 'user_id' => $order_info['user_id'],
|
|
|
+ 'coupon_id' => $invite_coupon['id'],
|
|
|
+ 'title' => $invite_coupon['title'],
|
|
|
+ 'desc' => $invite_coupon['desc'],
|
|
|
+ 'type' => $invite_coupon['type'],
|
|
|
+ 'money' => $invite_coupon['money'],
|
|
|
+ 'minmoney' => $invite_coupon['minmoney'],
|
|
|
+ 'purpose' => $invite_coupon['purpose'],
|
|
|
+ 'starttime' => time(),
|
|
|
+ 'endtime' => time() + $invite_coupon['effectiveday'] * 86400,
|
|
|
+ 'active_id' => 0,
|
|
|
+ 'order_id' => 0,
|
|
|
+ 'createtime' => time()
|
|
|
+ ];
|
|
|
+
|
|
|
+ for ($i=1; $i<=$recharge['couponnum']; $i++) {
|
|
|
+ $invite_coupon_rs = Db::name('user_coupon')->insertGetId($invite_coupon_data);
|
|
|
+ if (!$invite_coupon_rs) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($rs != 1 && $invite_coupon_rs) {
|
|
|
+ Db::commit();
|
|
|
+ } else {
|
|
|
+ Db::rollback();
|
|
|
+ $_data['pay_status'] = 2; //回调状态: 1=支付订单回调失败,2=充值回调失败,3=开通会员回调失败
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- $_data['trade_no'] = trim($flag['data']['transaction_id']); //微信交易凭证
|
|
|
- $_data['status'] = 1;
|
|
|
- $_data['pay_time'] = time();
|
|
|
$PayResult->where($where)->save($_data);
|
|
|
|
|
|
$r_arr['return_code'] = 'SUCCESS';
|