Parcourir la source

客户和片区

shish il y a 8 mois
Parent
commit
9b864e22e8

+ 158 - 0
app-ghs/controllers/DistController.php

@@ -0,0 +1,158 @@
+<?php
+
+namespace ghs\controllers;
+
+use bizGhs\custom\classes\CustomClass;
+use bizGhs\custom\classes\DistClass;
+use bizGhs\shop\classes\ShopClass;
+use common\components\util;
+use Yii;
+
+class DistController extends BaseController
+{
+
+    //修改片区 ssh 20251117
+    public function actionChangeDist()
+    {
+        $get = Yii::$app->request->get();
+        $customId = $get['customId'] ?? 0;
+        $id = $get['distId'] ?? 0;
+        $custom = CustomClass::getById($customId, true);
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+        if ($custom->ownMainId != $this->mainId) {
+            util::fail('不是你的客户');
+        }
+        $dist = DistClass::getById($id, true);
+        if (empty($dist)) {
+            util::fail('没有找到片区');
+        }
+        if ($dist->mainId != $this->mainId) {
+            util::fail('不是你的片区');
+        }
+        $custom->distId = $id;
+        $custom->save();
+        util::complete('修改成功');
+    }
+
+    //获取所有片区id ssh 20251117
+    public function actionGetAllDist()
+    {
+        $mainId = $this->mainId;
+        $all = DistClass::getAllByCondition(['mainId' => $mainId], null, '*');
+        util::success(['list' => $all]);
+    }
+
+    public function actionGetList()
+    {
+        $where = ['mainId' => $this->mainId, 'delStatus' => 0];
+        $list = DistClass::getDistList($where);
+        util::success($list);
+    }
+
+    public function actionAdd()
+    {
+        $post = Yii::$app->request->post();
+        $post['adminId'] = $this->adminId;
+        $post['mainId'] = $this->mainId ?? 0;
+        DistClass::addDist($this->shop, $post);
+        util::complete('添加成功');
+    }
+
+    //修改分类同步 ssh 20220906
+    public function actionUpdate()
+    {
+        $data = Yii::$app->request->post();
+        $id = $data['id'] ?? 0;
+        $name = $data['name'] ?? '';
+        $currentDist = DistClass::getById($id, true);
+        if (empty($currentDist)) {
+            util::fail('没有找到片区');
+        }
+        if ($currentDist->mainId != $this->mainId) {
+            util::fail('不是您的片区');
+        }
+        $originName = $currentDist->name ?? '';
+        $has = DistClass::getByCondition(['mainId' => $this->mainId, 'name' => $name], true);
+        if (!empty($has) && $id != $has->id) {
+            util::fail('名称已经存在');
+        }
+        $currentDist->name = $name;
+        $currentDist->save();
+
+        //在首店修改,则父级下所有直营和加盟店,同步修改
+        $masterShop = $this->shop;
+        if (isset($masterShop->default) && $masterShop->default == 1 && isset($masterShop->dataSync) && $masterShop->dataSync == 1) {
+            $sjId = $masterShop->sjId ?? 0;
+            $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+            foreach ($shopList as $shop) {
+                $shopId = $shop->id ?? 0;
+                if ($shopId == $masterShop->id) {
+                    //前面已经修改过了
+                    continue;
+                }
+                $currentMainId = $shop->mainId ?? 0;
+                $chainList = DistClass::getAllByCondition(['mainId' => $currentMainId], null, '*', null, true);
+                if (!empty($chainList)) {
+                    foreach ($chainList as $chain) {
+                        if ($chain->name == $originName) {
+                            $chain->name = $name;
+                            $chain->save();
+                        }
+                    }
+                }
+            }
+        }
+
+        util::complete('修改成功');
+    }
+
+    //删除花材分类  ssh 202207062136
+    public function actionDelete()
+    {
+        $id = Yii::$app->request->get('id', 0);
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $myDist = DistClass::getById($id, true);
+            if ($myDist->mainId != $this->mainId) {
+                util::fail('不是你的片区');
+            }
+            $myDist->delStatus = 1;
+            $myDist->save();
+            $originName = $myDist->name ?? '';
+            //在首店删除,则父级下所有直营和加盟店同步删除
+            $masterShop = $this->shop;
+            if (isset($masterShop->default) && $masterShop->default == 1) {
+                $sjId = $masterShop->sjId ?? 0;
+                $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+                foreach ($shopList as $shop) {
+                    $shopId = $shop->id ?? 0;
+                    if ($shopId == $masterShop->id) {
+                        //前面已经删除过了
+                        continue;
+                    }
+                    $currentMainId = $shop->mainId ?? 0;
+                    $chainList = DistClass::getAllByCondition(['mainId' => $currentMainId], null, '*', null, true);
+                    if (!empty($chainList)) {
+                        foreach ($chainList as $chain) {
+                            if ($chain->name == $originName) {
+                                $chain->delStatus = 1;
+                                $chain->save();
+                            }
+                        }
+                    }
+                }
+            }
+
+            $transaction->commit();
+            util::complete('操作成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("失败原因:" . $e->getMessage());
+            util::fail('删除失败');
+        }
+    }
+
+}

+ 17 - 12
biz-ghs/custom/classes/CustomClass.php

@@ -353,27 +353,25 @@ class CustomClass extends BaseClass
     }
 
     //整合头像等信息 ssh 2021.1.8
