Browse Source

Merge branch 'master' into zhongqi-delivery

shish 8 months ago
parent
commit
b94398a4e9

+ 34 - 12
app-ghs/controllers/CustomController.php

@@ -9,6 +9,7 @@ use biz\sj\classes\SjClass;
 use biz\wx\classes\WxMessageClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\services\CustomService;
+use common\components\noticeUtil;
 use common\components\qrCodeUtil;
 use bizGhs\order\classes\OrderClass;
 use bizHd\saas\classes\ApplyClass;
@@ -675,19 +676,31 @@ class CustomController extends BaseController
         foreach ($arr as $item) {
             $name = $item['name'] ?? '';
             $mobile = $item['mobile'] ?? '';
-            //队列方式去处理
-            $customerCachedKey = 'batch_create_customer_list';
-            $value = $name . '_' . $mobile . '_' . $this->sjId . '_' . $this->shop->id . '_' . $this->sj->name . '_' . $this->shopAdminId;
-            Yii::$app->redis->executeCommand('LPUSH', [$customerCachedKey, $value]);
-            Yii::info("供货商添加客户:name - " . $name . ' == mobile - ' . $mobile);
-            Yii::info("shopAdminId: " . $this->shopAdminId);
-        }
-        util::complete('已提交,15秒后生效');
+            //使用消息队列处理
+            try {
+                $producer = Yii::$app->rabbitmq->getProducer('customProducer');
+                $msg = serialize(['type' => 'add_custom', 'name' => $name, 'mobile' => $mobile, 'sjId' => $this->sjId,
+                    'shopId' => $this->shop->id, 'sjName' => $this->sj->name, 'staffId' => $this->shopAdminId]);
+                $producer->publish($msg, 'customExchange', 'customRoute');
+            } catch (\Exception $e) {
+                $msg = $e->getMessage();
+                $remind = "供货商创建新客户,生产消息报错 {$name} {$mobile} {$this->sj->name} {$msg}";
+                noticeUtil::push($remind, '15280215347');
+            }
+        }
+        util::complete('已添加');
     }
 
     //从其它店同步客户 shizhongqi 2022.6.9
     public function actionCopyCustomers()
     {
+        //限制请求次数
+        $shopId = $this->shopId;
+        util::perDayCommitTimeLimit($shopId, 3);
+
+        //限制频繁请求
+        util::checkRepeatCommit($this->adminId, 6);
+
         $get = Yii::$app->request->get();
         $fromShopId = $get['fromShopId'] ?? 0;
         $fromShop = ShopClass::getById($fromShopId, true);
@@ -712,10 +725,19 @@ class CustomController extends BaseController
         if ($toSjId != $fromSjId) {
             util::fail('不是您的门店');
         }
-        $cachedKey = 'copy_other_shop_customers';
-        Yii::$app->redis->executeCommand('LPUSH', [$cachedKey, $toShopId . '_' . $fromShopId]);
-        Yii::info("从其他门店同步客户:目标门店id =  " . $toShopId . ' 来源门店id = ' . $fromShopId);
-        util::complete('已提交,1分钟后生效');
+
+        //使用消息队列处理 ssh 20251204
+        try {
+            $producer = Yii::$app->rabbitmq->getProducer('customProducer');
+            $msg = serialize(['type' => 'pull_custom_from_other_shop', 'toShopId' => $toShopId, 'fromShopId' => $fromShopId]);
+            $producer->publish($msg, 'customExchange', 'customRoute');
+        } catch (\Exception $e) {
+            $msg = $e->getMessage();
+            $remind = "供货商拉取其他门店客户,生产消息报错 {$toShopId} {$fromShopId} {$msg}";
+            noticeUtil::push($remind, '15280215347');
+        }
+
+        util::complete('已拉取');
     }
 
     //客户列表 ssh 2021.7.8

+ 1 - 30
app-ghs/controllers/UploadController.php

@@ -177,36 +177,7 @@ class UploadController extends BaseController
     //批量导入客户 ssh 2024426
     public function actionCustom()
     {
-        $file = $_FILES['file'];
-        if (!is_uploaded_file($file['tmp_name'])) {
-            util::fail('please upload img');
-        }
-        $mainId = $this->sjId;
-        $shopId = $this->shopId;
-        $month = date("Ym");
-        $date = date("d");
-        $path = dirUtil::getImgUploadDir() . "/{$mainId}/{$shopId}/{$month}/{$date}/";
-        if (!file_exists($path)) {
-            //检查是否有该文件夹,如果没有就创建,并给予最高权限
-            mkdir($path, 0700, true);
-        }
-        $preFileName = stringUtil::uniqueFileName();
-        //$newFile = $preFileName . ".txt";
-        $newFile = $preFileName . ".txt";
-        $fullPathFile = $path . $newFile;
-        if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
-
-//            //队列方式去处理
-//            $customerCachedKey = 'file_batch_create_customer_list';
-            $value = $shopId . ',' . $fullPathFile;
-//            Yii::$app->redis->executeCommand('LPUSH', [$customerCachedKey, $value]);
-
-            noticeUtil::push("待批量导入客户的文件:" . $value, '15280215347');
-
-            util::complete();
-        } else {
-            util::fail('fail');
-        }
+        //重新写这个方法,用rabbitMQ来实现
     }
 
     //删除oss上的图片

+ 6 - 2
app-hd/controllers/GhsController.php

