shish 5 лет назад
Родитель
Сommit
2c26c97ea9

+ 55 - 55
app/ghs/controllers/BaseController.php

@@ -16,65 +16,65 @@ use common\components\util;
 
 class BaseController extends PublicController
 {
-	public $admin, $adminId, $adminAvatar, $account;
-	public $ghsId = 0, $merchantName, $merchant, $merchantExtend, $merchantLogo, $signPackage, $shopId = 0;
-	public $appId;
-	public $isWx = false;
-	public $isLogin = false;
-	public $withoutLogin = [];//不需要登陆的方法名
-	public $validate = true;
+    public $admin, $adminId, $adminAvatar, $account;
+    public $ghsId = 0, $ghsName, $ghs, $ghsExtend, $ghsLogo, $signPackage, $shopId = 0;
+    public $appId;
+    public $isWx = false;
+    public $isLogin = false;
+    public $withoutLogin = [];//不需要登陆的方法名
+    public $validate = true;
 
-	//shish 2020.3.8
-	public function beforeAction($action)
-	{
-		//token验证
-		//$adminId = jwt::getLoginId();
-		//模拟用户
+    //shish 2020.3.8
+    public function beforeAction($action)
+    {
+        //token验证
+        //$adminId = jwt::getLoginId();
+        //模拟用户
         $adminId = 1;
-		$ghsId = 0;
-		$merchant = [];
-		$merchantExtend = [];
-		$admin = [];
-		if (empty($adminId)) {
-			$this->validate = false;
-		} else {
-			$admin = AdminService::getById($adminId);
-			if (empty($admin)) {
-				util::fail('帐号无效');
-			}
-			$adminId = $admin['id'];
-			//$shopId = Yii::$app->redis->executeCommand('GET', ['LOGIN_ADMIN_SHOP' . $adminId]);
-			//取不到门店id可能被清缓存,需要重新登陆,$shopId = 0 则表示非管理员,没有关联的门店,只可以访问官网
+        $ghsId = 0;
+        $ghs = [];
+        $ghsExtend = [];
+        $admin = [];
+        if (empty($adminId)) {
+            $this->validate = false;
+        } else {
+            $admin = AdminService::getById($adminId);
+            if (empty($admin)) {
+                util::fail('帐号无效');
+            }
+            $adminId = $admin['id'];
+            //$shopId = Yii::$app->redis->executeCommand('GET', ['LOGIN_ADMIN_SHOP' . $adminId]);
+            //取不到门店id可能被清缓存,需要重新登陆,$shopId = 0 则表示非管理员,没有关联的门店,只可以访问官网
             $staff = ShopAdminService::getByCondition(['adminId' => $adminId]);
             $shopId = isset($staff['shopId']) ? $staff['shopId'] : 0;
-			if (is_numeric($shopId) == false) {
-				util::notLogin('登陆已失效,请重新登陆');
-			}
-			if (!empty($shopId)) {
-				$shop = ShopService::getById($shopId);
-				if (empty($shop)) {
-					util::fail('没有找到门店');
-				}
-				$ghsId = $shop['ghsId'];
-				$merchant = MerchantService::getMerchantById($ghsId);
-				$merchantExtend = MerchantExtendService::getByMerchantId($ghsId);
-			}
-			$this->shopId = $shopId;
-		}
-		//游客可以访问的方法
-		if (in_array($action->id, $this->withoutLogin)) {
-			$this->validate = true;
-		}
-		if ($this->validate == false) {
-			util::notLogin('您还没有登陆哦');
-		}
-		$this->admin = $admin;
-		$this->adminId = $adminId;
-		$this->ghsId = $ghsId;
-		$this->merchant = $merchant;
-		$this->merchantExtend = $merchantExtend;
-		return parent::beforeAction($action);
-	}
+            if (is_numeric($shopId) == false) {
+                util::notLogin('登陆已失效,请重新登陆');
+            }
+            if (!empty($shopId)) {
+                $shop = ShopService::getById($shopId);
+                if (empty($shop)) {
+                    util::fail('没有找到门店');
+                }
+                $ghsId = $shop['ghsId'];
+                $ghs = MerchantService::getMerchantById($ghsId);
+                $ghsExtend = MerchantExtendService::getByMerchantId($ghsId);
+            }
+            $this->shopId = $shopId;
+        }
+        //游客可以访问的方法
+        if (in_array($action->id, $this->withoutLogin)) {
+            $this->validate = true;
+        }
+        if ($this->validate == false) {
+            util::notLogin('您还没有登陆哦');
+        }
+        $this->admin = $admin;
+        $this->adminId = $adminId;
+        $this->ghsId = $ghsId;
+        $this->ghs = $ghs;
+        $this->ghsExtend = $ghsExtend;
+        return parent::beforeAction($action);
+    }
 
 }
 

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

