Bladeren bron

增加取消活动 微信退款

15954078560 2 jaren geleden
bovenliggende
commit
98c2a76e6c

+ 81 - 4
application/admin/controller/Acitve.php

@@ -4,6 +4,7 @@ namespace app\admin\controller;
 
 use app\common\controller\Backend;
 use Think\Db;
+use wxpay;
 
 /**
  * 活动管理
@@ -177,15 +178,91 @@ class Acitve extends Backend
                             }
                         } elseif ($params['status'] == 3) {
                             //活动取消
+                            //修改活动人员状态
+                            $people_rs = Db::name('active_people')->where(['active_id' => $ids, 'status' => 1])->setField(['status' => 3, 'modifystatus' => 0, 'updatetime' => time()]);
+                            if ($people_rs === false) {
+                                Db::rollback();
+                                $this->error('操作失败');
+                            }
+                            //修改活动人员信息修改表
+                            $people_modify_rs = Db::name('active_people_modify')->where(['active_id' => $ids, 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
+                            if ($people_modify_rs === false) {
+                                Db::rollback();
+                                $this->error('操作失败');
+                            }
+                            //修改活动申请取消表
+                            $refund_rs = Db::name('active_refund')->where(['active_id' => $ids, 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
+                            if ($refund_rs === false) {
+                                Db::rollback();
+                                $this->error('操作失败');
+                            }
                             //查询活动订单
-                            $active_order_list = Db::name('active_order')->where(['active_id' => $ids, 'status' => 1])->select();
+                            $active_order = Db::name('active_order'); //活动订单表
+                            $user_coupon = Db::name('user_coupon'); //用户优惠券表
+                            $sys_msg = Db::name('sys_msg'); //消息通知
+
+                            $active_order_list = $active_order->where(['active_id' => $ids, 'status' => 1])->select();
                             if ($active_order_list) {
+                                //活动订单修改信息
+                                $order_data['status'] = 3; //状态:0=待付款,1=待出行,2=已完成,3=已取消
+                                $order_data['updatetime'] = time();
+
                                 foreach ($active_order_list as &$v) {
+                                    //退还支付金额
+                                    if ($v['price'] > 0) {
+                                        $order_data['refundstatus'] = 1; //退款状态:0=无需退款,1=退款成功,2=退款失败
+                                        $order_data['refundprice'] = $v['price'];//退款金额
+                                        $order_data['refundtime'] = time();
 
+                                        if ($v['paytype'] == 0) {
+                                            //余额支付, 退回余额
+                                            $rs = create_log($v['price'], '活动取消返还', $v['user_id'], 3, $v['id']);
+                                            if ($rs != 1) {
+                                                $order_data['refundstatus'] = 2;
+                                            }
+                                        } elseif ($v['paytype'] == 1) {
+                                            //微信支付, 退回微信
+                                            //扣除用户成长值
+                                            $paygrowth = (int)config('site.paygrowth'); //每消费1元赠送成长值数量, 1元=?成长值
+                                            $balance = floor($paygrowth * $v['price']);
+                                            if ($balance > 0) {
+                                                $paygrowth_rs = create_growth_log(-$balance, '活动取消扣除', $v['user_id'], 4);
+                                            }
+                                            //退款单号
+                                            $order_data['refund_no'] = $v['refund_no'] ? : date('YmdHis', time()) . rand(10000000, 99999999);
+                                            //调用微信退款
+                                            $wxData['transaction_id'] = $v['transaction_id'];
+                                            $wxData['out_refund_no'] = $order_data['refund_no'];
+                                            $wxData['total_fee'] = (int)($v['price'] * 100);//1 微信支付 单位为分
+                                            $wxData['refund_fee'] = (int)($v['price'] * 100);//1 微信支付 单位为分
+                                            $wxData['refund_desc'] = '活动取消返还';
+//                                            require_once("Plugins/WxPay/WxPay.php");
+                                            $wxPay = new wxpay\WxPay(config('wxchatpay'));
+                                            $back = $wxPay->WxPayRefund($wxData);
+                                            if($back['return_code'] != 'SUCCESS' || $back['result_code'] != 'SUCCESS') {
+                                                $order_data['refundstatus'] = 2;
+                                            }
+                                        }
+                                    }
+                                    //修改活动订单状态
+                                    $order_rs = $active_order->where(['id' => $v['id'], 'status' => 1])->setField($order_data);
+                                    if ($order_rs === false) {
+                                        Db::rollback();
+                                        $this->error('操作失败');
+                                    }
+                                    //上级优惠券设为过期
+                                    $user_coupon->where(['active_id' => $ids, 'status' => 0])->setField('endtime', time() - 1);
+                                    //发送消息
+                                    $data = [
+                                        'user_id' => $v['user_id'],
+                                        'type' => 1,
+                                        'title' => '活动通知',
+                                        'content' => '您报名的' . $row['title'] . '活动已取消',
+                                        'createtime' => time()
+                                    ];
+                                    $sys_msg->insertGetId($data);
                                 }
                             }
-
-
                         }
                     }
 
@@ -228,7 +305,7 @@ class Acitve extends Backend
         }
         $ids = $ids ? $ids : $this->request->post("ids");
 
-        $count = Db::name('active_order')->where(['active_id' => $ids])->count('id');
+        $count = Db::name('active_order')->where(['active_id' => $ids, 'status' => ['neq', 3]])->count('id');
         if ($count) {
             $this->error('已经有人报名,不能删除');
         }

+ 1 - 1
application/api/controller/Notify.php

@@ -58,7 +58,7 @@ class Notify extends Api
                     //开启事务
                     Db::startTrans();
                     //修改报名订单状态
-                    $active_order_rs = Db::name('active_order')->where(['id' => $order_info['relation_id'], 'status' => 0])->setField(['status' => 1, 'updatetime' => time()]);
+                    $active_order_rs = Db::name('active_order')->where(['id' => $order_info['relation_id'], 'status' => 0])->setField(['status' => 1, 'updatetime' => time(), 'transaction_id' => $_data['transaction_id']]);
                     //修改报名人员信息状态
                     $active_people_rs = Db::name('active_people')->where(['order_id' => $order_info['relation_id'], 'status' => 0])->setField(['status' => 1, 'updatetime' => time()]);
                     //给上级发送优惠券

+ 2 - 0
application/api/controller/User.php

@@ -1987,6 +1987,8 @@ class User extends Api
             'user_id' => $this->auth->id,
             'price' => $info['price'],
             'number' => $info['number'],
+            'transaction_id' => $info['transaction_id'],
+            'refund_no' => date('YmdHis', time()) . rand(10000000, 99999999), //退款单号
             'refundprice' => $refundprice,
             'createtime' => time()
         ];

+ 10 - 10
extend/wxpay/WxPay.php

@@ -152,10 +152,10 @@ class WxPay {
      */
     public function WxPayRefund($d) {
         $wxConfig = $this->config;
-        $out_trade_no = $d['out_trade_no'];
-        $transaction_id = $d['trade_no'];
-        $total_fee = $d['total_amount'];// 微信支付 单位为分
-        $refund_reason = $d['refund_reason'];
+//        $out_trade_no = $d['out_trade_no'];
+//        $transaction_id = $d['trade_no'];
+//        $total_fee = $d['total_amount'];// 微信支付 单位为分
+//        $refund_reason = $d['refund_reason'];
         $nonce_str = $this->getRandChar(32);
         $data ["appid"] = $wxConfig["app_id"];
         $data ["mch_id"] = $wxConfig['mch_id'];
@@ -163,12 +163,12 @@ class WxPay {
         if ($wxConfig["refund_notify"]) {
             $data ["notify_url"] = $wxConfig["refund_notify"];
         }
-        $data ["out_trade_no"] = $out_trade_no;
-        $data ["transaction_id"] = $transaction_id;
-        $data ["out_refund_no"] = $out_trade_no;
-        $data ["total_fee"] = $total_fee;
-        $data ["refund_fee"] = $total_fee;
-        $data ['refund_desc'] = $refund_reason;
+//        $data ["out_trade_no"] = $out_trade_no;
+        $data ["transaction_id"] = $d['transaction_id'];
+        $data ["out_refund_no"] = $d['out_refund_no'];
+        $data ["total_fee"] = $d['total_fee'];
+        $data ["refund_fee"] = $d['refund_fee'];
+        $data ['refund_desc'] = $d['refund_desc'];
         $s = $this->getSign($data);
         $data ["sign"] = $s;
         $xml = $this->arrayToXml($data);

+ 1 - 1
public/assets/js/backend/recharorder.js

@@ -36,7 +36,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'purpose', title: __('Purpose'), searchList: {"1":__('Purpose 1'),"2":__('Purpose 2'),"3":__('Purpose 3')}, formatter: Table.api.formatter.normal},
                         {field: 'pay_type', title: __('Pay_type'), operate: 'LIKE'},
                         {field: 'relation_id', title: __('Relation_id')},
-                        {field: 'refund_no', title: __('Refund_no'), operate: 'LIKE'},
+                        // {field: 'refund_no', title: __('Refund_no'), operate: 'LIKE'},
                         {field: 'transaction_id', title: __('Transaction_id'), operate: 'LIKE'},
                         {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                         {field: 'pay_status', title: __('Pay_status'), searchList: {"0":__('正常'),"1":__('Pay_status 1'),"2":__('Pay_status 2'),"3":__('Pay_status 3')}, formatter: Table.api.formatter.status,