@@ -326,10 +326,10 @@ class GhsController extends BaseController
     public function actionInfo()
     {
         $shopId = Yii::$app->request->get('shopId');
-        if (isset($this->shopId) && !empty($this->shopId)) {
+        if (!empty($this->shopId)) {
 
             $current = ShopClass::getById($shopId, true);
-            if (isset($current->ptStyle) == false || $current->ptStyle != dict::getDict('ptStyle', 'ghs')) {
+            if (!isset($current->ptStyle) || $current->ptStyle != dict::getDict('ptStyle', 'ghs')) {
                 util::fail('没有找到批发店');
             }
 
@@ -349,7 +349,11 @@ class GhsController extends BaseController
             $giveLevel = $ghs['giveLevel'] ?? 0;
             $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
             $ghs['showSold'] = $ghsShop->showSold ?? 0;
+
             $ghs['buyNotice'] = $ghsShop->buyNotice ?? 0;
+            $shopExt = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, false, 'id,shopId,purchaseGuideText');
+            $ghs['buyNoticeText'] = $shopExt->purchaseGuideText ?? '';
+
             $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
             $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
             $ghs['tjFl'] = $ghsShop->tjFl ?? 0;

+ 25 - 13
app-hd/controllers/NoticeController.php

@@ -2,6 +2,7 @@
 
 namespace hd\controllers;
 
+use biz\common\classes\GhsNotifyClass;
 use biz\shop\classes\ShopClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\classes\CustomRechargeClass;
@@ -9,6 +10,7 @@ use bizGhs\order\classes\OrderClearClass;
 use bizGhs\order\classes\RefundOrderClass;
 use bizHd\cg\classes\CgRefundClass;
 use bizHd\ghs\classes\GhsClass;
+use bizHd\notice\classes\NoticeClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\classes\PurchaseClearClass;
 use bizHd\wx\classes\WxOpenClass;
@@ -236,7 +238,7 @@ class NoticeController extends PublicController
                         $cgShopId = $cg->shopId ?? 0;
                         $cgShop = ShopClass::getById($cgShopId, true);
                         if (!empty($cgShop)) {
-                            \bizHd\notice\classes\NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
+                            //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
                         }
                         //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
                         if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
@@ -245,10 +247,14 @@ class NoticeController extends PublicController
                         $shopId = $order->shopId ?? 0;
                         $shop = ShopClass::getById($shopId, true);
                         if (!empty($shop)) {
+
                             //花店采购,供货商端微信收到通知
-                            $noticeText = json_encode(['orderId' => $saleId]);
-                            $noticeKey = "hdCgNoticeGhs";
-                            Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
+//                            $noticeText = json_encode(['orderId' => $saleId]);
+//                            $noticeKey = "hdCgNoticeGhs";
+//                            Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
+
+                            GhsNotifyClass::newOrderNotify($saleId);
+
                         }
                     }
                 }
@@ -459,7 +465,7 @@ class NoticeController extends PublicController
                         $cgShopId = $cg->shopId ?? 0;
                         $cgShop = ShopClass::getById($cgShopId, true);
                         if (!empty($cgShop)) {
-                            \bizHd\notice\classes\NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
+                            //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
                         }
                         //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
                         if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
@@ -470,9 +476,11 @@ class NoticeController extends PublicController
                         if (!empty($shop)) {
                             //花店采购供货商端微信收到通知
                             //WxMessageClass::ghsHasNewOrderInform($shop, $order);
-                            $noticeText = json_encode(['orderId' => $saleId]);
-                            $noticeKey = "hdCgNoticeGhs";
-                            Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
+//                            $noticeText = json_encode(['orderId' => $saleId]);
+//                            $noticeKey = "hdCgNoticeGhs";
+//                            Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
+
+                            GhsNotifyClass::newOrderNotify($saleId);
 
                             //向供货商APP发通知
 //                            $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
@@ -595,7 +603,7 @@ class NoticeController extends PublicController
                         $cgShopId = $cg->shopId ?? 0;
                         $cgShop = ShopClass::getById($cgShopId, true);
                         if (!empty($cgShop)) {
-                            \bizHd\notice\classes\NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
+                            //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
                         }
                         //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
                         if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
@@ -606,9 +614,11 @@ class NoticeController extends PublicController
                         if (!empty($shop)) {
                             //花店采购供货商端微信收到通知
                             //WxMessageClass::ghsHasNewOrderInform($shop, $order);
-                            $noticeText = json_encode(['orderId' => $saleId]);
-                            $noticeKey = "hdCgNoticeGhs";
-                            Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
+//                            $noticeText = json_encode(['orderId' => $saleId]);
+//                            $noticeKey = "hdCgNoticeGhs";
+//                            Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
+
+                            GhsNotifyClass::newOrderNotify($saleId);
 
                             //向供货商端APP发通知
 //                            $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
@@ -842,7 +852,7 @@ class NoticeController extends PublicController
                             $cgShopId = $cg->shopId ?? 0;
                             $cgShop = ShopClass::getById($cgShopId, true);
                             if (!empty($cgShop)) {
-                                \bizHd\notice\classes\NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
+                                NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
                             }
                             $shopId = $order->shopId ?? 0;
                             $shop = ShopClass::getById($shopId, true);
@@ -853,6 +863,8 @@ class NoticeController extends PublicController
                                 $noticeKey = "hdCgNoticeGhs";
                                 Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
 
+                                GhsNotifyClass::newOrderNotify($saleId);
+
                                 //向供货商端APP发通知
 //                                $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
 //                                $push = new push('ghs', push::MSG_TYPE_ORDER);

+ 6 - 3
app-hd/controllers/PurchaseController.php

@@ -3,6 +3,7 @@
 namespace hd\controllers;
 
 use biz\admin\classes\AdminClass;
+use biz\common\classes\GhsNotifyClass;
 use biz\ghs\classes\GhsClass;
 use biz\shop\classes\ShopClass;
 use biz\shop\classes\ShopExtClass;
@@ -864,9 +865,11 @@ class PurchaseController extends BaseController
                 if (!empty($shop)) {
                     //微信通知供货商
                     //WxMessageClass::ghsHasNewOrderInform($shop, $order);
-                    $noticeText = json_encode(['orderId' => $saleId]);
-                    $noticeKey = "hdCgNoticeGhs";
-                    Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
+//                    $noticeText = json_encode(['orderId' => $saleId]);
+//                    $noticeKey = "hdCgNoticeGhs";
+//                    Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
+
+                    GhsNotifyClass::newOrderNotify($saleId);
 
                     //向供货商APP发通知
 //                    $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');

+ 117 - 0
biz-ghs/custom/classes/CustomClass.php

@@ -4,6 +4,8 @@ namespace bizGhs\custom\classes;
 
 use biz\ghs\classes\GhsClass;
 use biz\sj\classes\MerchantClass;
+use biz\sj\classes\SjClass;
+use bizGhs\admin\classes\AdminClass;
 use bizGhs\book\classes\BookCustomClass;
 use bizGhs\book\classes\BookItemCustomClass;
 use bizGhs\custom\models\Custom;
@@ -13,10 +15,13 @@ use bizGhs\shop\classes\TotalDebtChangeClass;
 use bizGhs\ghs\classes\GhsBalanceClass;
 use bizGhs\ghs\classes\GhsRechargeClass;
 use bizGhs\shop\classes\ShopClass;
+use bizHd\saas\classes\ApplyClass;
+use bizHd\saas\services\ApplyService;
 use common\components\business;
 use common\components\dict;
 use common\components\imgUtil;
 use common\components\noticeUtil;
+use common\components\stringUtil;
 use common\components\util;
 use common\components\orderSn;
 use bizHd\base\classes\BaseClass;
@@ -66,6 +71,118 @@ class CustomClass extends BaseClass
         self::LEVEL_ZS => 'zsAddPrice',
     ];
 
+    public static function pullOtherShopCustom($data)
+    {
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $toShopId = $data['toShopId'] ?? 0;
+            $fromShopId = $data['fromShopId'] ?? 0;
+            //指定当前环境为批发商,重要!!!
+            Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
+            $fromCustomList = CustomClass::getAllByCondition(['ownShopId' => $fromShopId], null, '*');
+            if (!empty($fromCustomList)) {
+                foreach ($fromCustomList as $fromCustomer) {
+                    $exist = CustomClass::exists(['ownShopId' => $toShopId, 'shopId' => $fromCustomer['shopId']]);
+                    if (!$exist) {
+                        CustomClass::build($toShopId, $fromCustomer['shopId'], $fromCustomer['name']);
+                    }
+                }
+            }
+            $transaction->commit();
+            return true;
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            noticeUtil::push("批量拉取客户时报错了,fromShopId:{$fromShopId} toShopId:{$toShopId},报错内容:" . $exception->getMessage(), '15280215347');
+        }
+        return true;
+    }
+
+    public static function generateCustom($data)
+    {
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            // 组织表单数据
+            $shopName = $data['name'] ?? '';
+            $mobile = $data['mobile'] ?? '';
+            $post = [];
+            $post['introSjId'] = $data['sjId'] ?? '';
+            $post['introShopId'] = $data['shopId'] ?? '';
+            $post['introSjName'] = $data['sjName'] ?? '';
+            $post['introStyle'] = SjClass::STYLE_SUPPLIER;
+
+            $post['name'] = $shopName;
+            if (empty($shopName)) {
+                noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称没有填写", '15280215347');
+                $transaction->rollBack();
+                return true;
+            }
+            $post['mobile'] = $mobile;
+            if (!stringUtil::isMobile($mobile)) {
+                noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号填写错误", '15280215347');
+                $transaction->rollBack();
+                return true;
+            }
+            if (stringUtil::getWordNum($shopName) > 15) {
+                noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称超过了15个汉字", '15280215347');
+                $transaction->rollBack();
+                return true;
+            }
+            $has = ApplyClass::getByCondition(['mobile' => $mobile]);
+            if (!empty($has)) {
+                noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了哦", '15280215347');
+                $transaction->rollBack();
+                return true;
+            }
+            $hasShop = \biz\shop\classes\ShopClass::getByCondition(['mobile' => $mobile]);
+            if (!empty($hasShop)) {
+                noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了", '15280215347');
+                $transaction->rollBack();
+                return true;
+            }
+            $adminName = $post['adminName'] ?? '';
+            $miniOpenId = $post['miniOpenId'] ?? '';
+            $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId];
+            $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
+
+            $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
+            $adminId = $admin['id'] ?? 0;
+            $post['adminId'] = $adminId;
+            $post['adminName'] = $admin['name'] ?? '';
+            $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
+            $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
+            $post['from'] = ApplyClass::FROM_RETAIL;
+            $post['style'] = SjClass::STYLE_RETAIL;
+            //增加或更新申请
+            $respond = ApplyService::replaceRetail($post);
+            $id = $respond['id'] ?? 0;
+            //后面的代码,要用到此参数,重要
+            Yii::$app->params['ptStyle'] = 2;
+            ApplyService::pass($id, '批发商手动添加');
+            $transaction->commit();
+
+            //只要手动添加的都标记为花店,任何情况都不会标记为散客,任何情况都是审核通过的状态
+            $customList = CustomClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true);
+            if (!empty($customList)) {
+                foreach ($customList as $custom) {
+                    $custom->isHd = 1;
+                    $custom->passStatus = 1;
+                    $custom->save();
+                    $ghsId = $custom->ghsId;
+                    GhsClass::updateById($ghsId, ['passStatus' => 1]);
+                }
+            }
+            //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 由批发商添加成功");
+            return true;
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:" . $exception->getMessage(), '15280215347');
+        }
+        return true;
+    }
+
     //预订相关表同步更新货位 ssh 20240729
     public static function syncBookSeat($shop, $custom, $seatSn)
     {

+ 73 - 70
biz/ghs/classes/GhsClass.php

@@ -52,9 +52,9 @@ class GhsClass extends BaseClass
         $needCheck = $ghsShop['needCheck'] ?? 0;
         $home = $ghsShop['home'] ?? 0;
         $homeAmount = $ghsShop['homeAmount'] ?? 0;
-        $homeType = $ghsShop['homeType']??0;
+        $homeType = $ghsShop['homeType'] ?? 0;
         $passStatus = $needCheck == 1 ? 0 : 1;
-        $live = isset($ghsShop['live']) ? $ghsShop['live'] : 1;
+        $live = $ghsShop['live'] ?? 1;
         $isHd = $ghsShop['isHd'] ?? 1;
         $showStock = $ghsShop['showStock'] ?? 0;
         $allowDebtAmount = $ghsShop['allowDebtAmount'] ?? 0;
@@ -75,37 +75,39 @@ class GhsClass extends BaseClass
         $hdOwnPtStyle = $hdShopInfo['ptStyle'] ?? 1;
 
         $salt = stringUtil::charsShuffleLowerCase(8);
-
-        $data = [
-            'sjId' => $ghsSjId,
-            'shopId' => $ghsShopId,
-            'mainId' => $ghsMainId,
-            'ownSjId' => $hdSjId,
-            'ownShopId' => $hdShopId,
-            'ownMainId' => $hdMainId,
-            'ownPtStyle' => $hdOwnPtStyle,
-            'name' => $name,
-            'py' => $py,
-            'avatar' => $ghsAvatar,
-            'mobile' => $ghsShop['mobile'] ?? '',
-            'province' => $ghsShop['province'] ?? '',
-            'city' => $ghsShop['city'] ?? '',
-            'dist' => $ghsShop['dist'] ?? '',
-            'address' => $ghsShop['address'] ?? '',
-            'floor' => $ghsShop['floor'] ?? '',
-            'fullAddress' => $ghsShop['fullAddress'] ?? '',
-            'lat' => $ghsShop['lat'] ?? '',
-            'long' => $ghsShop['long'] ?? '',
-            'live' => $live,
-            'giveLevel' => $giveLevel,
-            'showStock' => $showStock,
-            'salt' => $salt,
-            'passStatus' => $passStatus,
-            'home'=>$home,
-            'homeAmount'=>$homeAmount,
-            'homeType'=>$homeType,
-        ];
-        $ghs = self::addGhs($data);
+        $ghs = self::getByCondition(['ownShopId' => $hdShopId, 'shopId' => $ghsShopId]);
+        if (empty($ghs)) {
+            $data = [
+                'sjId' => $ghsSjId,
+                'shopId' => $ghsShopId,
+                'mainId' => $ghsMainId,
+                'ownSjId' => $hdSjId,
+                'ownShopId' => $hdShopId,
+                'ownMainId' => $hdMainId,
+                'ownPtStyle' => $hdOwnPtStyle,
+                'name' => $name,
+                'py' => $py,
+                'avatar' => $ghsAvatar,
+                'mobile' => $ghsShop['mobile'] ?? '',
+                'province' => $ghsShop['province'] ?? '',
+                'city' => $ghsShop['city'] ?? '',
+                'dist' => $ghsShop['dist'] ?? '',
+                'address' => $ghsShop['address'] ?? '',
+                'floor' => $ghsShop['floor'] ?? '',
+                'fullAddress' => $ghsShop['fullAddress'] ?? '',
+                'lat' => $ghsShop['lat'] ?? '',
+                'long' => $ghsShop['long'] ?? '',
+                'live' => $live,
+                'giveLevel' => $giveLevel,
+                'showStock' => $showStock,
+                'salt' => $salt,
+                'passStatus' => $passStatus,
+                'home' => $home,
+                'homeAmount' => $homeAmount,
+                'homeType' => $homeType,
+            ];
+            $ghs = self::addGhs($data);
+        }
         $ghsId = $ghs['id'] ?? 0;
         $shop = ShopClass::getShopInfo($hdShopId);
         $hdAvatar = $shop['shortAvatar'] ?? '';
@@ -127,42 +129,43 @@ class GhsClass extends BaseClass
             ShopClass::updateById($hdShopId, ['hasManyGhs' => 1]);
         }
 