@@ -2,6 +2,7 @@
 
 namespace ghs\controllers;
 
+use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\services\CustomService;
 use common\components\stringUtil;
 use common\components\util;
@@ -36,4 +37,26 @@ class CustomController extends BaseController
         util::success($list);
     }
 
+    //客户详情 shish 2021.1.8
+    public function actionDetail()
+    {
+        $get = Yii::$app->request->get();
+        $shopId = isset($get['shopId']) ? $get['shopId'] : -1;
+        $ghsId = $this->ghsId;
+        $info = CustomService::getFullInfo($ghsId, $shopId);
+        util::success($info);
+    }
+
+    //允许月结开关 shish 2021.1.8
+    public function actionDebt()
+    {
+        $get = Yii::$app->request->get();
+        $debt = isset($get['debt']) ? $get['debt'] : 0;
+        $customId = isset($get['customId']) ? $get['customId'] : 0;
+        $custom = CustomClass::getById($customId);
+        CustomClass::valid($custom, $this->ghsId);
+        CustomClass::debt($custom, $debt);
+        util::complete();
+    }
+
 }

+ 20 - 1
biz-ghs/custom/classes/CustomClass.php

@@ -13,7 +13,7 @@ class CustomClass extends BaseClass
     public static $baseFile = '\bizGhs\custom\models\Custom';
 
     //组合信息 shish 2021.1.8
-    public static function groupUserBaseInfo($list)
+    public static function groupBaseInfo($list)
     {
         if (empty($list)) {
             return $list;
@@ -34,4 +34,23 @@ class CustomClass extends BaseClass
         return $list;
     }
 
+    //欠款权限开关 shish 2021.1.8
+    public static function debt($custom, $debt)
+    {
+        $id = isset($custom['id']) ? $custom['id'] : 0;
+        self::updateById($id, ['debt' => $debt]);
+        return true;
+    }
+
+    //权限判断 shish 2021.1.8
+    public static function valid($custom, $ghsId)
+    {
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+        if ($custom['ghsId'] != $ghsId) {
+            util::fail('您没有权限操作此客户');
+        }
+    }
+
 }

+ 20 - 1
biz-ghs/custom/services/CustomService.php

@@ -3,6 +3,8 @@
 namespace bizGhs\custom\services;
 
 use biz\base\services\BaseService;
+use biz\merchant\classes\ShopClass;
+use bizGhs\admin\classes\ShopAdminClass;
 use bizGhs\custom\classes\CustomClass;
 use Yii;
 
@@ -18,8 +20,25 @@ class CustomService extends BaseService
         if (empty($list)) {
             return $data;
         }
-        $data['list'] = CustomClass::groupUserBaseInfo($list);
+        $data['list'] = CustomClass::groupBaseInfo($list);
         return $data;
     }
 
+    //获取客户信息 shish 2021.1.8
+    public static function getFullInfo($ghsId, $shopId)
+    {
+        $custom = CustomClass::getByCondition(['ghsId' => $ghsId, 'shopId' => $shopId]);
+        if (empty($custom)) {
+            return [];
+        }
+        $list = CustomClass::groupBaseInfo([$custom]);
+        $custom = current($list);
+        $custom['no'] = 1254358;
+
+        $shopInfo = ShopClass::getAddressAndManager($shopId);
+        $custom['shopInfo'] = $shopInfo;
+
+        return $custom;
+    }
+
 }

+ 75 - 63
biz/admin/classes/ShopAdminClass.php

