Jelajahi Sumber

绑供货商

shish 5 tahun lalu
induk
melakukan
9bbba36bf9

+ 9 - 0
app-ghs/controllers/ApplyController.php

@@ -2,6 +2,7 @@
 
 namespace ghs\controllers;
 
+use biz\sj\classes\SjClass;
 use bizHd\saas\classes\ApplyExtendClass;
 use biz\sj\classes\MerchantClass;
 use bizGhs\shop\services\ShopAdminService;
@@ -45,6 +46,14 @@ class ApplyController extends BaseController
         $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
         $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
         $post['from'] = ApplyClass::FROM_GHS;
+        $name = $get['name'] ?? '';
+        if (empty($name)) {
+            util::fail('名称不能为空');
+        }
+        $has = SjClass::getByCondition(['name' => $name]);
+        if (!empty($has)) {
+            util::fail('名称已经存在');
+        }
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {

+ 9 - 0
app-hd/controllers/ApplyController.php

@@ -2,6 +2,7 @@
 
 namespace hd\controllers;
 
+use biz\sj\classes\SjClass;
 use bizHd\admin\services\ShopAdminService;
 use biz\sj\classes\MerchantClass;
 use bizHd\saas\services\ApplyService;
@@ -47,6 +48,14 @@ class ApplyController extends BaseController
         $get['lat'] = isset($get['latitude']) ? $get['latitude'] : '';
         $get['from'] = ApplyClass::FROM_RETAIL;
         $get['style'] = SjClass::STYLE_RETAIL;
+        $name = $get['name'] ?? '';
+        if (empty($name)) {
+            util::fail('名称不能为空');
+        }
+        $has = SjClass::getByCondition(['name' => $name]);
+        if (!empty($has)) {
+            util::fail('名称已经存在');
+        }
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {

+ 49 - 215
app-pt/controllers/GhsController.php

@@ -2,229 +2,63 @@
 
 namespace pt\controllers;
 
-use biz\sj\services\MerchantExtendService;
-use Yii;
-use bizHd\admin\services\AdminService;
-use biz\sj\services\MerchantService;
+use biz\ghs\classes\GhsClass;
+use biz\shop\classes\ShopClass;
+use biz\sj\classes\MerchantClass;
+use biz\sj\classes\SjClass;
+use common\components\stringUtil;
 use common\components\util;
-use common\components\wxUtil;
-use common\services\xhMerchantService;
+use Yii;
 
 class GhsController extends BaseController
 {
 
-    public $guestAccessAction = ['bind-open'];
-
-    //商家列表 ssh 2019.12.20
-    public function actionList()
-    {
-        $where = [];
-        $list = MerchantService::getSaasMerchant($where);
-        util::success($list);
-    }
+    public $guestAccessAction = [];
 
-    //获取当前登陆老板的帐号详情,官网购买套餐时使用 ssh 2020.1.11
-    public function actionLoginAccount()
+    //绑定供货商 shish 2021.3.29
+    public function actionBindGhs()
     {
-        $userId = $this->userId;
-        $admin = AdminService::getByCondition(['platUserId' => $userId]);
-        if (empty($admin)) {
-            util::fail('没有找到注册信息');
-        }
-        $merchantId = $admin['merchantId'];
-        $merchant = MerchantService::getMerchantById($merchantId);
-        util::success($merchant);
-    }
-
-    //商家信息 ssh 2020.1.11
-    public function actionDetail()
-    {
-        $id = Yii::$app->request->get('id');
-        $merchant = MerchantService::getMerchantById(12358);
-        util::success($merchant);
-    }
-
-    //开放平台设置相关操作 ssh 2020.1.18
-    public function actionBindOpen()
-    {
-        $merchantId = Yii::$app->request->get('account', 0);
-        $merchant = MerchantService::getById($merchantId);
-        if (empty($merchant)) {
-            util::fail('没有找到商家');
-        }
-        $wxAppId = $merchant['wxAppId'];
-        $miniAppId = $merchant['miniAppId'];
-        $openAppId = $merchant['openAppId'];
-
-        echo "<pre>";
-
-        $id = Yii::$app->request->get('id', 0);
-        //创建平台,并将公众号绑定到平台
-        if ($id == 1) {
-            wxUtil::createOpenAccount($wxAppId, $merchant);
-            $return = wxUtil::getOpenAccount($wxAppId, $merchant, false);
-            print_r($return);
-            if ($return['errcode'] == 0) {
-                $openAppId = $return['open_appid'];
-                xhMerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
-                MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppId' => $openAppId, 'openAppBind' => 1, 'wxAuth' => 1]);
-            }
-        }
-        //将小程序绑定到平台
-        if ($id == 2) {
-            $openAppId = $merchant['openAppId'];
-            $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
-            MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppBind' => 3, 'miniAuth' => 1]);
-            print_r($r);
-        }
-        //查询公众号 小程序的绑定情况
-        if ($id == 3) {
-            $return = wxUtil::getOpenAccount($wxAppId, $merchant, false);
-            echo "公众号绑定情况:<br />";
-            print_r($return);
-            $return = wxUtil::getOpenAccount($miniAppId, $merchant, true);
-            echo "小程序绑定情况:<br />";
-            print_r($return);
-        }
-
-        //设置小程序服务器域名
-        if ($id == 4) {
-            wxUtil::setDomain($merchant, 2);
-            wxUtil::setWebViewDomain($merchant, 2);
-        }
-
-        //为授权的小程序帐号上传小程序代码
-        if ($id == 5) {
-            //模板id
-            $tId = Yii::$app->request->get('tId');
-            wxUtil::miniCommit($merchant, $tId);
-        }
-
-        //获取小程序体验码
-        if ($id == 6) {
-            wxUtil::getExperienceQrCode($merchant);
-        }
-
-        //获取授权小程序帐号已设置的类目
-        if ($id == 7) {
-            wxUtil::getMiniCategory($merchant);
-        }
-
-        //获取小程序的第三方提交代码的页面配置
-        if ($id == 8) {
-            wxUtil::getMiniPage($merchant);
-        }
-
-        //将第三方提交的代码包提交审核
-        if ($id == 9) {
-            wxUtil::miniSubmitAudit($merchant);
-        }
-
-        //查询最新一次提交的审核状态
-        if ($id == 10) {
-            wxUtil::miniGetLatestAuditStatus($merchant);
-        }
-
-        //发布已通过审核的小程序
-        if ($id == 11) {
-            wxUtil::miniRelease($merchant);
-        }
-
-        //撤回审核
-        if ($id == 12) {
-            wxUtil::rollbackCheck($merchant);
-        }
-        //生成 申请会员页 的小程序码
-        if ($id == 13) {
-            wxUtil::generateMemberCode($merchant);
-        }
-        //解绑小程序和公众号绑定的平台
-        if ($id == 14) {
-            wxUtil::unbindAccount($merchant);
-            wxUtil::unbindMiniProgram($merchant);
-        }
-        Yii::$app->end();
-
-        $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
-        print_r($r);
-        echo $miniAppId . ' ' . $openAppId . ' ';
-
-        $return = wxUtil::getOpenAccount($wxAppId, $merchant, false);
-        print_r($return);
-        die;
-
-        $return = wxUtil::createOpenAccount($wxAppId, $merchant);
-        print_r($return);
-        die;
-
-        $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, false);
-        print_r($r);
-        echo $miniAppId . ' ' . $openAppId . ' ';
-
-        $return = wxUtil::getOpenAccount($wxAppId, $merchant, false);
-        print_r($return);
-        $return = wxUtil::getOpenAccount($miniAppId, $merchant, false);
-        print_r($return);
-        die;
-
-        if ($return['errcode'] == 0) {
-            $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
-        } else {
-            $return = wxUtil::createOpenAccount($wxAppId, $merchant);
-            if ($return['errcode'] == 0) {
-                $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
-            }
-        }
-        echo "<br />openAppId:" . $openAppId . "<br />";
-        if (!empty($openAppId)) {
-            xhMerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
-            $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, false);
-            echo "绑定小程序结果:<br />";
-            print_r($r);
-        }
-        echo "<br /><br />";
-        $return = wxUtil::getOpenAccount($wxAppId, $merchant, false);
-        echo "微信appId:{$wxAppId}<br />";
-        print_r($return);
-        $return = wxUtil::getOpenAccount($miniAppId, $merchant, false);
-        echo "<br />小程序appId:{$miniAppId}<br />";
-        print_r($return);
-    }
-
-    //平台帐号激活 ssh 2020.2.15
-    public function actionAddPlatformMerchant()
-    {
-        MerchantService::initOpenMerchant();
-        echo 'ok';
-    }
-
-    //注释商家 ssh 2020.3.4
-    public function actionCancel()
-    {
-        if (getenv('YII_ENV') != 'test') {
-            util::fail('只有测试环境才能操作');
-        }
-        $id = Yii::$app->request->get('id', 0);
-        $merchant = MerchantService::getById($id, true);
-        if (isset($merchant->wxAppId) && empty($merchant->wxAppId)) {
-            util::fail('已注销/未授权');
-        }
-        $merchant->wxAppId = '';
-        $merchant->miniAppId = '';
-        $merchant->save();
-        $extend = MerchantExtendService::getByMerchantId($id, true);
-        $extend->miniAppId = '';
-        $extend->wxAppId = '';
-        $extend->save();
+        $get = Yii::$app->request->get();
+        $sjId = $get['sjId'] ?? '';
+        $ghsSjId = $get['ghsSjId'] ?? '';
+        if ($sjId == $ghsSjId) {
+            util::fail('不能绑自己');
+        }
+        $sj = MerchantClass::getMerchantById($sjId);
+        if (isset($sj['style']) == false || $sj['style'] != SjClass::STYLE_SUPPLIER) {
+            util::fail('城市供货商才能发起绑定');
+        }
+        $ghsSj = MerchantClass::getMerchantById($ghsSjId);
+        if (isset($ghsSj['style']) == false || $ghsSj['style'] != SjClass::STYLE_KM_SUPPLIER) {
+            util::fail('请选择昆明供货商');
+        }
+        $shop = ShopClass::getByCondition(['delStatus' => 0, 'merchantId' => $sjId]);
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+        $shopId = $shop['id'] ?? 0;
+
+        $ghsShop = ShopClass::getByCondition(['delStatus' => 0, 'merchantId' => $ghsSjId]);
+        if (empty($ghsShop)) {
+            util::fail('没有找到门店');
+        }
+        $ghsShopId = $ghsShop['id'] ?? 0;
+
+        $has = GhsClass::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'ghsSjId' => $ghsSjId, 'ghsShopId' => $ghsShopId]);
+        if (!empty($has)) {
+            util::fail('您已经绑定这个供货商了');
+        }
+        $name = $ghsSj['name'] ?? '';
+        $data = [
+            'name' => $name,
+            'sjId' => $sjId,
+            'ghsSjId' => $ghsSjId,
+            'py' => stringUtil::getSpelling($name),
+            'shopId' => $shopId,
+            'ghsShopId' => $ghsShopId,
+        ];
+        GhsClass::addGhs($data);
         util::complete();
     }
 