-        $debtLimit = 0;//欠款额度
-        $customData = [
-            'sjId' => $hdSjId,
-            'ghsId' => $ghsId,
-            'shopId' => $hdShopId,
-            'mainId' => $hdMainId,
-            'ownSjId' => $ghsSjId,
-            'ownShopId' => $ghsShopId,
-            'ownMainId' => $ghsMainId,
-            'ownPtStyle' => $ghsOwnPtStyle,
-            'name' => $firstName,
-            'originName' => $secondName,
-            'py' => $py,
-            'avatar' => $hdAvatar,
-            'mobile' => $mobile,
-            'province' => $shop['province'] ?? '',
-            'city' => $shop['city'] ?? '',
-            'dist' => $shop['dist'] ?? '',
-            'address' => $shop['address'] ?? '',
-            'fullAddress' => $shop['fullAddress'] ?? '',
-            'showAddress' => $shop['showAddress'] ?? '',
-            'long' => $shop['long'] ?? '',
-            'lat' => $shop['lat'] ?? '',
-            'debtLimit' => $debtLimit,
-            'debt' => $allowDebt,
-            'debtLimit' => $allowDebtAmount,
-            'live' => $live,
-            'level' => $level,
-            'showStock' => $showStock,
-            'salt' => $salt,
-            'passStatus' => $passStatus,
-            'home'=>$home,
-            'homeAmount'=>$homeAmount,
-            'homeType'=>$homeType,
-        ];
-        $custom = CustomClass::addCustom($customData);
+        $custom = CustomClass::getByCondition(['ownShopId' => $ghsShopId, 'shopId' => $hdShopId]);
+        if (empty($custom)) {
+            $customData = [
+                'sjId' => $hdSjId,
+                'ghsId' => $ghsId,
+                'shopId' => $hdShopId,
+                'mainId' => $hdMainId,
+                'ownSjId' => $ghsSjId,
+                'ownShopId' => $ghsShopId,
+                'ownMainId' => $ghsMainId,
+                'ownPtStyle' => $ghsOwnPtStyle,
+                'name' => $firstName,
+                'originName' => $secondName,
+                'py' => $py,
+                'avatar' => $hdAvatar,
+                'mobile' => $mobile,
+                'province' => $shop['province'] ?? '',
+                'city' => $shop['city'] ?? '',
+                'dist' => $shop['dist'] ?? '',
+                'address' => $shop['address'] ?? '',
+                'fullAddress' => $shop['fullAddress'] ?? '',
+                'showAddress' => $shop['showAddress'] ?? '',
+                'long' => $shop['long'] ?? '',
+                'lat' => $shop['lat'] ?? '',
+                'debt' => $allowDebt,
+                'debtLimit' => $allowDebtAmount,
+                'live' => $live,
+                'level' => $level,
+                'showStock' => $showStock,
+                'salt' => $salt,
+                'passStatus' => $passStatus,
+                'home' => $home,
+                'homeAmount' => $homeAmount,
+                'homeType' => $homeType,
+            ];
+            $custom = CustomClass::addCustom($customData);
+        }
         $customId = $custom['id'] ?? 0;
         self::updateById($ghsId, ['customId' => $customId]);
 