@@ -9,69 +9,81 @@ use biz\base\classes\BaseClass;
 
 class ShopAdminClass extends BaseClass
 {
-	
-	public static $baseFile = '\biz\admin\models\ShopAdmin';
-	
-	const GENERATE_ADMIN_DATA = 'generate_admin_data_';//创建管理员需要的数据
-	
-	//创建管理准备数据key shish 2020.4.17
-	public static function getGenerateAdminDataKey($shopId, $adminId)
-	{
-		return self::GENERATE_ADMIN_DATA . $shopId . '_' . $adminId;
-	}
-	
-	//创建管理员数据准备 shish 2020.4.17
-	public static function prepareBindAdmin($data)
-	{
-		$adminId = $data['adminId'];
-		$shopId = $data['shopId'];
-		$cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
-		$params = [$cacheKey];
-		if (!empty($data)) {
-			foreach ($data as $key => $val) {
-				if (!is_array($val)) {
-					$params[] = $key;
-					$params[] = $val;
-				}
-			}
-		}
-		Yii::$app->redis->executeCommand('HMSET', $params);
-	}
-	
-	//获取创建管理员需要的信息 shish 2020.4.20
-	public static function getBindAdminData($shopId, $adminId)
-	{
-		$cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
-		$cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
-		$data = [];
-		if (!empty($cacheData)) {
-			$data = [];
-			$list = [];
-			$x = 0;
-			foreach ($cacheData as $cKey => $cVal) {
-				if ($cKey % 2 == 0) {
-					$list[$x]['key'] = $cVal;
-				} else {
-					$list[$x]['value'] = $cVal;
-					$x++;
-				}
-			}
-			foreach ($list as $lKey => $lVal) {
-				$data[$lVal['key']] = $lVal['value'];
-			}
-		}
-		return $data;
-	}
 
-	//删除创建管理员需要的信息 shish 2020.4.20
-	public static function delBindAdminData($shopId, $adminId)
-	{
-		$cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
-		$keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
-		if (!empty($keyNameList)) {
-			$data = array_merge([$cacheKey], $keyNameList);
-			$cacheData = Yii::$app->redis->executeCommand('HDEL', $data);
-		}
-	}
+    public static $baseFile = '\biz\admin\models\ShopAdmin';
+
+    const GENERATE_ADMIN_DATA = 'generate_admin_data_';//创建管理员需要的数据
+
+    //创建管理准备数据key shish 2020.4.17
+    public static function getGenerateAdminDataKey($shopId, $adminId)
+    {
+        return self::GENERATE_ADMIN_DATA . $shopId . '_' . $adminId;
+    }
+
+    //创建管理员数据准备 shish 2020.4.17
+    public static function prepareBindAdmin($data)
+    {
+        $adminId = $data['adminId'];
+        $shopId = $data['shopId'];
+        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $params = [$cacheKey];
+        if (!empty($data)) {
+            foreach ($data as $key => $val) {
+                if (!is_array($val)) {
+                    $params[] = $key;
+                    $params[] = $val;
+                }
+            }
+        }
+        Yii::$app->redis->executeCommand('HMSET', $params);
+    }
+
+    //获取创建管理员需要的信息 shish 2020.4.20
+    public static function getBindAdminData($shopId, $adminId)
+    {
+        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
+        $data = [];
+        if (!empty($cacheData)) {
+            $data = [];
+            $list = [];
+            $x = 0;
+            foreach ($cacheData as $cKey => $cVal) {
+                if ($cKey % 2 == 0) {
+                    $list[$x]['key'] = $cVal;
+                } else {
+                    $list[$x]['value'] = $cVal;
+                    $x++;
+                }
+            }
+            foreach ($list as $lKey => $lVal) {
+                $data[$lVal['key']] = $lVal['value'];
+            }
+        }
+        return $data;
+    }
+
+    //删除创建管理员需要的信息 shish 2020.4.20
+    public static function delBindAdminData($shopId, $adminId)
+    {
+        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
+        if (!empty($keyNameList)) {
+            $data = array_merge([$cacheKey], $keyNameList);
+            $cacheData = Yii::$app->redis->executeCommand('HDEL', $data);
+        }
+    }
+
+    //取店长 shish 2021.1.8
+    public static function getManager($shopId)
+    {
+        $relate = self::getByCondition(['shopId' => $shopId]);
+        $adminId = isset($relate['adminId']) ? $relate['adminId'] : 0;
+        $info = [];
+        if (!empty($adminId)) {
+            $info = AdminClass::getById($adminId);
+        }
+        return $info;
+    }
 
 }

