shish před 8 měsíci
rodič
revize
40afa8bc38

+ 17 - 5
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,12 +676,23 @@ 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);
+//            $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]);
+
+            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('已提交,15秒后生效');
     }

+ 90 - 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,91 @@ class CustomClass extends BaseClass
         self::LEVEL_ZS => 'zsAddPrice',
     ];
 
+    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)
     {

+ 15 - 58
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,31 @@ 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);
-                    break;
-                case 'update':
-                    $result = $this->handleUpdateCustom($data);
-                    break;
-                case 'delete':
-                    $result = $this->handleDeleteCustom($data);
+            $type = $data['type'] ?? null;
+            switch ($type) {
+                case 'add_custom':
+                    //添加新客户
+                    $result = CustomClass::generateCustom($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;
-    }
+
 }
 

+ 1 - 105
console/controllers/CustomController.php

@@ -110,114 +110,10 @@ 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');
-            }
-        }
     }
 
     //批发端分店从首店同步客户
@@ -242,7 +138,7 @@ class CustomController extends Controller
                 continue;
             }
 
-            //指定当前环境为批发商
+            //指定当前环境为批发商,重要
             Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
 
             $toShopId = $shopIdArr[0];