@@ -222,7 +225,7 @@ class GhsClass extends BaseClass
             $avatar = $val['avatar'] ?? '';
             $list[$key]['shortAvatar'] = $avatar;
             $list[$key]['avatar'] = imgUtil::groupImg($avatar);
-            $list[$key]['smallAvatar'] = imgUtil::groupImg($avatar). "?x-oss-process=image/resize,m_fill,h_80,w_80";
+            $list[$key]['smallAvatar'] = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_80,w_80";
             $currentShopId = $val['shopId'] ?? 0;
 
             $currentShop = $shopInfo[$currentShopId] ?? [];

+ 17 - 57
common/components/rabbitmq/customConsumer.php

@@ -6,6 +6,7 @@
 
 namespace common\components\rabbitmq;
 
+use bizGhs\custom\classes\CustomClass;
 use common\components\noticeUtil;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
@@ -15,10 +16,10 @@ class customConsumer implements ConsumerInterface
 {
     /**
      * 执行消费者逻辑
-     * 
+     *
      * @param AMQPMessage $msg 消息对象
      * @return string 消息处理结果
-     * 
+     *
      * ConsumerInterface::MSG_ACK - 确认消息(标记为已处理)并从队列中删除
      * ConsumerInterface::MSG_REJECT - 拒绝并从队列中删除消息
      * ConsumerInterface::MSG_REQUEUE - 拒绝并重新入队消息
@@ -32,75 +33,34 @@ class customConsumer implements ConsumerInterface
                 noticeUtil::push("客户的消费者报错:Invalid notify message format: {$msg->body}", '15280215347');
                 return ConsumerInterface::MSG_REJECT;
             }
-            //print_r($data);
+            print_r($data);
             // 根据操作类型分发处理
-            $action = $data['action'] ?? null;
-            switch ($action) {
-                case 'create':
-                    $result = $this->handleCreateCustom($data);
+            $type = $data['type'] ?? null;
+            switch ($type) {
+                case 'add_custom':
+                    //添加新客户
+                    $result = CustomClass::generateCustom($data);
                     break;
-                case 'update':
-                    $result = $this->handleUpdateCustom($data);
-                    break;
-                case 'delete':
-                    $result = $this->handleDeleteCustom($data);
+                case 'pull_custom_from_other_shop':
+                    $result = CustomClass::pullOtherShopCustom($data);
                     break;
                 default:
-                    Yii::warning("Unknown custom action: {$action}", 'rabbitmq.custom');
+                    noticeUtil::push("客户的消费者报错,不存在的类型: {$type}");
                     $result = false;
             }
-            
+
             if ($result) {
-                Yii::info("Custom message processed successfully", 'rabbitmq.custom');
                 return ConsumerInterface::MSG_ACK;
             } else {
-                Yii::error("Custom message processing failed", 'rabbitmq.custom');
+                noticeUtil::push("客户的消费者报错:Notify message processing failed", '15280215347');
                 return ConsumerInterface::MSG_REQUEUE;
             }
-            
+
         } catch (\Exception $e) {
-            Yii::error("Custom consumer exception: " . $e->getMessage(), 'rabbitmq.custom');
+            noticeUtil::push("客户的消费者报错:" . $e->getMessage());
             return ConsumerInterface::MSG_REQUEUE;
         }
     }
-    
-    /**
-     * 处理客户创建
-     * 
-     * @param array $data 消息数据
-     * @return bool 处理结果
-     */
-    private function handleCreateCustom($data)
-    {
-        // TODO: 实现客户创建业务逻辑
-        // 调用对应的 Service 或 Class 层处理
-        return true;
-    }
-    
-    /**
-     * 处理客户更新
-     * 
-     * @param array $data 消息数据
-     * @return bool 处理结果
-     */
-    private function handleUpdateCustom($data)
-    {
-        // TODO: 实现客户更新业务逻辑
-        // 调用对应的 Service 或 Class 层处理
-        return true;
-    }
-    
-    /**
-     * 处理客户删除
-     * 
-     * @param array $data 消息数据
-     * @return bool 处理结果
-     */
-    private function handleDeleteCustom($data)
-    {
-        // TODO: 实现客户删除业务逻辑
-        // 调用对应的 Service 或 Class 层处理
-        return true;
-    }
+
 }
 

