Browse Source

赠送RWA接口优化

xiaodong 2 days ago
parent
commit
cc75b31fb8
2 changed files with 39 additions and 15 deletions
  1. 36 13
      application/api/controller/Chabao.php
  2. 3 2
      application/common/model/ProductOrder.php

+ 36 - 13
application/api/controller/Chabao.php

@@ -158,30 +158,53 @@ class Chabao extends Api
         $order_model = new ProductOrder();
         $data = $this->params['data'];
         $mobile_list = array_column($data, 'mobile');
+        $order_id_arr = array_column($data, 'order_id');
+        $order_id_arr = array_map(function($item) {
+            return 'CFB_' . $item; // 自动将数字转为字符串
+        }, $order_id_arr);
+        
         $user = $userModel->whereIn('phone', $mobile_list)->field('phone,id')->select();
-
+        $product_arr = $order_model->whereIn('order_id', $order_id_arr)->column('order_id');
+        $add_data=[];
+        $ret_data=[];
         foreach ($data as &$item) {
-            $item['gift_record_type'] = 2;
-            $item['reason'] = '手机号未注册';
-            foreach($user as &$item_1){
-                if($item['mobile']==$item_1['phone']){
-                    $ret = $order_model->setGiverwagoods(101, 0, $item['product_id'], $item_1['id'], $order_model::Airdrop);
-                    if ($ret) {
+            
+            $item_order_id='CFB_'.$item['order_id'];
+            if(!in_array($item_order_id,$product_arr)){
+                foreach($user as &$item_1){
+                    if($item['mobile']==$item_1['phone']){
+                        $ret = $order_model->setGiverwagoods('CFB_'.$item['order_id'], 0, $item['product_id'], $item_1['id'], $order_model::Airdrop);
+                        $add_data[]=$ret;
+                        // if ($ret) {
+                        //     $item['gift_record_type'] = 1;
+                        //     $item['reason'] = '赠送RWA茶成功';
+                            
+                        // } else {
+                        //     $item['gift_record_type'] = 0;
+                        //     $item['reason'] = '赠送RWA茶失败';
+                        // }
                         $item['gift_record_type'] = 1;
                         $item['reason'] = '赠送RWA茶成功';
+                        break;
+                    }else{
+                        $item['gift_record_type'] = 2;
+                        $item['reason'] = '手机号未注册';
                         
-                    } else {
-                        $item['gift_record_type'] = 0;
-                        $item['reason'] = '赠送RWA茶失败';
                     }
-                    break;
                 }
+                $item['order_id']=(int)$item['order_id'];
+                $ret_data[]=$item;
+            }else{
+                // $item['order_id']=(int)$item['order_id'];
+                // $item['gift_record_type'] = 3;
+                // $item['reason'] = '已经赠送';
             }
+            
         }
-
+        $order_model->saveAll($add_data);
         unset($mobile_list);
         unset($user);
 
-        $this->success('赠送RWA茶', $data);
+        $this->success('赠送RWA茶', $ret_data);
     }
 }

+ 3 - 2
application/common/model/ProductOrder.php

@@ -305,7 +305,7 @@ class ProductOrder extends Model
     }
 
     //抢购下单:未选择地区购买
-    public static function setGiverwagoods($orderId, $price, $productId, $uid, $typeId): bool
+    public function setGiverwagoods($orderId, $price, $productId, $uid, $typeId)
     {
         //抢购订单
         $time = time();
@@ -326,6 +326,7 @@ class ProductOrder extends Model
             'create_time' => $time,
             'update_time' => $time
         ];
-        return self::insert($data);
+        return $data;
+        // return self::insert($data);
     }
 }