浏览代码

自动取消超时未支付的活动订单 消息推送

15954078560 2 年之前
父节点
当前提交
b0b0d4e1ef
共有 2 个文件被更改,包括 103 次插入2 次删除
  1. 101 0
      application/api/controller/Notify.php
  2. 2 2
      application/api/controller/User.php

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

@@ -310,4 +310,105 @@ class Notify extends Api
         echo $pay->success();
     }
 
+    //自动取消超时未支付的活动订单
+    public function cancelorder() {
+        set_time_limit(0);
+
+        $where = array(
+            'status' => 0,
+            'createtime' => ['lt', time() - 1920], //32分钟之前
+        );
+        $active_order = Db::name('active_order');
+        $list = $active_order->where($where)->limit(200)->select();
+
+        if (!$list) {
+            echo 'mei shu ju';
+            die;
+        }
+
+
+        $active_people = Db::name('active_people');
+        $active_people_modify = Db::name('active_people_modify');
+        $active = Db::name('active');
+
+        foreach ($list as &$v) {
+            //开启事务
+            Db::startTrans();
+            //修改订单信息
+            $rs = $active_order->where(['id' => $v['id'], 'status' => 0])->setField('status', 3);
+            if (!$rs) {
+                Db::rollback();
+                continue;
+            }
+            //修改活动人员
+            $rt = $active_people->where(['order_id' => $v['id'], 'status' => 0])->setField(['status' => 3, 'modifystatus' => 0]);
+            if (!$rt) {
+                Db::rollback();
+                continue;
+            }
+            //修改活动人员修改记录
+            $res = $active_people_modify->where(['order_id' => $v['id'], 'status' => 0])->setField('status', 2);
+            if ($res === false) {
+                Db::rollback();
+                continue;
+            }
+            //减少活动已报名人数
+            $active_info = $active->find($v['active_id']);
+            $currentperson = $active_info['currentperson'] - $v['number'];
+            $active_rs = $active->where(['id' => $v['active_id'], 'currentperson' => $active_info['currentperson']])->setField('currentperson', $currentperson);
+            if (!$active_rs) {
+                Db::rollback();
+                continue;
+            }
+
+            Db::commit();
+        }
+
+        echo 'wan bi';
+        die;
+    }
+
+    //消息推送 我报名参加活动的前一天会提前推送消息,时间 地点 及一些提醒
+    public function sysmsg() {
+        set_time_limit(0);
+
+        $where = array(
+            'starttime' => ['elt', time() + 86400], //活动开始前一天
+            'msgstatus' => 0,
+            'status' => ['neq', 3]
+        );
+
+        $active = Db::name('active');
+        $list = $active->where($where)->limit(200)->select();
+
+        if (!$list) {
+            echo 'mei shu ju';
+            die;
+        }
+
+        $active_order = Db::name('active_order');
+        $sys_msg = Db::name('sys_msg'); //系统消息
+
+        $data['type'] = 1;
+        $data['title'] = '活动通知';
+        $data['createtime'] = time();
+        foreach ($list as &$v) {
+            //修改活动消息通知状态
+            $active->where(['id' => $v['id']])->setField('msgstatus', 1);
+            //发送通知
+            $data['content'] = '您报名的' . $v['title'] . '活动即将开始,请规划好您的时间。活动集合时间:' . date('Y-m-d H:i', $v['collectiontime']) . ',活动集合地点:' . $v['collectionplace'];
+            //查询报名用户id
+            $user_ids = $active_order->where(['active_id' => $v['id'], 'status' => 1])->column('user_id');
+            if ($user_ids) {
+                foreach ($user_ids as &$va) {
+                    $data['user_id'] = $va;
+                    $sys_msg->insertGetId($data);
+                }
+            }
+        }
+
+        echo 'wan bi';
+        die;
+    }
+
 }

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

@@ -1811,7 +1811,7 @@ class User extends Api
         }
 
         Db::commit();
-        $this->success('修改成功');
+        $this->success('修改成功,请等待审核');
     }
 
     //取消订单
@@ -1976,7 +1976,7 @@ class User extends Api
             $this->error('申请退款失败');
         }
 
-        $this->success('申请退款成功');
+        $this->success('申请退款成功,请等待审核');
     }