+ 3 - 2
common/components/rabbitmq/notifyConsumer.php

@@ -8,6 +8,7 @@ namespace common\components\rabbitmq;
 
 use biz\wx\classes\WxMessageClass;
 use bizGhs\order\classes\OrderClass;
+use bizHd\device\classes\HdDeviceClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\shop\classes\ShopClass;
 use common\components\noticeUtil;
@@ -37,7 +38,7 @@ class notifyConsumer implements ConsumerInterface
                 noticeUtil::push("通知的消费者报错:Invalid notify message format: {$msg->body}", '15280215347');
                 return ConsumerInterface::MSG_REJECT;
             }
-            //print_r($data);
+            print_r($data);
             // 根据通知类型分发处理
             $type = $data['type'] ?? null;
             switch ($type) {
@@ -106,7 +107,7 @@ class notifyConsumer implements ConsumerInterface
         $cg = PurchaseClass::getById($cgId, true);
         $shopId = $cg->shopId ?? 0;
         $shop = ShopClass::getById($shopId, true);
-        $allDevices = \bizHd\device\classes\HdDeviceClass::getAllByCondition(['shopId' => $shopId]);
+        $allDevices = HdDeviceClass::getAllByCondition(['shopId' => $shopId]);
         $cids = array_column($allDevices, 'clientId');
         $title = '买花成功';
         $shopName = $shop->merchantName . ($shop->shopName != '首店' ? '(' . $shop->shopName . ')' : '');

+ 8 - 59
common/components/rabbitmq/stockConsumer.php

@@ -32,78 +32,27 @@ class stockConsumer implements ConsumerInterface
                 noticeUtil::push("库存的消费者报错:Invalid notify message format: {$msg->body}", '15280215347');
                 return ConsumerInterface::MSG_REJECT;
             }
