Просмотр исходного кода

Merge branch 'master' into zhongqi-recommend

shish 4 месяцев назад
Родитель
Сommit
5fc7978126

+ 25 - 20
app-ghs/controllers/ApplyController.php

@@ -125,25 +125,32 @@ class ApplyController extends BaseController
             if (stringUtil::getWordNum($shopName) > 8) {
                 util::fail('名称不能超过8个汉字');
             }
-            $has = SjClass::getByCondition(['name' => $shopName]);
-            if (!empty($has)) {
-                //util::fail('名称已经存在');
-            }
-            $hasApply = ApplyClass::getByCondition(['mobile' => $mobile], true);
-            if (!empty($hasApply)) {
-                //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
-                if ($hasApply->status == 1) {
-                    util::fail('此手机号已提交过申请,审核中');
-                }
-                if ($hasApply->status == 3) {
-                    util::fail('此手机号已提交申请,审核没有通过');
+
+            $hasShopList = ShopClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true);
+            if (!empty($hasShopList)) {
+                foreach ($hasShopList as $hasShop) {
+                    if ($hasShop->ptStyle == 2) {
+                        util::fail('这个手机号已经开了批发店');
+                    }
                 }
-                util::fail('手机号已经申请过了');
             }
-            $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
-            if (!empty($hasShop)) {
-                //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
-                util::fail('手机号已经被使用');
+
+            $apply = ApplyClass::getByCondition(['mobile' => $mobile], true);
+            if (!empty($apply)) {
+                $shop = ShopClass::getByCondition(['mobile' => $mobile], true);
+                if (!empty($shop)) {
+                    $apply->introSjId = 1;
+                    $apply->introStyle = 0;
+                    $apply->introSjName = 0;
+                    $apply->introShopId = 0;
+                    $apply->name = $shopName;
+                    $apply->style = 2;
+                    $apply->status = 1;
+                    $apply->save();
+                    $transaction->commit();
+                    noticeUtil::push("{$shopName} 手机号 {$mobile} 申请开通批发店", '15280215347');
+                    util::complete('已提交申请');
+                }
             }
             $ptStyle = Yii::$app->params['ptStyle'];
             $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
@@ -178,9 +185,7 @@ class ApplyController extends BaseController
             ApplyService::replaceGhs($post);
             $transaction->commit();
 
-            $noticeMobile = '15280215347';
-            //sms::freeSend($noticeMobile . ',' . $mobile, '有新的批发店申请开店,手机号:{$var}');
-            noticeUtil::push("供货商 {$shopName} 手机号 {$mobile} 申请开店", '15280215347');
+            noticeUtil::push("{$shopName} 手机号 {$mobile} 申请开通批发店", '15280215347');
 
         } catch (\Exception $exception) {
             $transaction->rollBack();

+ 77 - 1
app-hd/controllers/ItemClassController.php

@@ -179,7 +179,83 @@ class ItemClassController extends BaseController
 
     public function actionDelete()
     {
-        util::complete('没有删除成功');
+        $id = Yii::$app->request->get('id', 0);
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $default = ItemClassClass::getByCondition(['mainId' => $this->mainId, 'isDefault' => 1], true);
+            $defaultClassId = $default->id ?? 0;
+            if (empty($defaultClassId)) {
+                util::fail('没有默认分类');
+            }
+            if ($defaultClassId == $id) {
+                util::fail('不能删除默认分类');
+            }
+            $class = ItemClassClass::getById($id, true);
+            if (empty($class)) {
+                util::fail('没有找到分类');
+            }
+            if($class->mainId!=$this->mainId){
+                util::fail('不是你的分类');
+            }
+            $originName = $class->name ?? '';
+            $class->delete();
+            $list = ProductClass::getAllByCondition(['classId' => $id], null, '*', null, true);
+            if (!empty($list)) {
+                foreach ($list as $item) {
+                    //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
+                    $itemClassKey = 'item_class_modify_sync';
+                    Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $item->id]);
+                }
+            }
+            ProductClass::updateByCondition(['classId' => $id], ['classId' => $defaultClassId]);
+
+            //在首店删除,则父级下所有直营和加盟店同步删除
+            $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 = ItemClassClass::getAllByCondition(['mainId' => $currentMainId], null, '*', null, true);
+                    if (!empty($chainList)) {
+                        foreach ($chainList as $chain) {
+                            if ($chain->name == $originName) {
+                                $currentId = $chain->id;
+                                $chain->delete();
+                                $default = ItemClassClass::getByCondition(['mainId' => $currentMainId, 'isDefault' => 1], true);
+                                $defaultClassId = $default->id ?? 0;
+                                if (empty($defaultClassId)) {
+                                    util::fail('分店同步删除时,找到默认分类');
+                                }
+                                $list = ProductClass::getAllByCondition(['classId' => $currentId], null, '*', null, true);
+                                if (!empty($list)) {
+                                    //noticeUtil::push('有商家在删除分类', '15280215347');
+                                    foreach ($list as $item) {
+                                        //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
+                                        $itemClassKey = 'item_class_modify_sync';
+                                        Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $item->id]);
+                                    }
+                                }
+                                ProductClass::updateByCondition(['classId' => $currentId], ['classId' => $defaultClassId]);
+                            }
+                        }
+                    }
+                }
+            }
+
+            $transaction->commit();
+            util::complete('操作成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("失败原因:" . $e->getMessage());
+            util::fail('删除失败');
+        }
     }
 
     //开单: 获取所有分类