-    //商家h5商城二维码 ssh 2020.4.30
-    public function actionGetH5MallQrCode()
-    {
-        $id = Yii::$app->request->get('id', 0);
-        $imgUrl = MerchantService::getH5MallQrCode($id);
-        util::success(['imgUrl' => $imgUrl]);
-    }
-
 }

+ 64 - 68
app-pt/controllers/MerchantController.php

@@ -1,7 +1,9 @@
 <?php
 
 namespace pt\controllers;
+
 use biz\sj\classes\MerchantClass;
+use biz\sj\classes\SjClass;
 use biz\sj\services\MerchantExtendService;
 use Yii;
 use bizHd\admin\services\AdminService;
@@ -11,74 +13,68 @@ use common\components\util;
 class MerchantController extends BaseController
 {
 
-	//商家列表 ssh 2019.12.20
-	public function actionList()
-	{
-		$get = Yii::$app->request->get();
-		$style = $get['style'] ?? SjClass::STYLE_RETAIL;
-		$where = [];
-		if (!empty($style)) {
-			$where['style'] = $style;
-		}
-		$list = MerchantService::getMerchantList($where);
-		util::success($list);
-	}
+    //商家列表 ssh 2019.12.20
+    public function actionList()
+    {
+        $where = ['delStatus' => 0];
+        $list = MerchantService::getMerchantList($where);
+        util::success($list);
+    }
+
+    //获取当前登陆老板的帐号详情,官网购买套餐时使用 ssh 2020.1.11
+    public function actionLoginAccount()
+    {
+        $userId = $this->userId;
+        $admin = AdminService::getByCondition(['platUserId' => $userId]);
+        if (empty($admin)) {
+            util::fail('没有找到注册信息');
+        }
+        $merchantId = $admin['merchantId'];
+        $merchant = MerchantService::getMerchantById($merchantId);
+        util::success($merchant);
+    }
+
+    //商家信息 ssh 2020.1.11
+    public function actionDetail()
+    {
+        $merchant = MerchantService::getMerchantById(12358);
+        util::success($merchant);
+    }
+
+    //平台帐号激活 ssh 2020.2.15
+    public function actionAddPlatformMerchant()
+    {
+        MerchantService::initOpenMerchant();
+        echo 'ok';
+    }
+
+    //注释商家 ssh 2020.3.4
+    public function actionCancel()
+    {
+        if (getenv('YII_ENV') != 'test') {
+            util::fail('只有测试环境才能操作');
+        }
+        $id = Yii::$app->request->get('id', 0);
+        $merchant = MerchantService::getById($id, true);
+        if (isset($merchant->wxAppId) && empty($merchant->wxAppId)) {
+            util::fail('已注销/未授权');
+        }
+        $merchant->wxAppId = '';
+        $merchant->miniAppId = '';
+        $merchant->save();
+        $extend = MerchantExtendService::getByMerchantId($id, true);
+        $extend->miniAppId = '';
+        $extend->wxAppId = '';
+        $extend->save();
+        util::complete();
+    }
 
-	//获取当前登陆老板的帐号详情,官网购买套餐时使用 ssh 2020.1.11
-	public function actionLoginAccount()
-	{
-		$userId = $this->userId;
-		$admin = AdminService::getByCondition(['platUserId' => $userId]);
-		if (empty($admin)) {
-			util::fail('没有找到注册信息');
-		}
-		$merchantId = $admin['merchantId'];
-		$merchant = MerchantService::getMerchantById($merchantId);
-		util::success($merchant);
-	}
-	
-	//商家信息 ssh 2020.1.11
-	public function actionDetail()
-	{
-		$id = Yii::$app->request->get('id');
-		$merchant = MerchantService::getMerchantById(12358);
-		util::success($merchant);
-	}
+    //商家h5商城二维码 ssh 2020.4.30
+    public function actionGetH5MallQrCode()
+    {
+        $id = Yii::$app->request->get('id', 0);
+        $imgUrl = MerchantService::getH5MallQrCode($id);
+        util::success(['imgUrl' => $imgUrl]);
+    }
 
-	//平台帐号激活 ssh 2020.2.15
-	public function actionAddPlatformMerchant()
-	{
-		MerchantService::initOpenMerchant();
-		echo 'ok';
-	}
-	
-	//注释商家 ssh 2020.3.4
-	public function actionCancel()
-	{
-		if (getenv('YII_ENV') != 'test') {
-			util::fail('只有测试环境才能操作');
-		}
-		$id = Yii::$app->request->get('id', 0);
-		$merchant = MerchantService::getById($id, true);
-		if (isset($merchant->wxAppId) && empty($merchant->wxAppId)) {
-			util::fail('已注销/未授权');
-		}
-		$merchant->wxAppId = '';
-		$merchant->miniAppId = '';
-		$merchant->save();
-		$extend = MerchantExtendService::getByMerchantId($id, true);
-		$extend->miniAppId = '';
-		$extend->wxAppId = '';
-		$extend->save();
-		util::complete();
-	}
-	
-	//商家h5商城二维码 ssh 2020.4.30
-	public function actionGetH5MallQrCode()
-	{
-		$id = Yii::$app->request->get('id', 0);
-		$imgUrl = MerchantService::getH5MallQrCode($id);
-		util::success(['imgUrl' => $imgUrl]);
-	}
-	
 }