+ 92 - 80
biz/merchant/classes/ShopClass.php

@@ -2,6 +2,7 @@
 
 namespace biz\merchant\classes;
 
+use biz\admin\classes\ShopAdminClass;
 use common\components\dirUtil;
 use common\components\httpUtil;
 use common\components\qrCodeUtil;
@@ -12,85 +13,96 @@ use biz\base\classes\BaseClass;
 
 class ShopClass extends BaseClass
 {
-	
-	public static $baseFile = '\biz\merchant\models\Shop';
-	
-	public static function getShopList($where)
-	{
-		$list = self::getList('*', $where, 'addTime DESC');
-		return $list;
-	}
-	
-	//获取商家默认的门店ID shish 2020.1.19
-	public static function getDefaultShopId($merchant)
-	{
-		return isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
-	}
-	
-	//创建门店 shish 2020.2.8
-	public static function addShop($data)
-	{
-		$data['createTime'] = date("Y-m-d H:i:s");
-		$shopName = isset($data['shopName']) ? $data['shopName'] : '';
-		if (empty($shopName)) {
-			util::fail('请填写门店名称');
-		}
-		$exists = self::getByCondition(['merchantId' => $data['merchantId'], 'shopName' => $shopName]);
-		if (!empty($exists)) {
-			util::fail('门店名称已经存在');
-		}
-		$shop = self::add($data);
-		
-		return $shop;
-	}
-	
-	//更新门店 shish 2020.2.29
-	public static function updateShop($id, $data)
-	{
-		$shopName = isset($data['shopName']) ? $data['shopName'] : '';
-		$merchantId = $data['merchantId'];
-		$findShop = self::getByCondition(['merchantId' => $merchantId, 'shopName' => $shopName]);
-		if (!empty($findShop) && $findShop['id'] != $id) {
-			util::fail('门店名称已经存在');
-		}
-		return self::updateById($id, $data);
-	}
-	
-	//取商家所有门店 shish 2020.2.29
-	public static function getAllShop($merchantId)
-	{
-		return self::getAllByCondition(['merchantId' => $merchantId]);
-	}
-	
-	//验证所属权限 shish 2020.2.29
-	public static function valid($shop, $merchantId)
-	{
-		if (empty($shop)) {
-			util::fail('门店无效');
-		}
-		if (isset($shop['merchantId']) == false || $shop['merchantId'] != $merchantId) {
-			util::fail('您没有权限访问');
-		}
-	}
-	
-	//删除门店 shish 2020.3.1
-	public static function deleteShop($shop)
-	{
-		if (isset($shop['default']) && $shop['default'] == 1) {
-			util::fail('默认门店不允许删除');
-		}
-		$id = $shop['id'];
-		self::updateById($id, ['delStatus' => 1]);
-	}
-	
-	//生成收款码 shish 2020.3.9
-	public static function generateGatheringCode($merchantId, $shopId)
-	{
-		$url = Yii::$app->params['mallDomain'] . "/#/pages/pay/index?account={$merchantId}&shopId=" . $shopId;
-		//强制转成https
-		$url = httpUtil::becomeHttps($url);
-		$gatheringCode = qrCodeUtil::generateGatheringQrCode($url, $merchantId, $shopId, '', 10);
-		return $gatheringCode;
-	}
+
+    public static $baseFile = '\biz\merchant\models\Shop';
+
+    public static function getShopList($where)
+    {
+        $list = self::getList('*', $where, 'addTime DESC');
+        return $list;
+    }
+
+    //获取商家默认的门店ID shish 2020.1.19
+    public static function getDefaultShopId($merchant)
+    {
+        return isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
+    }
+
+    //创建门店 shish 2020.2.8
+    public static function addShop($data)
+    {
+        $data['createTime'] = date("Y-m-d H:i:s");
+        $shopName = isset($data['shopName']) ? $data['shopName'] : '';
+        if (empty($shopName)) {
+            util::fail('请填写门店名称');
+        }
+        $exists = self::getByCondition(['merchantId' => $data['merchantId'], 'shopName' => $shopName]);
+        if (!empty($exists)) {
+            util::fail('门店名称已经存在');
+        }
+        $shop = self::add($data);
+
+        return $shop;
+    }
+
+    //更新门店 shish 2020.2.29
+    public static function updateShop($id, $data)
+    {
+        $shopName = isset($data['shopName']) ? $data['shopName'] : '';
+        $merchantId = $data['merchantId'];
+        $findShop = self::getByCondition(['merchantId' => $merchantId, 'shopName' => $shopName]);
+        if (!empty($findShop) && $findShop['id'] != $id) {
+            util::fail('门店名称已经存在');
+        }
+        return self::updateById($id, $data);
+    }
+
+    //取商家所有门店 shish 2020.2.29
+    public static function getAllShop($merchantId)
+    {
+        return self::getAllByCondition(['merchantId' => $merchantId]);
+    }
+
+    //验证所属权限 shish 2020.2.29
+    public static function valid($shop, $merchantId)
+    {
+        if (empty($shop)) {
+            util::fail('门店无效');
+        }
+        if (isset($shop['merchantId']) == false || $shop['merchantId'] != $merchantId) {
+            util::fail('您没有权限访问');
+        }
+    }
+
+    //删除门店 shish 2020.3.1
+    public static function deleteShop($shop)
+    {
+        if (isset($shop['default']) && $shop['default'] == 1) {
+            util::fail('默认门店不允许删除');
+        }
+        $id = $shop['id'];
+        self::updateById($id, ['delStatus' => 1]);
+    }
+
+    //生成收款码 shish 2020.3.9
+    public static function generateGatheringCode($merchantId, $shopId)
+    {
+        $url = Yii::$app->params['mallDomain'] . "/#/pages/pay/index?account={$merchantId}&shopId=" . $shopId;
+        //强制转成https
+        $url = httpUtil::becomeHttps($url);
+        $gatheringCode = qrCodeUtil::generateGatheringQrCode($url, $merchantId, $shopId, '', 10);
+        return $gatheringCode;
+    }
+
+    //取门店店长信息和地址信息
+    public static function getAddressAndManager($shopId)
+    {
+        $shop = ShopClass::getById($shopId);
+        $manager = ShopAdminClass::getManager($shopId);
+        $name = isset($manager['adminName']) ? $manager['adminName'] : '';
+        $mobile = isset($manager['mobile']) ? $manager['mobile'] : '';
+        $address = isset($shop['fullAddress']) ? $shop['fullAddress'] : '';
+        return ['userName' => $name, 'mobile' => $mobile, 'address' => $address];
+    }
 
 }

