浏览代码

订单核销,结算奖金

lizhen_gitee 7 月之前
父节点
当前提交
f6d74e38ad

+ 1 - 1
addons/unishop/controller/Order.php

@@ -230,7 +230,7 @@ class Order extends Base
             }
 
             $orderModel = new \addons\unishop\model\Order();
-            $result = $orderModel->createOrder($this->auth->id, $data);
+            $result = $orderModel->createOrder($this->auth->id, $data, $this->auth->intro_uid);
 
             Db::commit();
 

+ 3 - 1
addons/unishop/model/Order.php

@@ -239,7 +239,7 @@ class Order extends Model
      * @return int
      * @throws \Exception
      */
-    public function createOrder($userId, $data)
+    public function createOrder($userId, $data, $intro_uid)
     {
         $data['userId'] = $userId;
 
@@ -283,6 +283,8 @@ class Order extends Model
             'booktime' => $data['booktime'] ?? '',
             'book_realname' => $data['book_realname'] ?? '',
             'book_mobile' => $data['book_mobile'] ?? '',
+
+            'intro_uid' => $intro_uid,
         ]);
 
 

+ 39 - 5
application/api/controller/Hexiao.php

@@ -18,6 +18,8 @@ class Hexiao extends Api
     //order_no:2024090466d7c9d5abb1c1
     public function order_info()
     {
+        if($this->auth->group_id != 3){$this->error('你是不是来错地方了?');}
+
         $code = input('code','');
         if(strpos($code,'order_hexiao_no|') !== 0){
             $this->error('识别不到的订单');
@@ -122,36 +124,68 @@ class Hexiao extends Api
 
     //完成核销动作
     public function hexiao(){
+        if($this->auth->group_id != 3){$this->error('你是不是来错地方了?');}
 //        $order_id = input('order_id', 0);
 //        $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
         $out_trade_no = input('out_trade_no','');
 
-        $orderModel = new \addons\unishop\model\Order();
-        $order = $orderModel->where(['out_trade_no' => $out_trade_no])->find();
+        Db::startTrans();
+        $order = Db::name('unishop_order')->where(['out_trade_no' => $out_trade_no])->lock(true)->find();
 
         if (!$order) {
+            Db::rollback();
             $this->error('不存在的订单');
         }
 
         if($order['status'] != 1){
+            Db::rollback();
             $this->error('非正常的订单');
         }
         if($order['have_paid'] == 0){
+            Db::rollback();
             $this->error('未支付的订单');
         }
         if($order['have_received'] != 0){
+            Db::rollback();
             $this->error('该订单已核销');
         }
 
+        $update = [
+            'have_received' => time(),
+            'hexiao_uid'    => $this->auth->id,
+        ];
+        $order_rs = Db::name('unishop_order')->where('id',$order['id'])->update($update);
+        if($order_rs === false){
+            Db::rollback();
+            $this->error('核销失败');
+        }
+
+        //给推广人结算
+        if($order['intro_uid']){
+
+            $bili = config('site.unishop_order_hexiao_bili');
 
-        $order->have_received = time();
-        $order->hexiao_uid    = $this->auth->id;
-        $order->save();
+            $money = bcdiv(bcmul($order['total_price'],$bili,2),100,2);
+
+            if($money > 0){
+                $rs_wallet = model('Wallet')->lockChangeAccountRemain($order['intro_uid'],'money',$money,10,'推广订单:'.$out_trade_no,'unishop_order',$order['id']);
+                if($rs_wallet['status']===false)
+                {
+                    Db::rollback();
+                    $this->error($rs_wallet['msg']);
+                }
+            }
+
+        }
+
+        Db::commit();
         $this->success('核销成功');
     }
 
     //核销记录
     public function order_list(){
+        if($this->auth->group_id != 3){$this->error('你是不是来错地方了?');}
+
         $orderModel = new \addons\unishop\model\Order();
 
         $condition = [

+ 5 - 1
application/api/controller/Userintro.php

@@ -52,6 +52,8 @@ class Userintro extends Api
 
     //生成视频分享海报
     public function shareposter() {
+        if($this->auth->group_id != 2){$this->error('你是不是来错地方了?');}
+
         $inviteimage = $this->mini_code($this->auth->id,'',$this->auth->username);
 
         $data = [
@@ -118,7 +120,9 @@ class Userintro extends Api
 
     //我邀请的人列表
     public function myintro_list(){
-        $list = Db::name('user')->field('id,mobile,username,nickname,avatar,createtime')->where('intro_uid',$this->auth->id)->autopage()->select();
+        if($this->auth->group_id != 2){$this->error('你是不是来错地方了?');}
+
+        $list = Db::name('user')->field('id,nickname,avatar,createtime')->where('intro_uid',$this->auth->id)->autopage()->select();
         $list = list_domain_image($list,['avatar']);
 
         $this->success('success',$list);