Browse Source

美团优化

shish 3 years ago
parent
commit
8519cd8961

+ 4 - 0
app-hd/controllers/GoodsController.php

@@ -149,6 +149,10 @@ class GoodsController extends BaseController
         $data['shopId'] = $this->shopId ?? 0;
         $data['flower'] = $info['flower'] ?? 0;
 
+        if (isset($info['spu']) && !empty($info['spu'])) {
+            util::fail('美团商品暂时不能修改,请在美团APP上修改');
+        }
+
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {

+ 289 - 17
app-hd/controllers/MtController.php

@@ -5,6 +5,7 @@ namespace hd\controllers;
 use biz\shop\classes\ShopExtClass;
 use bizHd\custom\classes\CustomClass;
 use bizHd\goods\classes\CategoryClass;
+use bizHd\goods\classes\GoodsCategoryClass;
 use bizHd\goods\classes\GoodsClass;
 use bizHd\meituan\classes\MtOrderClass;
 use bizHd\order\classes\OrderClass;
@@ -26,11 +27,294 @@ class MtController extends PublicController
 
     public $guestAccess = [];
 
+    public function actionGoodsAdd()
+    {
+        $post = Yii::$app->request->post();
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            if (isset($post['retail_data']) == false) {
+                noticeUtil::push("美团添加商品,通知我们时出错了,没有获取到相应信息", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $retailData = $post['retail_data'];
+            $retail = urldecode(urldecode($retailData));
+            $info = json_decode($retail);
+            $obj = $info[0] ?? null;
+            $shopId = $obj->app_poi_code ?? 0;
+            $shop = ShopClass::getById($shopId, true);
+            if (empty($shop)) {
+                noticeUtil::push("美团添加商品,通知我们时出错了,没有找到门店", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $sjId = $shop->sjId ?? 0;
+            $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
+            if (empty($ext)) {
+                noticeUtil::push("美团添加商品,通知我们时出错了,没有找到门店拓展信息", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $mainId = $shop->mainId ?? 0;
+            if (empty($mainId)) {
+                noticeUtil::push("美团添加商品,通知我们时出错了,没有main信息", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
+            if (empty($mtCategory)) {
+                $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
+            }
+            $catId = $mtCategory->id ?? 0;
+            if (empty($catId)) {
+                noticeUtil::push("美团添加商品,通知我们时出错了,没有美团的分类id", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+
+            $config = dict::getDict('mtConfig');
+            $app = new Application($config);
+            $accessToken = mtUtil::getAccessToken($ext);
+
+            $appSpuCode = $obj->app_spu_code ?? '';
+            $hasGoods = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $appSpuCode], true);
+            if (!empty($hasGoods)) {
+                noticeUtil::push("美团添加商品,通知我们时,发现已经有这个商品了,mainId:{$mainId} spu:{$appSpuCode}", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+
+            $params = ['app_poi_code' => $shopId, 'app_spu_code' => $appSpuCode, 'access_token' => $accessToken];
+            $goodsInfo = $app->retail->getDetail($params);
+
+            Yii::info('获取商品详情:' . $goodsInfo . ' ' . json_encode($params));
+
+            $goodsInfo = json_decode($goodsInfo, true);
+            if (isset($goodsInfo['error'])) {
+                noticeUtil::push("美团添加商品,通知我们时出错了,没有找到商品图片", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $imgString = $goodsInfo['data']['picture'] ?? '';
+            if (empty($imgString)) {
+                noticeUtil::push("美团添加商品,通知我们时出错了,没有商品图片...", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+
+            noticeUtil::push("美团添加商品,通知我们,商品图片:" . $imgString, '15280215347');
+
+            $goodsName = $goodsInfo['data']['name'] ?? '';
+            $goodsPrice = $goodsInfo['data']['price'] ?? '';
+            $description = $goodsInfo['data']['description'] ?? '';
+            $sh = strstr($description, '【鲜花】') !== false ? 1 : 0;
+
+            $shopImg = [];
+            $cover = '';
+            $imgArr = explode(',', $imgString);
+            if (!empty($imgArr)) {
+                foreach ($imgArr as $imgUrl) {
+                    $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
+                    $shopImg[] = $shortUrl;
+                    if ($cover == '') {
+                        $cover = $shortUrl;
+                    }
+                }
+            }
+
+            $catIds = [$catId];
+            $addData = [
+                'name' => $goodsName,
+                'flower' => 1,
+                'property' => 0,
+                'price' => $goodsPrice,
+                'sjId' => $sjId,
+                'mainId' => $mainId,
+                'shopId' => $shopId,
+                'status' => 0,
+                'delStatus' => 0,
+                'shopImg' => $shopImg,
+                'catIds' => $catIds,
+                'cover' => $cover,
+                'spu' => $appSpuCode,
+                'sh' => $sh,
+            ];
+            GoodsClass::addGoods($addData);
+            $transaction->commit();
+            return Json::encode(['data' => 'ok']);
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            $msg = $e->getMessage();
+            noticeUtil::push("美团添加商品,通知我们时出错了,错误信息:{$msg}", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+
+    }
+
+    //删除商品 ssh 20220914
+    public function actionGoodsDel()
+    {
+        $post = Yii::$app->request->post();
+        if (isset($post['retail_data']) == false) {
+            noticeUtil::push("美团删除商品,通知我们时出错了,没有获取到相应信息", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+        $retailData = $post['retail_data'];
+        $retail = urldecode(urldecode($retailData));
+        $info = json_decode($retail);
+        $obj = $info[0] ?? null;
+        $shopId = $obj->app_poi_code ?? 0;
+        $shop = ShopClass::getById($shopId, true);
+        if (empty($shop)) {
+            noticeUtil::push("美团删除商品,通知我们时出错了,没有找到门店", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+        $sjId = $shop->sjId ?? 0;
+        $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
+        if (empty($ext)) {
+            noticeUtil::push("美团删除商品,通知我们时出错了,没有找到门店拓展信息", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+        $mainId = $shop->mainId ?? 0;
+        if (empty($mainId)) {
+            noticeUtil::push("美团删除商品,通知我们时出错了,没有main信息", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+        $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
+        if (empty($mtCategory)) {
+            $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
+        }
+        $catId = $mtCategory->id ?? 0;
+        if (empty($catId)) {
+            noticeUtil::push("美团删除商品,通知我们时出错了,没有美团的分类id", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+        $appSpuCode = $obj->app_spu_code ?? '';
+        $hasGoods = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $appSpuCode], true);
+        if (empty($hasGoods)) {
+            return Json::encode(['data' => 'ok']);
+        }
+        $hasGoods->delStatus = 1;
+        $hasGoods->save();
+        $goodsId = $hasGoods->id ?? 0;
+        GoodsCategoryClass::updateByCondition(['gId' => $goodsId], ['delStatus' => 1]);
+        return Json::encode(['data' => 'ok']);
+    }
+
+    //修改商品 ssh 20220914
+    public function actionGoodsUpdate()
+    {
+        $post = Yii::$app->request->post();
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            if (isset($post['retail_data']) == false) {
+                noticeUtil::push("美团修改商品,通知我们时出错了,没有获取到相应信息", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $retailData = $post['retail_data'];
+            $retail = urldecode(urldecode($retailData));
+            $info = json_decode($retail);
+            $obj = $info[0] ?? null;
+            $shopId = $obj->app_poi_code ?? 0;
+            $shop = ShopClass::getById($shopId, true);
+            if (empty($shop)) {
+                noticeUtil::push("美团修改商品,通知我们时出错了,没有找到门店", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $sjId = $shop->sjId ?? 0;
+            $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
+            if (empty($ext)) {
+                noticeUtil::push("美团修改商品,通知我们时出错了,没有找到门店拓展信息", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $mainId = $shop->mainId ?? 0;
+            if (empty($mainId)) {
+                noticeUtil::push("美团修改商品,通知我们时出错了,没有main信息", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
+            if (empty($mtCategory)) {
+                $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
+            }
+            $catId = $mtCategory->id ?? 0;
+            if (empty($catId)) {
+                noticeUtil::push("美团修改商品,通知我们时出错了,没有美团的分类id", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+
+            $config = dict::getDict('mtConfig');
+            $app = new Application($config);
+            $accessToken = mtUtil::getAccessToken($ext);
+
+            $appSpuCode = $obj->app_spu_code ?? '';
+            $hasGoods = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $appSpuCode], true);
+            if (empty($hasGoods)) {
+                noticeUtil::push("美团修改商品,通知我们时,没有发现这个商品,mainId:{$mainId} spu:{$appSpuCode}", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $hasGoodsId = $hasGoods->id ?? 0;
+
+            $params = ['app_poi_code' => $shopId, 'app_spu_code' => $appSpuCode, 'access_token' => $accessToken];
+            $goodsInfo = $app->retail->getDetail($params);
+
+            Yii::info('获取商品详情:' . $goodsInfo . ' ' . json_encode($params));
+
+            $goodsInfo = json_decode($goodsInfo, true);
+            if (isset($goodsInfo['error'])) {
+                noticeUtil::push("美团修改商品,通知我们时出错了,没有找到商品图片", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+            $imgString = $goodsInfo['data']['picture'] ?? '';
+            if (empty($imgString)) {
+                noticeUtil::push("美团修改商品,通知我们时出错了,没有商品图片...", '15280215347');
+                return Json::encode(['data' => 'ok']);
+            }
+
+            $goodsName = $goodsInfo['data']['name'] ?? '';
+            $goodsPrice = $goodsInfo['data']['price'] ?? '';
+            $description = $goodsInfo['data']['description'] ?? '';
+            $sh = strstr($description, '【鲜花】') !== false ? 1 : 0;
+
+            $currentStr = md5($goodsName . '_' . $goodsPrice . '_' . $description . '_' . $sh . '_' . $imgString);
+            $cacheKey = 'mt_goods_id_' . $hasGoodsId;
+            $cacheStr = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+            if ($cacheStr == $currentStr) {
+                //商品没有更新
+                return Json::encode(['data' => 'ok']);
+            } else {
+                Yii::$app->redis->executeCommand('SET', [$cacheKey, $currentStr]);
+            }
+
+            noticeUtil::push("美团修改商品,通知我们,商品图片:" . $imgString, '15280215347');
+
+            $shopImg = [];
+            $cover = '';
+            $imgArr = explode(',', $imgString);
+            if (!empty($imgArr)) {
+                foreach ($imgArr as $imgUrl) {
+                    $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
+                    $shopImg[] = $shortUrl;
+                    if ($cover == '') {
+                        $cover = $shortUrl;
+                    }
+                }
+            }
+            $hasGoods->price = $goodsPrice;
+            $hasGoods->name = $goodsName;
+            $hasGoods->cover = $cover;
+            $hasGoods->sh = $sh;
+            $hasGoods->shopImg = json_encode($shopImg);
+            $hasGoods->save();
+
+            $transaction->commit();
+            return Json::encode(['data' => 'ok']);
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            $msg = $e->getMessage();
+            noticeUtil::push("美团修改商品,通知我们时出错了,错误信息:{$msg}", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+
+    }
+
     //已确认订单通知
     public function actionConfirmOrder()
     {
         //error_reporting(E_ALL);
-
         $post = Yii::$app->request->post();
         $mtOrderId = $post['order_id'] ?? 0;
         $thirdSn = $post['day_seq'] ?? 0;
@@ -111,7 +395,7 @@ class MtController extends PublicController
             $receiveUserName = $post['recipient_name'] ?? '';
             $fullAddress = $post['recipient_address'] ?? '';
 
-            $orderCover = '';
+            $cover = '';
 
             $goodsNum = 0;
             foreach ($mtGoodsData as $mtKey => $mtGoods) {
@@ -182,7 +466,7 @@ class MtController extends PublicController
                 'modifyPrice' => $modifyPrice,
                 'serviceFee' => $serviceFee,
                 'thirdSn' => $thirdSn,
-                'cover' => $orderCover,
+                'cover' => $cover,
                 'reachTime' => $reachTime,
                 'reachDate' => $reachDate,
                 'reachPeriod' => $reachPeriod,
@@ -243,28 +527,16 @@ class MtController extends PublicController
         //只要制作单没有完成,则走取消订单流程。如果有制作单完成,则订单状态和制作单暂时先不管,后面要兼容。
         $orderId = $order->id ?? 0;
         $workList = WorkClass::getAllByCondition(['orderId' => $orderId], null, '*', null, true);
-        $hasCompleteWork = false;
         if (!empty($workList)) {
             foreach ($workList as $work) {
-                if ($work->status == 1) {
-                    $hasCompleteWork = true;
-                }
-            }
-        }
-
-        //取消订单和制作单
-        if ($hasCompleteWork == false) {
-            $order->status = 5;
-            $order->save();
-            if (!empty($workList)) {
-                foreach ($workList as $work) {
+                if ($work->status == 0) {
                     $work->status = 2;
                     $work->save();
                 }
             }
         }
+        //订单取消,金额全部退还
 
-        //如果制作单完成了还会出现取消订单情况,这个等于全部退款,这个后面再考虑兼容!!!!!
 
         //制作单取消通知
         $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);

+ 13 - 9
app-hd/controllers/WorkController.php

@@ -51,19 +51,23 @@ class WorkController extends BaseController
         $get = Yii::$app->request->get();
         $where = [];
         $where['mainId'] = $this->mainId;
+        $sh = $get['sh'] ?? 0;
+        $where['sh'] = $sh;
         if (isset($get['status']) && $get['status'] >= 0) {
             $status = $get['status'];
             $where['status'] = $status;
         }
-        if (isset($get['fromType']) && is_numeric($get['fromType'])) {
-            $where['fromType'] = $get['fromType'];
-        } else {
-            $shopId = $this->shopId;
-            $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
-            $mtAlone = $ext->mtAlone ?? 0;
-            $isCashier = $get['isCashier'] ?? 0;
-            if ($mtAlone == 1 && $isCashier == 1) {
-                $where['fromType'] = ['in', [1, 2, 3]];
+        if ($sh == 0) {
+            if (isset($get['fromType']) && is_numeric($get['fromType'])) {
+                $where['fromType'] = $get['fromType'];
+            } else {
+                $shopId = $this->shopId;
+                $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
+                $mtAlone = $ext->mtAlone ?? 0;
+                $isCashier = $get['isCashier'] ?? 0;
+                if ($mtAlone == 1 && $isCashier == 1) {
+                    $where['fromType'] = ['in', [1, 2, 3]];
+                }
             }
         }
         if (isset($get['sn']) && !empty($get['sn']) && is_numeric($get['sn'])) {

+ 8 - 2
biz-hd/goods/classes/GoodsClass.php

@@ -576,10 +576,11 @@ class GoodsClass extends BaseClass
         }
         //改库存
         $newStock = $goodsData['stock'] - $num;
+
         if ($newStock < 0) {
 
+            $goodsName = $goodsData['name'] ?? '';
             if ($checkStock) {
-                $goodsName = $goodsData['name'] ?? '';
                 util::fail($goodsName . '库存不足,剩余:' . $goodsData['stock']);
             }
 
@@ -601,6 +602,7 @@ class GoodsClass extends BaseClass
             $thirdSn = $params['thirdSn'] ?? '';
             $cardInfo = $params['cardInfo'] ?? '';
             $anonymity = $params['anonymity'] ?? 0;
+            $manyType = $params['manyType'] ?? 0;
             $hasReachTime = 0;
             $reachPeriod = 0;
             $reachDate = '0000-00-00';
@@ -620,8 +622,9 @@ class GoodsClass extends BaseClass
                     $bookName = $order->bookName ?? '';
                 }
             }
+            $sh = $goodsData['sh'] ?? 0;
             $params = [
-                'goods' => [['productId' => $goodsId, 'num' => abs($newStock)]],
+                'goods' => [['productId' => $goodsId, 'num' => abs($num)]],
                 'sjId' => $sjId,
                 'mainId' => $mainId,
                 'orderSn' => $orderSn,
@@ -641,6 +644,8 @@ class GoodsClass extends BaseClass
                 'thirdSn' => $thirdSn,
                 'cardInfo' => $cardInfo,
                 'anonymity' => $anonymity,
+                'sh' => $sh,
+                'manyType' => $manyType,
             ];
             $main = MainClass::getById($mainId, true);
             if (empty($main)) {
@@ -648,6 +653,7 @@ class GoodsClass extends BaseClass
             }
             WorkClass::goodsCreateFinish($params, $main);
         }
+
         $data['stock'] = $newStock;
         self::updateById($goodsId, $data);
         util::unlock($key);

+ 1 - 1
biz-hd/order/classes/OrderClass.php

@@ -523,7 +523,7 @@ class OrderClass extends BaseClass
         if ($fromType == dict::getDict('fromType', 'mt')) {
             $content = '<B>美团 ' . $order->thirdSn . '</B><BR>';
             if (isset($order->goodsNum) && $order->goodsNum > 1) {
-                $content = '<B>美团 ' . $order->thirdSn . ' (' . $order->goodsNum . ')</B><BR>';
+                $content = '<B>美团 ' . $order->thirdSn . ' (' . $order->goodsNum . ')</B><BR>';
             }
             $content .= '--------------------------------<BR>';
             $content .= date("Y-m-d", strtotime($order->addTime)) . '<BR>';

+ 3 - 0
biz-hd/order/services/OrderService.php

@@ -114,6 +114,8 @@ class OrderService extends BaseService
         $groupGoodsData = [];
         $groupItemData = [];
 
+        $manyType = count($product) > 1 ? 1 : 0;
+
         foreach ($product as $key => $val) {
             if (isset($val['property']) == false) {
                 util::fail('没有找到产品属性');
@@ -297,6 +299,7 @@ class OrderService extends BaseService
         $data['sjId'] = $sjId;
         $data['shopId'] = $shopId;
         $data['mainId'] = $mainId;
+        $data['manyType'] = $manyType;
         $data['payWay'] = $payWay;
         $data['orderSn'] = $orderSn;
         $data['status'] = OrderClass::ORDER_STATUS_UN_PAY;

+ 4 - 0
biz-hd/work/classes/WorkClass.php

@@ -125,6 +125,8 @@ class WorkClass extends BaseClass
         $thirdSn = $data['thirdSn'] ?? '';
         $cardInfo = $data['cardInfo'] ?? '';
         $anonymity = $data['anonymity'] ?? 0;
+        $sh = $data['sh'] ?? 0;
+        $manyType = $data['manyType'] ?? 0;
 
         $ids = array_column($goods, 'productId');
         $info = GoodsClass::getByIds($ids, null, 'id');
@@ -191,6 +193,8 @@ class WorkClass extends BaseClass
                 'thirdSn' => $thirdSn,
                 'cardInfo' => $cardInfo,
                 'anonymity' => $anonymity,
+                'sh' => $sh,
+                'manyType' => $manyType,
             ];
             self::createFinish($current, $main);
         }

+ 2 - 1
biz-mall/order/classes/OrderGoodsClass.php

@@ -37,8 +37,9 @@ class OrderGoodsClass extends BaseClass
                 $thirdSn = $order->thirdSn ?? '';
                 $cardInfo = $order->cardInfo ?? '';
                 $anonymity = $order->anonymity ?? 0;
+                $manyType = $order->manyType ?? 0;
                 $params = ['orderId' => $orderId, 'orderSn' => $orderSn, 'shopId' => $shopId, 'sendType' => $sendType, 'thirdSn' => $thirdSn, 'cardInfo' => $cardInfo, 'anonymity' => $anonymity,
-                    'fromType' => $fromType, 'orderPrice' => $orderPrice, 'remark' => $remark, 'orderDebtPrice' => $orderDebtPrice];
+                    'fromType' => $fromType, 'orderPrice' => $orderPrice, 'remark' => $remark, 'orderDebtPrice' => $orderDebtPrice, 'manyType' => $manyType];
                 $flower = $goods->flower ?? 0;
                 //鲜花类不需要验证库存,库存可以负数,并相应生成制作单
                 $checkStock = $flower == 0 ? true : false;

+ 106 - 38
biz/shop/classes/ShopExtClass.php

@@ -35,50 +35,118 @@ class ShopExtClass extends BaseClass
     public static function newWorkRemind($shopExt, $order)
     {
         $id = $order->id ?? 0;
-        $work = WorkClass::getByCondition(['orderId' => $id], true);
-        if (empty($work)) {
-            return false;
-        }
-        $lbSn = $order->fromType == 4 ? $shopExt->mtLbSn : $shopExt->makeLbSn;
-        $lbVersion = $order->fromType == 4 ? $shopExt->mtLbVersion : $shopExt->makeLbVersion;
-        $sound = "您有新的制作单";
-        $reachDate = $order->reachDate ?? '';
-        if ($order->sendType == 1) {
-            if (!empty($reachDate) && $reachDate != '0000-00-00') {
-                $readPeriod = $order->reachPeriod ?? 0;
-                $period = explode(':', $readPeriod);
-                $periodName = implode($period, '点');
-                if ($reachDate == date("Y-m-d")) {
-                    $sound .= ',今天' . $periodName . "分客户到店自取";
-                } elseif ($reachDate == date("Y-m-d", strtotime("+1 day"))) {
-                    $sound .= ',明天' . $periodName . "分客户到店自取";
-                } elseif ($reachDate == date("Y-m-d", strtotime("+2 day"))) {
-                    $sound .= ',后天' . $periodName . "分客户到店自取";
-                } else {
-                    $sound .= ',' . date("d", strtotime($reachDate)) . '号' . $periodName . "分客户到店自取";
-                }
-            } else {
-                $sound .= ",客户到店自取";
+        $list = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
+        if (empty($list)) {
+            //提示有订单,但没有生成制作单
+            if (isset($order->shopAdminId) == false || empty($order->shopAdminId)) {
+                $lbSn = $order->fromType == 4 ? $shopExt->mtLbSn : $shopExt->makeLbSn;
+                $lbVersion = $order->fromType == 4 ? $shopExt->mtLbVersion : $shopExt->makeLbVersion;
+                $sound = "您有新订单,没有生成制作单";
+                $url = "https://speaker.17laimai.cn/notify.php?id={$lbSn}&token=HK1626595800&version={$lbVersion}&message=" . $sound;
+                $curl = new curl\Curl();
+                $curl->get($url);
             }
         } else {
-            if (!empty($reachDate) && $reachDate != '0000-00-00') {
-                $readPeriod = $order->reachPeriod ?? 0;
-                $period = explode(':', $readPeriod);
-                $periodName = implode($period, '点');
-                if ($reachDate == date("Y-m-d")) {
-                    $sound .= ',今天' . $periodName . "分前送达";
-                } elseif ($reachDate == date("Y-m-d", strtotime("+1 day"))) {
-                    $sound .= ',明天' . $periodName . "分前送达";
-                } elseif ($reachDate == date("Y-m-d", strtotime("+2 day"))) {
-                    $sound .= ',后天' . $periodName . "分前送达";
+            //散花
+            $sh = 0;
+            //花束
+            $hs = 0;
+            foreach ($list as $work) {
+                if ($work->sh == 1) {
+                    $sh = 1;
                 } else {
-                    $sound .= date("d", strtotime($reachDate)) . '号' . $periodName . "分前送达";
+                    $hs = 1;
+                }
+            }
+            if ($sh == 1) {
+                $lbSn = $shopExt->lbSn??'';
+                $lbVersion = $shopExt->lbVersion??'';
+                if (!empty($lbSn)) {
+                    $sound = "您有新的散花订单";
+                    $reachDate = $order->reachDate ?? '';
+                    if ($order->sendType == 1) {
+                        if (!empty($reachDate) && $reachDate != '0000-00-00') {
+                            $readPeriod = $order->reachPeriod ?? 0;
+                            $period = explode(':', $readPeriod);
+                            $periodName = implode($period, '点');
+                            if ($reachDate == date("Y-m-d")) {
+                                $sound .= ',今天' . $periodName . "分客户到店自取";
+                            } elseif ($reachDate == date("Y-m-d", strtotime("+1 day"))) {
+                                $sound .= ',明天' . $periodName . "分客户到店自取";
+                            } elseif ($reachDate == date("Y-m-d", strtotime("+2 day"))) {
+                                $sound .= ',后天' . $periodName . "分客户到店自取";
+                            } else {
+                                $sound .= ',' . date("d", strtotime($reachDate)) . '号' . $periodName . "分客户到店自取";
+                            }
+                        } else {
+                            $sound .= ",客户到店自取";
+                        }
+                    } else {
+                        if (!empty($reachDate) && $reachDate != '0000-00-00') {
+                            $readPeriod = $order->reachPeriod ?? 0;
+                            $period = explode(':', $readPeriod);
+                            $periodName = implode($period, '点');
+                            if ($reachDate == date("Y-m-d")) {
+                                $sound .= ',今天' . $periodName . "分前送达";
+                            } elseif ($reachDate == date("Y-m-d", strtotime("+1 day"))) {
+                                $sound .= ',明天' . $periodName . "分前送达";
+                            } elseif ($reachDate == date("Y-m-d", strtotime("+2 day"))) {
+                                $sound .= ',后天' . $periodName . "分前送达";
+                            } else {
+                                $sound .= date("d", strtotime($reachDate)) . '号' . $periodName . "分前送达";
+                            }
+                        }
+                    }
+                    $url = "https://speaker.17laimai.cn/notify.php?id={$lbSn}&token=HK1626595800&version={$lbVersion}&message=" . $sound;
+                    $curl = new curl\Curl();
+                    $curl->get($url);
+                }
+            }
+            if ($hs == 1) {
+                $lbSn = $order->fromType == 4 ? $shopExt->mtLbSn : $shopExt->makeLbSn;
+                $lbVersion = $order->fromType == 4 ? $shopExt->mtLbVersion : $shopExt->makeLbVersion;
+                if (!empty($lbSn)) {
+                    $sound = "您有新的制作单";
+                    $reachDate = $order->reachDate ?? '';
+                    if ($order->sendType == 1) {
+                        if (!empty($reachDate) && $reachDate != '0000-00-00') {
+                            $readPeriod = $order->reachPeriod ?? 0;
+                            $period = explode(':', $readPeriod);
+                            $periodName = implode($period, '点');
+                            if ($reachDate == date("Y-m-d")) {
+                                $sound .= ',今天' . $periodName . "分客户到店自取";
+                            } elseif ($reachDate == date("Y-m-d", strtotime("+1 day"))) {
+                                $sound .= ',明天' . $periodName . "分客户到店自取";
+                            } elseif ($reachDate == date("Y-m-d", strtotime("+2 day"))) {
+                                $sound .= ',后天' . $periodName . "分客户到店自取";
+                            } else {
+                                $sound .= ',' . date("d", strtotime($reachDate)) . '号' . $periodName . "分客户到店自取";
+                            }
+                        } else {
+                            $sound .= ",客户到店自取";
+                        }
+                    } else {
+                        if (!empty($reachDate) && $reachDate != '0000-00-00') {
+                            $readPeriod = $order->reachPeriod ?? 0;
+                            $period = explode(':', $readPeriod);
+                            $periodName = implode($period, '点');
+                            if ($reachDate == date("Y-m-d")) {
+                                $sound .= ',今天' . $periodName . "分前送达";
+                            } elseif ($reachDate == date("Y-m-d", strtotime("+1 day"))) {
+                                $sound .= ',明天' . $periodName . "分前送达";
+                            } elseif ($reachDate == date("Y-m-d", strtotime("+2 day"))) {
+                                $sound .= ',后天' . $periodName . "分前送达";
+                            } else {
+                                $sound .= date("d", strtotime($reachDate)) . '号' . $periodName . "分前送达";
+                            }
+                        }
+                    }
+                    $url = "https://speaker.17laimai.cn/notify.php?id={$lbSn}&token=HK1626595800&version={$lbVersion}&message=" . $sound;
+                    $curl = new curl\Curl();
+                    $curl->get($url);
                 }
             }
         }
-        $url = "https://speaker.17laimai.cn/notify.php?id={$lbSn}&token=HK1626595800&version={$lbVersion}&message=" . $sound;
-        $curl = new curl\Curl();
-        $curl->get($url);
     }
 
     //花店采购供货商端播放声音

+ 47 - 135
console/controllers/MtController.php

@@ -3,7 +3,6 @@
 namespace console\controllers;
 
 use common\components\noticeUtil;
-use common\components\oss;
 use common\components\util;
 use yii\console\Controller;
 use biz\shop\classes\ShopClass;
@@ -14,25 +13,12 @@ use common\components\dict;
 use common\components\httpUtil;
 use common\components\mtUtil;
 use Shishaoqi\MeituanFlashPurchase\Application;
-use linslin\yii2\curl;
 
 class MtController extends Controller
 {
 
-    public function actionCs()
-    {
-        $thirdOrderId = '82628691127252763';
-        $ext = ShopExtClass::getByCondition(['shopId' => 764], true);
-        $config = dict::getDict('mtConfig');
-        $app = new Application($config);
-        $accessToken = mtUtil::getAccessToken($ext);
-        $params = ['order_id' => $thirdOrderId, 'access_token' => $accessToken];
-        $mtRes = $app->order->logisticsPush($params);
-        $mtRes = json_decode($mtRes, true);
-        print_r($mtRes);
-    }
-
-    //同步商品 ssh 20220801
+    //美团里有的商品,但没同步到系统的进行同步;同时美团没有app_spu_code的,补充app_spu_code ssh 20220914
+    // ./yii mt/sync-goods 36524
     public function actionSyncGoods()
     {
         global $argv;
@@ -63,7 +49,6 @@ class MtController extends Controller
         if (isset($arr['data']) == false || empty($arr['data'])) {
             util::stop('没有商品');
         }
-
         $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
         if (empty($mtCategory)) {
             $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
@@ -72,135 +57,62 @@ class MtController extends Controller
         if (empty($catId)) {
             util::stop('没有找到美团的商品分类');
         }
-
         $goodsList = $arr['data'];
         foreach ($goodsList as $key => $val) {
-
             $picture = $val['picture'] ?? '';
             $price = $val['price'] ?? 0;
             $name = $val['name'] ?? '';
-            $mtGoodsSpu = $val['app_spu_code'] ?? '';
-            $imgArr = explode(',', $picture);
-            if (empty($mtGoodsSpu)) {
-                noticeUtil::push('商家有商品没有spuId,' . $name, '15280215347');
-                continue;
-            }
-            $current = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $mtGoodsSpu], true);
-            if (!empty($current)) {
-
-            } else {
-                $shopImg = [];
-                foreach ($imgArr as $imgUrl) {
-                    $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
-                    $shopImg[] = $shortUrl;
+            $description = $val['description'] ?? '';
+            $appSpuCode = $val['app_spu_code'] ?? '';
+            if (!empty($appSpuCode)) {
+                $current = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $appSpuCode], true);
+                if (!empty($current)) {
+                    continue;
                 }
-                $cover = $shopImg[0];
-                $goodsData = [
-                    'spu' => $mtGoodsSpu,
-                    'shopImg' => $shopImg,
-                    'name' => $name,
-                    'sjId' => $sjId,
-                    'mainId' => $mainId,
-                    'shopId' => $shopId,
-                    'catId' => $catId,
-                    'cover' => $cover,
-                    'unitGoodsPrice' => $price,
-                ];
-                GoodsClass::orderCreateGoods($goodsData);
             }
-        }
-    }
-
-    //同步商品 ssh 20220801
-    public function actionBc()
-    {
-        global $argv;
-
-        ini_set('memory_limit', '2045M');
-        set_time_limit(0);
-
-        $shopId = $argv[2] ?? 0;
-        if (empty($shopId)) {
-            util::stop('请填写门店id');
-        }
-        $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
-        if (empty($ext)) {
-            util::stop('没有找到门店相信息');
-        }
-        $shop = ShopClass::getById($shopId, true);
-        if (empty($shop)) {
-            util::stop('没有找到门店');
-        }
-        $mainId = $shop->mainId ?? 0;
-        $sjId = $shop->sjId ?? 0;
-        $config = dict::getDict('mtConfig');
-        $app = new Application($config);
-        $accessToken = mtUtil::getAccessToken($ext);
-        $params = ['app_poi_code' => $shopId, 'access_token' => $accessToken];
-        $json = $app->retail->retailList($params);
-        $arr = json_decode($json, true);
-        if (isset($arr['data']) == false || empty($arr['data'])) {
-            util::stop('没有商品');
-        }
-
-        $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
-        if (empty($mtCategory)) {
-            $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
-        }
-        $catId = $mtCategory->id ?? 0;
-        if (empty($catId)) {
-            util::stop('没有找到美团的商品分类');
-        }
-
-        $goodsList = $arr['data'];
-        foreach ($goodsList as $key => $val) {
-            $picture = $val['picture'] ?? '';
-            $name = $val['name'] ?? '';
-            $mtGoodsSpu = $val['app_spu_code'] ?? '';
+            $sh = strstr($description, '【鲜花】') !== false ? 1 : 0;
             $imgArr = explode(',', $picture);
-            if (empty($mtGoodsSpu)) {
-                noticeUtil::push('商家有商品没有spuId,' . $name, '15280215347');
-                continue;
+            $shopImg = [];
+            foreach ($imgArr as $imgUrl) {
+                $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
+                $shopImg[] = $shortUrl;
             }
-            $current = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $mtGoodsSpu], true);
-            if (!empty($current)) {
-                $shopImg = $current->shopImg;
-                $picArr = json_decode($shopImg, true);
-                $hasErr = false;
-                if (is_array($picArr)) {
-                    foreach ($picArr as $item) {
-                        $url = "https://img.wixhb.com/" . $item . '?x-oss-process=image/info';
-                        $curl = new curl\Curl();
-                        $result = $curl->get($url);
-                        $res = json_decode($result, true);
-                        if (isset($res['FileSize']) == false) {
-                            $hasErr = true;
-                        }
-                    }
+            $cover = $shopImg[0];
+            $catIds = [$catId];
+            $addData = [
+                'name' => $name,
+                'flower' => 1,
+                'property' => 0,
+                'price' => $price,
+                'sjId' => $sjId,
+                'mainId' => $mainId,
+                'shopId' => $shopId,
+                'status' => 0,
+                'delStatus' => 0,
+                'shopImg' => $shopImg,
+                'catIds' => $catIds,
+                'cover' => $cover,
+                'spu' => $appSpuCode,
+                'sh' => $sh,
+            ];
+            $goods = GoodsClass::addGoods($addData);
+            $goodsId = $goods->id ?? 0;
+            if (empty($appSpuCode)) {
+                $newSpuCode = 'hzg_' . $mainId . '_' . $goodsId;
+                $end_category_code = $val['category_code'] ?? '';
+                if (isset($val['secondary_category_code']) && !empty($val['secondary_category_code'])) {
+                    $end_category_code = $val['secondary_category_code'];
                 }
-
-                $cover = $current->cover;
-                $url = "https://img.wixhb.com/" . $cover . '?x-oss-process=image/info';
-                $curl = new curl\Curl();
-                $result = $curl->get($url);
-                $res = json_decode($result, true);
-                if (isset($res['FileSize']) == false) {
-                    $hasErr = true;
-                }
-
-                if ($hasErr == true) {
-                    $newShopImg = [];
-                    foreach ($imgArr as $imgUrl) {
-                        $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
-                        $newShopImg[] = $shortUrl;
-                    }
-                    $current->shopImg = json_encode($newShopImg);
-                    $current->cover = $newShopImg[0];
-                    $current->save();
-                    print_r($imgArr);
-                    echo "\n";
-                    echo $current->name . " ok \n";
+                $name = $val['name'] ?? '';
+                $params = ['app_poi_code' => $shopId, 'access_token' => $accessToken, 'name' => $name, 'category_code' => $end_category_code, 'app_spu_code' => $newSpuCode];
+                $json = $app->retail->updateAppFoodCodeByNameAndSpec($params);
+                $arr = json_decode($json, true);
+                if (isset($arr['data']) == false || $arr['data'] != 'ok') {
+                    noticeUtil::push("同步商品 {$name} 到系统时,app_spu_code 没有生成,请确认", '15280215347');
+                    continue;
                 }
+                $goods->spu = $newSpuCode;
+                $goods->save();
             }
         }
     }