+ 11 - 1
doc/开发规范.md

@@ -42,7 +42,17 @@ condition支持查询条件包括
 
 
 
-##### 命名规范
+##### service和class里的新方法命名规范建议
+````
+获取详情:getInfo getUserInfo getMerchantInfo
+
+获取列表:getList getUserList getMerchantlist
+
+````
+
+
+
+##### 文件命名规范
 
 数据库表和文件都使用驼峰式的
 

+ 6 - 1
sql.sql

@@ -203,4 +203,9 @@ isOpen TINYINT NOT NULL DEFAULT 0 COMMENT '是否开店 0没有 1已开',
 )COMMENT='供货商客户';
 
 ALTER TABLE xhGhsShop CHANGE `merchantId` ghsId INT NOT NULL DEFAULT 0 COMMENT '供货商id';
-ALTER TABLE xhGhsShop CHANGE `merchantName` ghsName VARCHAR(100) NOT NULL DEFAULT '' COMMENT '供货商名称';
+ALTER TABLE xhGhsShop CHANGE `merchantName` ghsName VARCHAR(100) NOT NULL DEFAULT '' COMMENT '供货商名称';
+ALTER TABLE `xhGhsCustom` ADD debt TINYINT NOT NULL DEFAULT 0 COMMENT '是否允许欠款买花 0不允许 1允许' AFTER `isOpen`;
+ALTER TABLE `xhGhsCustom` ADD debtAmount DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '欠款金额' AFTER `debt`;
+ALTER TABLE `xhGhsCustom` ADD buyNum INT NOT NULL DEFAULT 0 COMMENT '消费次数' AFTER `debtAmount`;
+ALTER TABLE `xhGhsCustom` ADD buyAmount DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '消费总金额' AFTER `buyNum`;
+ALTER TABLE xhGhsShopAdmin CHANGE merchantId `ghsId` INT NOT NULL DEFAULT 0 COMMENT '供货商id merchantId';