Kaynağa Gözat

添加供货商

shish 5 yıl önce
ebeveyn
işleme
2f6b739965

+ 1 - 0
app-ghs/controllers/CustomController.php

@@ -63,6 +63,7 @@ class CustomController extends BaseController
                 'introSjId' => $sjId,
                 'introSjName' => $sjName,
                 'introShopId' => $shopId,
+                'introStyle' => SjClass::STYLE_SUPPLIER,
                 'from' => ApplyClass::FROM_GHS,
                 'style' => SjClass::STYLE_RETAIL,
                 'province' => $shop->province ?? '',

+ 71 - 6
app-ghs/controllers/GhsController.php

@@ -3,6 +3,10 @@
 namespace ghs\controllers;
 
 use biz\ghs\classes\GhsClass;
+use biz\sj\classes\SjClass;
+use bizHd\saas\classes\ApplyClass;
+use bizHd\saas\services\ApplyService;
+use common\components\imgUtil;
 use common\components\stringUtil;
 use Yii;
 use common\components\util;
@@ -10,14 +14,75 @@ use common\components\util;
 class GhsController extends BaseController
 {
 
+    //添加供货商 shish 20210611
     public function actionAdd()
     {
-        $data = [
-            'id' => 2,
-            'name' => '小石头',
-            'avatar' => 'https://img.hzghd.com/ghs/home/deserve.png',
-        ];
-        util::success($data);
+        $post = Yii::$app->request->post();
+        $mobile = $post['mobile'] ?? '';
+        $confirmMobile = $post['confirmMobile'];
+        if (stringUtil::isMobile($mobile) == false) {
+            util::fail(' 请填写正确的手机号');
+        }
+        if ($mobile != $confirmMobile) {
+            util::fail('二次号码填写不一致');
+        }
+        $name = $post['name'] ?? '';
+        if (empty($name)) {
+            util::fail('名称不能为空');
+        }
+        if (stringUtil::getWordNum($name) > 8) {
+            util::fail('名称不能超过8个汉字');
+        }
+        $has = ApplyClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_KM_SUPPLIER]);
+        if (!empty($has)) {
+            util::fail('名称已经存在');
+        }
+        $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
+        if (!empty($has)) {
+            util::fail('手机号已经添加过');
+        }
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $sjId = $this->sjId;
+            $shopId = $this->shopId;
+            $sjName = $this->sj->name ?? '';
+            $address = $post['address'] ?? '';
+            $applyData = [
+                'name' => $name,
+                'licenseNo' => $mobile,
+                'certType' => ApplyClass::CERT_TYPE_MOBILE,
+                'mobile' => $mobile,
+                'introSjId' => $sjId,
+                'introSjName' => $sjName,
+                'introShopId' => $shopId,
+                'introStyle' => SjClass::STYLE_SUPPLIER,
+                'from' => ApplyClass::FROM_GHS,
+                'style' => SjClass::STYLE_KM_SUPPLIER,
+                'address' => $address,
+                'status' => ApplyClass::STATUS_PASS,
+                'replace' => 1,//1表示供货商添加的客户或供货商
+            ];
+            $apply = ApplyService::replaceKmGhs($applyData);
+            $id = $apply['id'] ?? 0;
+            $respond = ApplyService::pass($id);
+            $shop = $respond['shop'] ?? [];
+            $sj = $respond['sj'] ?? [];
+            $currentSjId = $sj['id'] ?? 0;
+            $currentShopId = $shop->id ?? 0;
+            ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
+            if (empty($currentShopId)) {
+                util::fail('供应商没有添加成功!');
+            }
+            $ghs = GhsClass::build($currentShopId, $shopId, 1);
+            $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
+            $transaction->commit();
+            util::success($ghs);
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("添加供应商没有成功:" . $exception->getMessage());
+            util::fail('添加供应商没有成功');
+        }
     }
 
     //供货商列表 ssh 2021.1.18

+ 1 - 40
app-pt/controllers/GhsController.php