-            //print_r($data);
+            print_r($data);
             // 根据操作类型分发处理
-            $action = $data['action'] ?? null;
-            switch ($action) {
+            $type = $data['type'] ?? null;
+            switch ($type) {
                 case 'add':
-                    $result = $this->handleAddStock($data);
-                    break;
-                case 'reduce':
-                    $result = $this->handleReduceStock($data);
-                    break;
-                case 'adjust':
-                    $result = $this->handleAdjustStock($data);
+                    $result = true;
                     break;
                 default:
-                    Yii::warning("Unknown stock action: {$action}", 'rabbitmq.stock');
+                    noticeUtil::push("库存的消费者报错,未知 type: {$type}");
                     $result = false;
             }
-            
             if ($result) {
-                Yii::info("Stock message processed successfully", 'rabbitmq.stock');
                 return ConsumerInterface::MSG_ACK;
             } else {
-                Yii::error("Stock message processing failed", 'rabbitmq.stock');
+                noticeUtil::push("库存的消费者报错:Stock message processing failed");
                 return ConsumerInterface::MSG_REQUEUE;
             }
-            
         } catch (\Exception $e) {
-            Yii::error("Stock consumer exception: " . $e->getMessage(), 'rabbitmq.stock');
+            noticeUtil::push("库存的消费者报错:" . $e->getMessage());
             return ConsumerInterface::MSG_REQUEUE;
         }
     }
-    
-    /**
-     * 处理库存补充(增加)
-     * 
-     * @param array $data 消息数据,包含 material_id, quantity 等
-     * @return bool 处理结果
-     */
-    private function handleAddStock($data)
-    {
-        // TODO: 实现库存增加业务逻辑
-        // 调用对应的 Service 或 Class 层处理
-        // 例如: StockClass::addStock($data);
-        return true;
-    }
-    
-    /**
-     * 处理库存扣减
-     * 
-     * @param array $data 消息数据,包含 material_id, quantity 等
-     * @return bool 处理结果
-     */
-    private function handleReduceStock($data)
-    {
-        // TODO: 实现库存扣减业务逻辑
-        // 调用对应的 Service 或 Class 层处理
-        // 例如: StockClass::reduceStock($data);
-        return true;
-    }
-    
-    /**
-     * 处理库存调整
-     * 
-     * @param array $data 消息数据,包含 material_id, quantity, type 等
-     * @return bool 处理结果
-     */
-    private function handleAdjustStock($data)
-    {
-        // TODO: 实现库存调整业务逻辑
-        // 调用对应的 Service 或 Class 层处理
-        // 例如: StockClass::adjustStock($data);
-        return true;
-    }
-}
 