+ 16 - 0
app-pt/controllers/SjController.php

@@ -23,6 +23,10 @@ class SjController extends BaseController
         try {
             $apply['name'] = $name;
             $apply['style'] = SjClass::STYLE_KM_SUPPLIER;
+            $has = SjClass::getByCondition(['name' => $name]);
+            if (!empty($has)) {
+                util::fail('名称已经存在');
+            }
             MerchantService::initSjInfo($apply);
             $transaction->commit();
             util::complete();
@@ -32,4 +36,16 @@ class SjController extends BaseController
         }
     }
 
+    //商家列表 ssh 2019.12.20
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $where = ['delStatus' => 0];
+        if (isset($get['name']) && !empty($get['name'])) {
+            $where['name'] = ['like', $get['name']];
+        }
+        $list = MerchantService::getMerchantList($where);
+        util::success($list);
+    }
+
 }

+ 3 - 3
app-pt/controllers/WxOpenController.php

@@ -580,11 +580,11 @@ class WxOpenController extends PublicController
         dd($return);
     }
 
-    public function actionCheckMerchantName()
+    public function actionCheckname()
     {
         $get = Yii::$app->request->get();
-        $merchantName = isset($get['name']) ? $get['name'] : '';
-        $m = xhMerchantService::getByName($merchantName);
+        $name = isset($get['name']) ? $get['name'] : '';
+        $m = xhMerchantService::getByName($name);
         if (!empty($m)) {
             util::fail('公众号名称已经使用');
         }

+ 6 - 0
biz/ghs/classes/GhsClass.php

@@ -12,6 +12,12 @@ class GhsClass extends BaseClass
 
     public static $baseFile = '\biz\ghs\models\Ghs';
 
+    //增加供货商 shish 2021.3.29
+    public static function addGhs($data)
+    {
+        return self::add($data);
+    }
+
     //供货商列表 ssh 2021.1.24
     public static function getGhsList($where)
     {

+ 7 - 1
biz/sj/classes/SjClass.php

@@ -8,7 +8,7 @@ use bizHd\base\classes\BaseClass;
 class SjClass extends BaseClass
 {
 
-	public static $baseFile = '\biz\sj\models\Sj';
+    public static $baseFile = '\biz\sj\models\Sj';
 
     //零售店
     const STYLE_RETAIL = 1;
@@ -17,4 +17,10 @@ class SjClass extends BaseClass
     //昆明供货商
     const STYLE_KM_SUPPLIER = 3;
 
+    const STYLE_LIST = [
+        self::STYLE_RETAIL => '花店',
+        self::STYLE_SUPPLIER => '供货商',
+        self::STYLE_KM_SUPPLIER => '昆明供货商',
+    ];
+
 }

+ 4 - 12
biz/sj/services/MerchantService.php

@@ -2,6 +2,7 @@
 
 namespace biz\sj\services;
 
+use biz\sj\classes\SjClass;
 use bizHd\agent\classes\AgentAssetClass;
 use bizHd\auth\services\AuthService;
 use bizHd\goods\classes\GoodsSettingClass;
@@ -241,21 +242,12 @@ class MerchantService extends BaseService
     //商家列表 ssh 2019.12.20
     public static function getMerchantList($where)
     {
-        $data = MerchantClass::getList(['id', 'name'], $where, 'addTime DESC');
+        $data = MerchantClass::getList(['id', 'name','style'], $where, 'addTime DESC');
         $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
         if (empty($list)) {
             return $data;
         }
-
-        //商家资产
-        $merchantIdList = array_column($list, 'id');
-        $asset = MerchantAssetService::getAssetByMerchantIds($merchantIdList);
-
-        //套餐
-        $setIdList = array_column($list, 'setId');
-        $set = SetMealService::getSetByIds($setIdList);
-        //拓展
-        $ext = MerchantExtendService::getExtendByMerchantIds($merchantIdList);
+        $styleList = SjClass::STYLE_LIST;
         foreach ($list as $key => $val) {
             $val['adminName'] = '';
             $val['city'] = '厦门';
@@ -265,10 +257,10 @@ class MerchantService extends BaseService
             $val['totalUser'] = 500;
             $val['totalView'] = 100;
             $val['shopNum'] = 2;
-            $val['main'] = '零售';
             $val['setName'] = '标准版';
             $val['deadline'] = date("Y-m-d H:i:s");
             $val['status'] = '正常';
+            $val['currentStyle'] = $styleList[$val['style']] ?? '';
             $list[$key] = business::formatMerchantLogo($val);
         }
         $data['list'] = $list;