Parcourir la source

增加任务完成, 任务取消定时任务

15954078560 il y a 2 ans
Parent
commit
f32a2016ff

+ 1 - 1
application/admin/view/banner/add.html

@@ -23,7 +23,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Url')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-url" data-rule="required" class="form-control" name="row[url]" type="text" value="">
+            <input id="c-url" data-rule="" class="form-control" name="row[url]" type="text" value="">
         </div>
     </div>
     <div class="form-group">

+ 1 - 1
application/admin/view/banner/edit.html

@@ -23,7 +23,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Url')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-url" data-rule="required" class="form-control" name="row[url]" type="text" value="{$row.url|htmlentities}">
+            <input id="c-url" data-rule="" class="form-control" name="row[url]" type="text" value="{$row.url|htmlentities}">
         </div>
     </div>
     <div class="form-group">

+ 185 - 0
application/api/controller/Notify.php

@@ -455,4 +455,189 @@ class Notify extends Api
         echo 'wan bi';
         die;
     }
+    
+    //自动结束已完成订单
+    public function finishorder() {
+        set_time_limit(0);
+
+        $where = array(
+            'status' => 1,
+            'endtime' => ['lt', time()]
+        );
+
+        $active = Db::name('active');
+        $list = $active->where($where)->limit(100)->select();
+
+        if (!$list) {
+            echo 'mei shu ju';
+            die;
+        }
+
+        $active_order = Db::name('active_order');
+        $active_people = Db::name('active_people');
+        $active_people_modify = Db::name('active_people_modify');
+        $active_refund = Db::name('active_refund');
+
+        foreach ($list as &$v) {
+            //开启事务
+            Db::startTrans();
+            //活动结束
+            $active_rs = $active->where(['id' => $v['id'], 'status' => 1])->setField(['status' => 2, 'updatetime' => time()]);
+            if (!$active_rs) {
+                Db::rollback();
+                continue;
+            }
+            //修改活动订单状态
+            $order_rs = $active_order->where(['active_id' => $v['id'], 'status' => 1])->setField(['status' => 2, 'updatetime' => time()]);
+            if ($order_rs === false) {
+                Db::rollback();
+                continue;
+            }
+            //修改活动人员状态
+            $people_rs = $active_people->where(['active_id' => $v['id'], 'status' => 1])->setField(['status' => 2, 'modifystatus' => 0, 'updatetime' => time()]);
+            if ($people_rs === false) {
+                Db::rollback();
+                continue;
+            }
+            //修改活动人员信息修改表
+            $people_modify_rs = $active_people_modify->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
+            if ($people_modify_rs === false) {
+                Db::rollback();
+                continue;
+            }
+            //修改活动申请取消表
+            $refund_rs = $active_refund->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
+            if ($refund_rs === false) {
+                Db::rollback();
+                continue;
+            }
+
+            Db::commit();
+        }
+
+        echo 'wan bi';
+        die;
+    }
+    
+    //自动取消未成行订单
+    public function cancelminpeopleorder() {
+        set_time_limit(0);
+
+        $where = array(
+            'status' => 0,
+            'signupendtime' => ['lt', time()]
+        );
+
+        $active = Db::name('active');
+        $list = $active->where($where)->limit(100)->select();
+
+        if (!$list) {
+            echo 'mei shu ju';
+            die;
+        }
+
+        $active_order = Db::name('active_order');
+        $active_people = Db::name('active_people');
+        $active_people_modify = Db::name('active_people_modify');
+        $active_refund = Db::name('active_refund');
+        $user_coupon = Db::name('user_coupon'); //用户优惠券表
+        $sys_msg = Db::name('sys_msg'); //消息通知
+
+        foreach ($list as &$v) {
+            //开启事务
+            Db::startTrans();
+            //活动结束
+            $active_rs = $active->where(['id' => $v['id'], 'status' => 0])->setField(['status' => 3, 'updatetime' => time()]);
+            if (!$active_rs) {
+                Db::rollback();
+                continue;
+            }
+            //修改活动人员状态
+            $people_rs = $active_people->where(['active_id' => $v['id'], 'status' => 1])->setField(['status' => 3, 'modifystatus' => 0, 'updatetime' => time()]);
+            if ($people_rs === false) {
+                Db::rollback();
+                continue;
+            }
+            //修改活动人员信息修改表
+            $people_modify_rs = $active_people_modify->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
+            if ($people_modify_rs === false) {
+                Db::rollback();
+                continue;
+            }
+            //修改活动申请取消表
+            $refund_rs = $active_refund->where(['active_id' => $v['id'], 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
+            if ($refund_rs === false) {
+                Db::rollback();
+                continue;
+            }
+            //查询活动订单
+            $active_order_list = $active_order->where(['active_id' => $v['id'], 'status' => 1])->select();
+            if ($active_order_list) {
+                //活动订单修改信息
+                $order_data['status'] = 3; //状态:0=待付款,1=待出行,2=已完成,3=已取消
+                $order_data['updatetime'] = time();
+
+                foreach ($active_order_list as &$vv) {
+                    //退还支付金额
+                    if ($vv['price'] > 0) {
+                        $order_data['refundstatus'] = 1; //退款状态:0=无需退款,1=退款成功,2=退款失败
+                        $order_data['refundprice'] = $vv['price'];//退款金额
+                        $order_data['refundtime'] = time();
+
+                        if ($vv['paytype'] == 0) {
+                            //余额支付, 退回余额
+                            $rs = create_log($vv['price'], '活动取消返还', $vv['user_id'], 3, $vv['id']);
+                            if ($rs != 1) {
+                                $order_data['refundstatus'] = 2;
+                            }
+                        } elseif ($vv['paytype'] == 1) {
+                            //微信支付, 退回微信
+                            //扣除用户成长值
+                            $paygrowth = (int)config('site.paygrowth'); //每消费1元赠送成长值数量, 1元=?成长值
+                            $balance = floor($paygrowth * $vv['price']);
+                            if ($balance > 0) {
+                                $paygrowth_rs = create_growth_log(-$balance, '活动取消扣除', $vv['user_id'], 4, $vv['id']);
+                            }
+                            //退款单号
+                            $order_data['refund_no'] = $vv['order_sn'];
+                            //调用微信退款
+                            $wxData['transaction_id'] = $vv['transaction_id'];
+                            $wxData['out_refund_no'] = $order_data['refund_no'];
+                            $wxData['total_fee'] = (int)($vv['price'] * 100);//1 微信支付 单位为分
+                            $wxData['refund_fee'] = (int)($vv['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' => $vv['id'], 'status' => 1])->setField($order_data);
+                    if ($order_rs === false) {
+                        Db::rollback();
+                        continue;
+                    }
+                    //上级优惠券设为过期
+                    $user_coupon->where(['active_id' => $vv['id'], 'status' => 0])->setField('endtime', time() - 1);
+                    //发送消息
+                    $data = [
+                        'user_id' => $vv['user_id'],
+                        'type' => 1,
+                        'title' => '活动通知',
+                        'content' => '您报名的' . $v['title'] . '活动已取消',
+                        'createtime' => time()
+                    ];
+                    $sys_msg->insertGetId($data);
+                }
+            }
+
+            Db::commit();
+        }
+
+        echo 'wan bi';
+        die;
+    }
 }