+}

+ 24 - 0
common/components/util.php

@@ -417,6 +417,30 @@ class util
         Yii::$app->redis->executeCommand('SETEX', [$cacheKey, $second, 'has']);
     }
 
+    //每天限制请求次数
+    public static function perDayCommitTimeLimit($uniqueId, $num = 0)
+    {
+        if ($num == 0) {
+            //0表示不限制请求次数
+            return true;
+        }
+        $second = 86400;
+        $ctl = Yii::$app->controller->id;
+        $action = Yii::$app->controller->action->id;
+        $cacheKey = "perDayCommitTimeLimit_" . $ctl . "_" . $action . "_" . $uniqueId;
+        $hasNum = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+        if (!empty($hasNum) && $hasNum > 0) {
+            if ($hasNum > $num) {
+                util::fail("已拉取{$num}次,请明天再试");
+            }
+            $newNum = bcadd($hasNum, 1);
+            Yii::$app->redis->executeCommand('SETEX', [$cacheKey, $second, $newNum]);
+        } else {
+            Yii::$app->redis->executeCommand('SETEX', [$cacheKey, $second, 1]);
+        }
+        return true;
+    }
+
     /**
      * 用 mainId 验证操作权限
      * @param array $arr 模型数据数组

+ 4 - 249
console/controllers/CustomController.php

@@ -110,267 +110,22 @@ class CustomController extends Controller
 
     }
 
-    public function actionBatchCommand()
-    {
-        //批量创建客户
-        $this->createCustomer();
-        //从首店同步客户
-        $this->copyCustomers();
-    }
-
     //批量创建客户
     private function createCustomer()
     {
-        $customerCachedKey = 'batch_create_customer_list';
-        $customList = [];
-        while ($count = Yii::$app->redis->executeCommand('LLEN', [$customerCachedKey])) {
-            $customer = Yii::$app->redis->executeCommand('RPOP', [$customerCachedKey]);
-            $customList[] = $customer;
-        }
-
-        if (empty($customList)) {
-            return false;
-        }
-
-        foreach ($customList as $customer) {
-
-            $connection = Yii::$app->db;
-            $transaction = $connection->beginTransaction();
-
-            $customerInfo = explode('_', $customer);
-            $shopName = $customerInfo[0];
-            $mobile = $customerInfo[1];
-
-            try {
-
-                // 组织表单数据
-                $post = [];
-                $post['introSjId'] = $customerInfo[2];
-                $post['introShopId'] = $customerInfo[3];
-                $post['introSjName'] = $customerInfo[4];
-                $post['introStyle'] = SjClass::STYLE_SUPPLIER;
-
-                $post['name'] = $shopName;
-                if (empty($shopName)) {
-                    noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称没有填写", '15280215347');
-                    $transaction->rollBack();
-                    continue;
-                }
-                $post['mobile'] = $mobile;
-                if (stringUtil::isMobile($mobile) == false) {
-                    noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号填写错误", '15280215347');
-                    $transaction->rollBack();
-                    continue;
-                }
-                if (stringUtil::getWordNum($shopName) > 15) {
-                    noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称超过了15个汉字", '15280215347');
-                    $transaction->rollBack();
-                    continue;
-                }
-                $has = ApplyClass::getByCondition(['mobile' => $mobile]);
-                if (!empty($has)) {
-                    noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了哦", '15280215347');
-                    $transaction->rollBack();
-                    continue;
-                }
-                $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
-                if (!empty($hasShop)) {
-                    noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了", '15280215347');
-                    $transaction->rollBack();
-                    continue;
-                }
-                $adminName = $post['adminName'] ?? '';
-                $miniOpenId = $post['miniOpenId'] ?? '';
-                $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId];
-                $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
-
-                $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
-                $adminId = $admin['id'] ?? 0;
-                $post['adminId'] = $adminId;
-                $post['adminName'] = $admin['name'] ?? '';
-                $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
-                $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
-                $post['from'] = ApplyClass::FROM_RETAIL;
-                $post['style'] = SjClass::STYLE_RETAIL;
-                //增加或更新申请
-                $respond = ApplyService::replaceRetail($post);
-                $id = $respond['id'] ?? 0;
-                //后继代码,要用到此参数
-                Yii::$app->params['ptStyle'] = 2;
-                ApplyService::pass($id, '批发商手动添加');
-                $transaction->commit();
-
-                //只要手动添加的都标记为花店,任何情况都不会标记为散客,任何情况都是审核通过的状态
-                $customList = CustomClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true);
-                if (!empty($customList)) {
-                    foreach ($customList as $custom) {
-                        $custom->isHd = 1;
-                        $custom->passStatus = 1;
-                        $custom->save();
-                        $ghsId = $custom->ghsId;
-                        GhsClass::updateById($ghsId, ['passStatus' => 1]);
-                    }
-                }
-
-                //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 由批发商添加成功");
-            } catch (\Exception $exception) {
-                $transaction->rollBack();
-                noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:" . $exception->getMessage(), '15280215347');
-            }
-        }
+        //重新写这个方法,用rabbitMQ来实现
     }
 
     //批发端分店从首店同步客户
     private function copyCustomers()
     {
-        $cachedKey = 'copy_other_shop_customers';
-        $shopIdList = [];
-        while ($count = Yii::$app->redis->executeCommand('LLEN', [$cachedKey])) {
-            $shopIdData = Yii::$app->redis->executeCommand('RPOP', [$cachedKey]);
-            $shopIdList[] = $shopIdData;
-        }
-
-        if (empty($shopIdList)) {
-            return;
-        }
-
-        foreach ($shopIdList as $shopIdData) {
-            $shopIdArr = explode('_', $shopIdData);
-            if (count($shopIdArr) != 2) {
-                Yii::info('copy customer 数据出错:' . $shopIdData);
-                noticeUtil::push("从分店同步客户出错了:" . $shopIdData, '15280215347');
-                continue;
-            }
-
-            //指定当前环境为批发商
-            Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
-
-            $toShopId = $shopIdArr[0];
-            $fromShopId = $shopIdArr[1];
-
-            $fromCustomList = CustomClass::getAllByCondition(['ownShopId' => $fromShopId], null, '*');
-            foreach ($fromCustomList as $fromCustomer) {
-                $exist = CustomClass::exists(['ownShopId' => $toShopId, 'shopId' => $fromCustomer['shopId']]);
-                if (!$exist) {
-                    CustomClass::build($toShopId, $fromCustomer['shopId'], $fromCustomer['name']);
-                }
-            }
-        }
+        //重新写这个方法,用rabbitMQ来实现
     }
 
     //从文件批量创建客户 ssh 20240426
     public function actionFileCreateCustom()
     {
-//        $customerCachedKey = 'file_batch_create_customer_list';
-//        $fileCustomList = [];
-//        while ($count = Yii::$app->redis->executeCommand('LLEN', [$customerCachedKey])) {
-//            $customer = Yii::$app->redis->executeCommand('RPOP', [$customerCachedKey]);
-//            $fileCustomList[] = $customer;
-//        }
-//
-//        if (empty($fileCustomList)) {
-//            noticeUtil::push("没有找到手机号", '15280215347');
-//            return false;
-//        }
-
-        $fileCustomList = ['23580,/usr/local/nginx/html/huahuibao/vendor/../../resource/images/uploads/35869/23580/202404/27/f4ed6c0aa209b4d0d56dd6543b7c4e25.txt'];
-
-        foreach ($fileCustomList as $fileCustom) {
-
-            $customerInfo = explode(',', $fileCustom);
-            $masterShopId = $customerInfo[0];
-            $masterShop = ShopClass::getById($masterShopId, true);
-            $masterSjId = $masterShop->sjId ?? 0;
-            $masterSjName = $masterShop->merchantName ?? '';
-
-            $filePath = $customerInfo[1];
-
-            $content = file_get_contents($filePath);
-            $content = trim($content);
-
-            $arr = explode('
-', $content);
-
-            foreach ($arr as $key => $one) {
-                $single = explode(',', $one);
-
-                $shopName = trim($single[0]);
-                $mobile = trim($single[1]);
-
-                echo bcadd($key, 1) . ' ' . $shopName . ' ' . $mobile . "\n";
-
-                $connection = Yii::$app->db;
-                $transaction = $connection->beginTransaction();
-
-                try {
-
-                    // 组织表单数据
-                    $post = [];
-                    $post['introSjId'] = $masterSjId;
-                    $post['introShopId'] = $masterShopId;
-                    $post['introSjName'] = $masterSjName;
-                    $post['introStyle'] = SjClass::STYLE_SUPPLIER;
-
-                    $post['name'] = $shopName;
-                    if (empty($shopName)) {
-                        noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称没有填写", '15280215347');
-                        $transaction->rollBack();
-                        continue;
-                    }
-                    $post['mobile'] = $mobile;
-                    if (stringUtil::isMobile($mobile) == false) {
-                        noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号填写错误", '15280215347');
-                        $transaction->rollBack();
-                        continue;
-                    }
-                    if (stringUtil::getWordNum($shopName) > 15) {
-                        noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称超过了15个汉字", '15280215347');
-                        $transaction->rollBack();
-                        continue;
-                    }
-                    $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
-                    if (!empty($hasShop)) {
-                        //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了", '15280215347');
-                        $transaction->rollBack();
-                        continue;
-                    }
-                    $has = ApplyClass::getByCondition(['mobile' => $mobile]);
-                    if (!empty($has)) {
-                        noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,在申请列表,手机号已经存在了哦", '15280215347');
-                        $transaction->rollBack();
-                        continue;
-                    }
-                    $adminName = $post['adminName'] ?? '';
-                    $miniOpenId = $post['miniOpenId'] ?? '';
-                    $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId];
-                    $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
-
-                    $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
-                    $adminId = $admin['id'] ?? 0;
-                    $post['adminId'] = $adminId;
-                    $post['adminName'] = $admin['name'] ?? '';
-                    $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
-                    $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
-                    $post['from'] = ApplyClass::FROM_RETAIL;
-                    $post['style'] = SjClass::STYLE_RETAIL;
-                    //增加或更新申请
-                    $respond = ApplyService::replaceRetail($post);
-                    $id = $respond['id'] ?? 0;
-                    //后继代码,要用到此参数
-                    Yii::$app->params['ptStyle'] = 2;
-                    ApplyService::pass($id, '批发商手动添加');
-                    $transaction->commit();
-                    //只要手动添加的都标记为花店,任何情况都不会标记为散客
-                    CustomClass::updateByCondition(['mobile' => $mobile], ['isHd' => 1]);
-                    //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 由批发商添加成功");
-                } catch (\Exception $exception) {
-                    $transaction->rollBack();
-                    noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:" . $exception->getMessage(), '15280215347');
-                }
-
-
-            }
-
-        }
+        //重新写这个方法,用rabbitMQ来实现
     }
+
 }