+ 60 - 0
app-hd/controllers/ProductController.php

@@ -432,6 +432,66 @@ class ProductController extends BaseController
 
     }
 
+    //批量修改更多,包括排序、重量和保质期 ssh 20211211
+    public function actionBatchChangeMore()
+    {
+        $shop = $this->shop;
+        $default = $shop->default ?? 0;
+        $join = $shop->join ?? 0;
+        if ($default == 0 && $join == 0) {
+            util::fail('当前是直营店,请返回总店修改');
+        }
+
+        $shopAdmin = $this->shopAdmin;
+        if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
+            util::fail('超管才能操作');
+        }
+
+        $addData = Yii::$app->request->post('addData', '');
+        if (empty($addData)) {
+            util::fail('没有花材');
+        }
+        $itemData = json_decode($addData, true);
+        if (is_array($itemData) == false) {
+            util::fail('没有花材...');
+        }
+        $ids = array_column($itemData, 'id');
+        $infoList = ProductClass::getByIds($ids, null, 'id');
+        if (empty($infoList)) {
+            util::fail('没有花材');
+        }
+        foreach ($infoList as $info) {
+            if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
+                util::fail('不是你的花材不能修改');
+            }
+        }
+
+        //总店修改同步到所有门店
+        $sjId = $shop->sjId ?? 0;
+        $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
+
+        foreach ($itemData as $key => $data) {
+            $id = $data['id'] ?? 0;
+            unset($data['id']);
+            ProductClass::updateById($id, $data);
+            $ptItemId = $infoList[$id]['itemId'] ?? 0;
+            if (empty($ptItemId)) {
+                continue;
+            }
+            if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
+                foreach ($chainShopList as $chainShop) {
+                    $currentMainId = $chainShop->mainId ?? 0;
+                    if ($currentMainId == $shop->mainId) {
+                        //前面已经修改过了,不需要重复修改
+                        continue;
+                    }
+                    ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
+                }
+            }
+        }
+        util::complete('修改成功');
+    }
+
     //批量改价
     public function actionBatchChangePrice()
     {

+ 1 - 1
app-mall/controllers/ItemController.php

@@ -59,7 +59,7 @@ class ItemController extends BaseController
                 $dateArr = explode(',', trim($preSellDate));
                 if (!empty($dateArr)) {
                     foreach ($dateArr as $sellTime) {
-                        $showDate = date("n月j日", $sellTime);
+                        $showDate = date("n.j", $sellTime);
                         $preSellDateShow[] = $showDate;
                     }
                 }

+ 4 - 0
biz-ghs/merchant/services/MerchantService.php

@@ -114,6 +114,8 @@ class MerchantService extends BaseService
 
         MerchantInitClass::add(['sjId' => $sjId]);
 
+        //给10天时间
+        $deadTime = time()+864000;
         //创建门店
         $shopData = [
             'shopName' => '首店',
@@ -139,6 +141,8 @@ class MerchantService extends BaseService
             'img' => ['/example/shop/1.jpg'],
             'ptStyle' => $ptStyle,
             'live' => $live,
+            'deadline'=> date("Y-m-d H:i:s", $deadTime),
+            'beforeDeadline'=> date("Y-m-d H:i:s"),
         ];
         $shopRespond = \bizGhs\shop\classes\ShopClass::addShop($shopData);
         $shopId = $shopRespond->id;

+ 21 - 131
biz-ghs/product/classes/ProductClass.php

@@ -647,7 +647,7 @@ class ProductClass extends BaseClass
                 if (!empty($dateArr)) {
                     foreach ($dateArr as $sellTime) {
                         $sellDate = date("Y-m-d", $sellTime);
-                        $showDate = date("n月j日", $sellTime);
+                        $showDate = date("n.j", $sellTime);
                         $preSellDateList[] = $sellDate;
                         $preSellDateShow[] = $showDate;
                     }
@@ -729,7 +729,7 @@ class ProductClass extends BaseClass
                 $dateArr = explode(',', trim($preSellDate));
                 if (!empty($dateArr)) {
                     foreach ($dateArr as $sellTime) {
-                        $showDate = date("n月j日", $sellTime);
+                        $showDate = date("n.j", $sellTime);
                         $preSellDateShow[] = $showDate;
                     }
                 }
@@ -2256,10 +2256,10 @@ class ProductClass extends BaseClass
         $data['py'] = stringUtil::py($data['name']);
         $name = $data['name'] ?? '';
         $data['alias'] = $data['alias'] ?? '';
-        $data['cover'] = isset($data['cover']) && !empty($data['cover']) ? $data['cover'] : '';
+        $data['cover'] = !empty($data['cover']) ? $data['cover'] : '';
         $ratioType = $data['ratioType'] ?? 0;
         if ($ratioType == 0) {
-            if (isset($data['ratio']) == false || $data['ratio'] <= 0) {
+            if (!isset($data['ratio']) || $data['ratio'] <= 0) {
                 util::fail('请填写单位比');
             }
             $ratio = $data['ratio'];
@@ -2302,13 +2302,13 @@ class ProductClass extends BaseClass
         if (empty($classId)) {
             util::fail("请选择分类");
         }
-        if (isset($data['price']) == false || is_numeric($data['price']) == false || $data['price'] < 0) {
+        if (!isset($data['price']) || !is_numeric($data['price']) || $data['price'] < 0) {
             util::fail("请输入价格");
         }
-        if (isset($data['cost']) == false || is_numeric($data['cost']) == false || $data['cost'] < 0) {
+        if (!isset($data['cost']) || !is_numeric($data['cost']) || $data['cost'] < 0) {
             util::fail("请输入成本价");
         }
-        if (isset($data['addPrice']) == false || is_numeric($data['addPrice']) == false) {
+        if (!isset($data['addPrice']) || !is_numeric($data['addPrice'])) {
             util::fail("请输入加价");
         }
         if ($stockWarning === false) {
@@ -2330,7 +2330,7 @@ class ProductClass extends BaseClass
         $catName = $cat->name ?? '';
 
         if (isset($data['discountPrice']) && is_numeric($data['discountPrice'])) {
-            $discountPrice = $data['discountPrice'] ?? 0;
+            $discountPrice = $data['discountPrice'];
             $currentPrice = $data['price'] ?? 0;
             if ($discountPrice >= $currentPrice) {
                 util::fail('特价要小于售价');
@@ -2348,7 +2348,18 @@ class ProductClass extends BaseClass
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-            if (isset($data['itemId']) == false || empty($data['itemId'])) {
+            $ptItemId = $data['itemId'] ?? 0;
+            $ptItemInfo = PtItemClass::getById($ptItemId, true);
+
+            $bigUnitId = $data['bigUnitId'] ?? 0;
+            $smallUnitId = $data['smallUnitId'] ?? 0;
+
+            $changeUnit = 0;
+            if ($ptItemInfo->bigUnitId != $bigUnitId || $ptItemInfo->smallUnitId != $smallUnitId || $ptItemInfo->ratio != $ratio) {
+                //如果被修改了单位,则重新创建花材
+                $changeUnit = 1;
+            }
+            if (empty($ptItemId) || $changeUnit == 1) {
                 //添加新品种先在平台新增花材
                 $defaultInfo = PtItemClassClass::getByCondition(['isDefault' => 1]);
                 $defaultClassId = $defaultInfo['id'] ?? 0;
@@ -2371,9 +2382,7 @@ class ProductClass extends BaseClass
                 }
             }
 
-            $ptItemId = $data['itemId'] ?? 0;
             //小菊的结构
-            $ptItemInfo = PtItemClass::getById($ptItemId, true);
             $data['variety'] = $ptItemInfo->variety ?? 0;
 
             //批发价比进货价贵多少 2021-12-07 lqh 如果前端有传取前端的,没有则取pt
@@ -2400,52 +2409,6 @@ class ProductClass extends BaseClass
             }
             $data['property'] = 1;
             $respond = self::addBaseData($data);
-            $respondId = $respond->id ?? 0;
-
-            /*****************产品模块*********************/
-            $ptCpIds = [];
-            if (isset($data['cpInfo']) && !empty($data['cpInfo'])) {
-                $cpIds = array_column($data['cpInfo'], 'cpId');
-                $cpInfoList = CpClass::getByIds($cpIds, null, 'id');
-                $ptCpIds = array_column($cpInfoList, 'ptCpId');
-                foreach ($data['cpInfo'] as $cpKey => $cpVal) {
-                    $cpId = $cpVal['cpId'] ?? 0;
-                    if (isset($cpInfoList[$cpId]) == false) {
-                        util::fail('添加了无效产品');
-                    }
-                    $currentCp = $cpInfoList[$cpId];
-                    if (isset($currentCp['mainId']) == false || $currentCp['mainId'] != $mainId) {
-                        util::fail('不是你的产品哦');
-                    }
-                    $cpName = $currentCp['name'] ?? '';
-                    $ptCpId = $currentCp['ptCpId'] ?? 0;
-                    $cpPy = $currentCp['py'] ?? '';
-                    $name = $data['name'] ?? '';
-                    $py = stringUtil::py($name);
-                    $hasCp = CpItemClass::getByCondition(['cpId' => $cpId, 'productId' => $respondId], true);
-                    if (empty($hasCp)) {
-                        $addCp = [
-                            'cpId' => $cpId,
-                            'ptCpId' => $ptCpId,
-                            'ptItemId' => $ptItemId,
-                            'productId' => $respondId,
-                            'name' => $name,
-                            'py' => $py,
-                            'cpName' => $cpName,
-                            'cpPy' => $cpPy,
-                            'mainId' => $mainId,
-                        ];
-                        CpItemClass::add($addCp);
-                    }
-                }
-                $respond->hasCpId = 1;
-                $respond->save();
-            } else {
-                if ($currentShop->itemToClass == 1) {
-                    util::fail('请选择产品');
-                }
-            }
-            /*****************产品模块*********************/
 
             if ($stock > 0) {
                 //有库存数量,增加盘盈记录 2021.7.9 lqh
@@ -2467,7 +2430,6 @@ class ProductClass extends BaseClass
                 $pdOrderItemData['orderSn'] = $pdOrderSn;
                 $pdOrderItemData['productId'] = $respond->id ?? 0;
                 $pdOrderItemData['itemId'] = $data['itemId'];
-                $pdOrderItemData['itemId'] = $data['itemId'];
                 $pdOrderItemData['itemNum'] = $stock;
                 $pdOrderItemData['itemStock'] = 0;
                 $pdOrderItemData['profitLostNum'] = $stock;
@@ -2547,79 +2509,7 @@ class ProductClass extends BaseClass
                     if (!empty($chainHas)) {
                         continue;
                     }
-                    $chainProduct = self::addBaseData($data);
-                    $chainProductId = $chainProduct->id ?? 0;
-
-                    /****************产品模块********************/
-                    if (!empty($ptCpIds)) {
-                        $ptCpClassList = PtCpClassClass::getAllByCondition(['delStatus' => 0], null, '*', 'id');
-                        $shopCpClassList = CpClassClass::getAllByCondition(['mainId' => $thisMainId, 'delStatus' => 0], null, '*', 'id');
-                        $shopCpDefaultClassId = 0;
-                        foreach ($shopCpClassList as $thisCpClass) {
-                            if ($thisCpClass['isDefault'] == 1) {
-                                $shopCpDefaultClassId = $thisCpClass['id'] ?? 0;
-                            }
-                        }
-                        if (empty($shopCpDefaultClassId)) {
-                            util::fail('没有找到产品的默认分类哦');
-                        }
-                        $ptCpList = PtCpClass::getAllByCondition(['id' => ['in', $ptCpIds]], null, '*', 'id');
-                        $shopCpList = CpClass::getAllByCondition(['mainId' => $thisMainId, 'ptCpId' => ['in', $ptCpIds]], null, '*', 'ptCpId', true);
-                        foreach ($ptCpList as $ptCpId => $ptCpInfo) {
-
-                            if (isset($shopCpList[$ptCpId])) {
-                                $currentCp = $shopCpList[$ptCpId];
-                            } else {
-                                $ptCpClassId = $ptCpInfo['classId'] ?? 0;
-                                $ptCpClassName = '';
-                                if (isset($ptCpClassList[$ptCpClassId])) {
-                                    $ptCpClassName = $ptCpClassList[$ptCpClassId]['name'] ?? '';
-                                }
-                                $currentCpClassId = $shopCpDefaultClassId;
-                                if (!empty($ptCpClassName)) {
-                                    foreach ($shopCpClassList as $thisCpClass) {
-                                        if (isset($thisCpClass['name']) && $thisCpClass['name'] == $ptCpClassName) {
-                                            $currentCpClassId = $thisCpClass['id'] ?? 0;
-                                        }
-                                    }
-                                }
-
-                                unset($ptCpInfo['id']);
-                                unset($ptCpInfo['addTime']);
-                                unset($ptCpInfo['updateTime']);
-                                $ptCpInfo['mainId'] = $thisMainId;
-                                $ptCpInfo['classId'] = $currentCpClassId;
-                                $ptCpInfo['ptCpId'] = $ptCpId;
-                                $currentCp = CpClass::add($ptCpInfo, true);
-                            }
-                            $currentCpId = $currentCp->id ?? 0;
-                            $cpName = $currentCp->name ?? '';
-                            $ptCpId = $currentCp->ptCpId ?? 0;
-                            $cpPy = $currentCp->py ?? '';
-                            $name = $chainProduct->name ?? '';
-                            $py = stringUtil::py($name);
-                            $hasCp = CpItemClass::getByCondition(['cpId' => $currentCpId, 'productId' => $chainProductId], true);
-                            if (empty($hasCp)) {
-                                $addCp = [
-                                    'cpId' => $currentCpId,
-                                    'ptCpId' => $ptCpId,
-                                    'ptItemId' => $ptItemId,
-                                    'productId' => $chainProductId,
-                                    'name' => $name,
-                                    'py' => $py,
-                                    'cpName' => $cpName,
-                                    'cpPy' => $cpPy,
-                                    'mainId' => $thisMainId,
-                                ];
-                                CpItemClass::add($addCp);
-                            }
-                        }
-                    } else {
-                        if ($shop->itemToClass == 1) {
-                            util::fail('请选择产品哈');
-                        }
-                    }
-                    /****************产品模块********************/
+                    self::addBaseData($data);
 
                 }
             }

+ 4 - 1
biz-hd/merchant/services/SjService.php

@@ -113,7 +113,8 @@ class SjService extends BaseService
         if (isset($applyData['appRegister']) && $applyData['appRegister'] == 1) {
             //$onlyCg = 0;
         }
-
+        //给10天时间
+        $deadTime = time()+864000;
         //创建门店
         $shopData = [
             'shopName' => '首店',
@@ -141,6 +142,8 @@ class SjService extends BaseService
             'ptStyle' => $ptStyle,
             'live' => $live,
             'onlyCg' => $onlyCg,
+            'deadline'=> date("Y-m-d H:i:s", $deadTime),
+            'beforeDeadline'=> date("Y-m-d H:i:s"),
         ];
         $shopInfo = ShopClass::addShop($shopData);
         $shopId = $shopInfo->id;