@@ -17,46 +17,7 @@ class GhsController extends BaseController
     //绑定供货商 shish 2021.3.29
     public function actionBindGhs()
     {
-        $get = Yii::$app->request->get();
-        $ownSjId = $get['ownSjId'] ?? '';
-        $sjId = $get['sjId'] ?? '';
-        if ($ownSjId == $sjId) {
-            util::fail('不能自己绑自己');
-        }
-        $sj = MerchantClass::getMerchantById($ownSjId);
-        if (isset($sj['style']) == false || $sj['style'] != SjClass::STYLE_SUPPLIER) {
-            util::fail('城市供货商才能发起绑定');
-        }
-        $ghsSj = MerchantClass::getMerchantById($sjId);
-        if (isset($ghsSj['style']) == false || $ghsSj['style'] != SjClass::STYLE_KM_SUPPLIER) {
-            util::fail('请选择昆明供货商');
-        }
-        $count = ShopClass::getCount(['delStatus' => 0, 'sjId' => $sjId]);
-        if ($count > 1) {
-            util::fail('供货商已经不止一家门店,不知道要绑供货商的哪家店,所以不能再进行绑定');
-        }
-        $currentShop = ShopClass::getByCondition(['sjId' => $sjId, 'delStatus' => 0]);
-        if (empty($currentShop)) {
-            util::fail('没有找到门店');
-        }
-        $currentShopId = $currentShop['id'] ?? 0;
-        $list = ShopClass::getAllByCondition(['sjId' => $ownSjId, 'delStatus' => 0], null, '*');
-        if (empty($list)) {
-            util::fail('没有找到门店');
-        }
-        $connection = Yii::$app->db;
-        $transaction = $connection->beginTransaction();
-        try {
-            foreach ($list as $current) {
-                $ownShopId = $current['id'];
-                GhsClass::build($currentShopId, $ownShopId);
-            }
-            $transaction->commit();
-            util::complete();
-        } catch (Exception $exception) {
-            $transaction->rollBack();
-            util::fail("绑定失败");
-        }
+        util::fail('已关闭');
     }
 
 }

+ 3 - 2
biz-hd/saas/classes/ApplyClass.php

@@ -98,8 +98,9 @@ class ApplyClass extends BaseClass
         $dist = $data['dist'] ?? '';
         $floor = $data['floor'] ?? '';
         $address = $data['address'] ?? '';
-        $data['fullAddress'] = $data['city'] . $dist . $address . $floor;
-        $data['style'] = SjClass::STYLE_SUPPLIER;
+        $city = $data['city'] ?? '';
+        $data['fullAddress'] = $city . $dist . $address . $floor;
+        $data['style'] = $data['style'] ?? SjClass::STYLE_SUPPLIER;
         $respond = self::addApply($data);
         if (isset($data['replace']) && $data['replace'] == 0) {
             $mobile = $data['mobile'];

+ 32 - 0
biz-hd/saas/services/ApplyService.php

@@ -215,4 +215,36 @@ class ApplyService extends BaseService
         return $respond;
     }
 
+    //供货商申请开店 ssh 2021.01.28
+    public static function replaceKmGhs($data)
+    {
+        $mobile = $data['mobile'] ?? 0;
+        if (empty($mobile)) {
+            util::fail('请填写手机号');
+        }
+        if (stringUtil::isMobile($mobile) == false) {
+            util::fail('请填写正确手机号');
+        }
+        $from = $data['from'] ?? ApplyClass::FROM_GHS;
+        if (in_array($from, [ApplyClass::FROM_GHS, ApplyClass::FROM_RETAIL]) == false) {
+            util::fail('请填写来源');
+        }
+        $data['licenseNo'] = $mobile;
+        $adminId = $data['adminId'] ?? 0;
+        $has = ApplyClass::getByCondition(['adminId' => $adminId, 'style' => SjClass::STYLE_KM_SUPPLIER]);
+        if (!empty($has)) {
+            util::fail('您已经申请过');
+        }
+        $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
+        if (!empty($has)) {
+            util::fail('手机号已经使用过了');
+        }
+        $respond = ApplyClass::addGhs($data);
+        if (!empty($adminId)) {
+            //已提交开店申请,待审核
+            \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 2]);
+        }
+        return $respond;
+    }
+
 }