-    public static function groupBaseInfo($list)
+    public static function groupBaseInfo($list, $mainId = 0)
     {
         if (empty($list)) {
             return $list;
         }
-        //获取客户信息
-        $customSjIdList = array_unique(array_filter(array_column($list, 'sjId')));
-        $sjInfo = MerchantClass::getByIds($customSjIdList, null, 'id');
 
-        $levelMap = self::$levelMap;
+        //片区划分
+        $distMap = [];
+        $custom = current($list);
+        if (!empty($custom) && !empty($custom['ownMainId'])) {
+            $distMap = DistClass::getAllByCondition(['mainId' => $custom['ownMainId']], null, '*', 'id');
+        }
 
+        $levelMap = self::$levelMap;
         foreach ($list as $key => $val) {
-            $customSjId = $val['sjId'];
-            $currentInfo = isset($sjInfo[$customSjId]) ? $sjInfo[$customSjId] : [];
-            //$currentInfo = business::formatMerchantLogo($currentInfo);
-            $smallAvatar =  imgUtil::getPrefix() . (!empty($val['avatar']) ? $val['avatar'] : '/hhb_small.png') . '?x-oss-process=image/resize,m_fill,h_130,w_130';
+            $smallAvatar = imgUtil::getPrefix() . (!empty($val['avatar']) ? $val['avatar'] : '/hhb_small.png') . '?x-oss-process=image/resize,m_fill,h_130,w_130';
             $avatar = imgUtil::getPrefix() . (!empty($val['avatar']) ? $val['avatar'] : '/hhb_small.png');
             $list[$key]['smallAvatar'] = $smallAvatar;
-            //$list[$key]['shortSmallAvatar'] = $currentInfo['shortSmallLogoUrl'];
             $list[$key]['avatar'] = $avatar;
-            //$list[$key]['shortAvatar'] = $currentInfo['shortLogoUrl'];
             $list[$key]['sn'] = $val['id'];
             $level = $val['level'] ?? 1;
             $levelName = $levelMap[$level] ?? '';
@@ -387,6 +385,13 @@ class CustomClass extends BaseClass
             $list[$key]['zbNum'] = '';
             $list[$key]['zbPrice'] = '';
 
+            //片区划分
+            $distId = $val['distId'] ?? 0;
+            $distInfo = $distMap[$distId] ?? [];
+            $distName = $distInfo['name'] ?? '';
+            //注意区别 dist 字段,dist字段是地图里的区
+            $list[$key]['distName'] = $distName;
+
             //超时未下单
             $recentExpend = $val['recentExpend'] ?? '';
             $list[$key]['overTimeUnExpend'] = 0;
@@ -458,7 +463,7 @@ class CustomClass extends BaseClass
                 //客户自己下单要受额度限制
                 if ($custom->debtAmount > $debtLimit) {
                     //虚拟供货商和客户关系不受影响
-                    if($custom->live == 1){
+                    if ($custom->live == 1) {
                         util::fail("已欠款{$custom->debtAmount},请先结账哦");
                     }
                 }

+ 55 - 0
biz-ghs/custom/classes/DistClass.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace bizGhs\custom\classes;
+
+use bizGhs\shop\classes\ShopClass;
+use bizHd\base\classes\BaseClass;
+use Yii;
+
+class DistClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\custom\models\Dist';
+
+    public static function getDistList($where)
+    {
+        return self::getList('*', $where, null);
+    }
+
+    //新增花材分类
+    public static function addDist($masterShop, $data)
+    {
+        $mainId = $masterShop->mainId ?? 0;
+        $name = $data['name'] ?? '';
+        if (empty($name)) {
+            util::fail("请输入名称");
+        }
+        $has = self::getByCondition(['mainId' => $mainId, 'name' => $name]);
+        if ($has) {
+            util::fail("名称已存在");
+        }
+        $res = self::add($data);
+        //在首店添加,则父级下所有直营和加盟店,同步添加分类
+        if (isset($masterShop->default) && $masterShop->default == 1) {
+            $sjId = $masterShop->sjId ?? 0;
+            $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+            foreach ($shopList as $shop) {
+                $shopId = $shop->id ?? 0;
+                if ($shopId == $masterShop->id) {
+                    //前面已经添加过了
+                    continue;
+                }
+                $thisMainId = $shop->mainId ?? 0;
+                $data['shopId'] = $shopId;
+                $data['mainId'] = $thisMainId;
+                $has = self::getByCondition(['mainId' => $thisMainId, 'name' => $name]);
+                if (!empty($has)) {
+                    continue;
+                }
+                self::add($data);
+            }
+        }
+        return $res;
+    }
+
+}

+ 13 - 0
biz-ghs/custom/models/Dist.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizGhs\custom\models;
+use bizHd\base\models\Base;
+
+class Dist extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhDist';
+    }
+
+}

+ 12 - 0
biz-ghs/custom/services/DistService.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace bizGhs\custom\services;
+
+use bizHd\base\services\BaseService;
+
+class DistService extends BaseService
+{
+
+    public static $baseFile = '\bizGhs\custom\classes\DistClass';
+
+}

+ 1 - 1
biz-ghs/item/classes/ItemClassClass.php

@@ -24,7 +24,7 @@ class ItemClassClass extends BaseClass
     public static function getGhsItemClassList($where)
     {
         $data = self::getList('*', $where, 'inTurn DESC');
-        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        $list = !empty($data['list']) ? $data['list'] : [];
         if (empty($list)) {
             return $data;
         }