Sfoglia il codice sorgente

美团对接-商品对接

fang 1 anno fa
parent
commit
62e7508845

+ 39 - 2
app/adminapi/controller/third/ThirdGoodsController.php

@@ -21,6 +21,7 @@ use app\adminapi\lists\third\ThirdGoodsLists;
 use app\adminapi\logic\third\ThirdGoodsLogic;
 use app\adminapi\validate\third\ThirdGoodsValidate;
 use app\common\logic\ThirdOrderLogic;
+use app\common\model\third\ThirdGoods;
 
 
 /**
@@ -105,10 +106,46 @@ class ThirdGoodsController extends BaseAdminController
         return $this->data($result);
     }
 
+    /**
+     * 获取美团商品
+     * @return \think\response\Json
+     */
     public function getMeituanGoods()
     {
-        $result = ThirdOrderLogic::queryshopdeal();
-        return $this->data($result);
+        $data = [];
+        $i = 1;
+        for ($i; $i < 100; $i++){
+            $result = ThirdOrderLogic::queryshopdeal($i);
+            if(empty($result['data']['result'])){
+                break;
+            }
+            foreach ($result['data']['result'] as $item){
+                $data[] = $item;
+            }
+        }
+
+        if(!empty($data)){
+            $good_data = [];
+            $dealGroupIds = array_column($data, 'dealGroupId');
+            $product_ids = ThirdGoods::whereIn('product_id', $dealGroupIds)->column('product_id');
+            foreach ($data as $key=>$items){
+                if(in_array($items['dealGroupId'], $product_ids)){
+                    unset($data[$key]);
+                }
+                $good_data[] = [
+                    'third_type' => 1,
+                    'goods_id' => 0,
+                    'product_id' => $items['dealGroupId'],
+                    'product_name' => $items['title'],
+                    'product_price' => $items['price'],
+                ];
+            }
+
+            if(!empty($good_data)){
+                $result = ThirdGoodsLogic::addMeituanGoods($good_data);
+            }
+        }
+        return $this->success('同步成功', [], 1, 1);
     }
 
 

+ 20 - 0
app/adminapi/logic/third/ThirdGoodsLogic.php

@@ -57,6 +57,26 @@ class ThirdGoodsLogic extends BaseLogic
         }
     }
 
+    /**
+     * 批量新增
+     * @param $data
+     * @return bool
+     */
+    public static function addMeituanGoods($data)
+    {
+        Db::startTrans();
+        try {
+            $ThirdGoods = new ThirdGoods();
+            $ThirdGoods->saveAll($data);
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
 
     /**
      * @notes 编辑

+ 2 - 2
app/common/logic/ThirdOrderLogic.php

@@ -66,6 +66,7 @@ class ThirdOrderLogic extends BaseLogic
     public static function orderhandle(array $order)
     {
         $message = json_decode($order['message'], true);
+        dd($message);
         //查询用户是否存在
         $userName = $message['userName'];
         $mobile = $message['mobile'];
@@ -460,8 +461,7 @@ class ThirdOrderLogic extends BaseLogic
         ];
         $sign_data = self::get_sign(self::assessKey, $data);
         $data['sign'] = $sign_data;
-        $result = http_request($url,http_build_query($data));
-        dd($result);
+        return http_request($url,http_build_query($data));
     }
 
 }