Browse Source

完善报名

15954078560 3 years ago
parent
commit
51355e5a2c
1 changed files with 25 additions and 1 deletions
  1. 25 1
      application/api/controller/Index.php

+ 25 - 1
application/api/controller/Index.php

@@ -506,7 +506,31 @@ class Index extends Api
                 $this->error('余额资金异常,请联系管理员');
             }
             //给上级发送优惠券
-
+            if ($this->auth->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' => $this->auth->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,
+                        'createtime' => time()
+                    ];
+
+                    $invite_coupon_rs = Db::name('user_coupon')->insertGetId($invite_coupon_data);
+                    if (!$invite_coupon_rs) {
+                        Db::rollback();
+                        $this->error('发放优惠券失败');
+                    }
+                }
+            }
 
             Db::commit();
             $this->success('报名成功');