shish 6 tahun lalu
induk
melakukan
38ad062bf8

+ 206 - 200
biz/merchant/classes/MerchantClass.php

@@ -17,205 +17,211 @@ use biz\base\classes\BaseClass;
 
 class MerchantClass extends BaseClass
 {
-	
-	public static $baseFile = '\biz\merchant\models\Merchant';
-	
-	//常用链接
-	public static $commonUrl = [
-		1 => ['id' => 1, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '商城'],
-		2 => ['id' => 2, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '申请会员'],
-		3 => ['id' => 3, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '点我付款'],
-	];
-	
-	//商家信息组合 shish 2019.12.20
-	public static function groupMerchantBaseInfo($list)
-	{
-		return $list;
-	}
-	
-	public static function getMerchantByIds($ids)
-	{
-		return self::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
-	}
-	
-	public static function getMerchantById($id)
-	{
-		$merchant = self::getById($id);
-		if (empty($merchant)) {
-			return $merchant;
-		}
-		$list = self::groupBaseInfo([$merchant]);
-		return current($list);
-	}
-	
-	public static function groupBaseInfo($list)
-	{
-		foreach ($list as $key => $val) {
-			$list[$key] = business::formatMerchantLogo($list[$key]);
-			$list[$key]['address'] = '福建省厦门市思明区上湖社1017号';
-		}
-		return $list;
-	}
-	
-	//创建商家信息 shish 2020.2.11
-	public static function generateMerchant($data)
-	{
-		//生成商家
-		$date = date("Y-m-d H:i:s");
-		$time = time();
-		$data['accountStyle'] = 0;//认证服务号
-		$data['status'] = 0;//待审核
-		$data['createTime'] = $date;
-		$data['updateTime'] = $date;
-		$data['shopLat'] = isset($data['lat']) ? $data['lat'] : (string)0;
-		$data['shopLong'] = isset($data['long']) ? $data['long'] : (string)0;
-		$data['shopPrecision'] = (string)0;
-		$data['wxToken'] = stringUtil::buildWxToken(0);
-		$data['shopPhotoList'] = isset($data['shopPhotoList']) ? $data['shopPhotoList'] : '';
-		$data['merchantName'] = isset($data['merchantName']) ? $data['merchantName'] : '';
-		$data['shopProvince'] = isset($data['province']) ? $data['province'] : '';
-		$data['shopCity'] = isset($data['city']) ? $data['city'] : '';
-		$data['shopDist'] = isset($data['dist']) ? $data['dist'] : '';
-		$data['shopAddress'] = isset($data['address']) ? $data['address'] : '';
-		$data['alipayAccount'] = isset($data['alipayAccount']) ? $data['alipayAccount'] : '';
-		$data['alipayAccountName'] = isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '';
-		//默认设置为代理商
-		$data['agentLevel'] = 1;
-		//申请表的id去掉,商家有自己的id
-		unset($data['id']);
-		$merchant = self::add($data);
-		$adminId = $data['adminId'];
-		$merchantId = $merchant['id'];
-		$mobile = $data['mobile'];
-		//生成商家资产
-		$assetData = [
-			'balance' => 0,
-			'totalVisit' => 0,
-			'totalUser' => 0,
-			'totalMember' => 0,
-			'totalFans' => 0,
-			'totalWeixinFans' => 0,
-			'totalIntegral' => 0,
-			'totalPoint' => 0,
-			'totalGoods' => 0,
-			'totalRecharge' => 0,
-			'totalOrder' => 0,
-			'totalDeal' => 0,
-			'merchantId' => $merchantId,
-			'totalIncome' => 0,
-			'totalExpend' => 0,
-			'createTime' => $date,
-			'updateTime' => $date,
-		];
-		//商家资产表
-		MerchantAssetClass::add($assetData);
-		
-		//生成商家拓展信息
-		$extendData = [
-			'merchantId' => $merchantId,
-			'wxAppId' => isset($data['wxAppId']) ? $data['wxAppId'] : '',
-			'webTitle' => isset($data['merchantName']) ? $data['merchantName'] : '',
-			'webKeyword' => isset($data['merchantName']) ? $data['merchantName'] : '',
-			'webDescription' => isset($data['merchantName']) ? $data['merchantName'] : '',
-			'wxMenuInit' => 0,
-			'wxTMessageInit' => 0,
-			'payment' => 0,//支付功能关闭
-			'recharge' => 0,//充值功能关闭
-			'giveCoupon' => 1,//默认赠送代金劵
-			'giveCouponPrice' => 5,//代金劵金额5元
-			'couponMeetPrice' => 180,//满足金额
-			'couponValidity' => 30,//代金劵有效期30天
-			'alipayAccount' => isset($data['alipayAccount']) ? $data['alipayAccount'] : '',//提现的支付宝帐号
-			'alipayAccountName' => isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '',//提现支付宝帐号姓名
-			'gradeList' => '1_2000_0.9I2_5000_0.88I3_10000_0.85I4_20000_0.8',//1 级会员需要满 2000 积分 购物享9折;2 级会员需要满 5000 积分 购物享88折
-			'createTime' => $date,
-			'updateTime' => $date,
-		];
-		MerchantExtendClass::add($extendData);
-		
-		MerchantInitClass::add(['merchantId' => $merchantId]);
-		
-		//商家商品配置信息
-		$setData = [
-			'merchantId' => $merchantId,
-			'riseType' => 0,
-			'riseAmount' => 0,
-			'addTime' => time(),
-		];
-		GoodsSettingClass::add($setData);
-		
-		//创建门店
-		$shopData = [
-			'shopName' => $merchant['merchantName'],
-			'merchantId' => $merchantId,
-			'addTime' => $time,
-			'createTime' => $date,
-			'updateTime' => $date,
-			'openTime' => '8:00 - 23:00',
-			'telephone' => $mobile,
-			'introduction' => '欢迎光临',
-			'province' => isset($data['province']) ? $data['province'] : '',
-			'city' => isset($data['city']) ? $data['city'] : '',
-			'dist' => isset($data['dist']) ? $data['dist'] : '',
-			'default' => 1,
-			'address' => isset($data['address']) ? $data['address'] : '',
-			'fullAddress' => isset($data['fullAddress']) ? $data['fullAddress'] : '',
-		];
-		$shopReturn = ShopClass::addShop($shopData);
-		$shopId = $shopReturn['id'];
-		//设置商家默认门店
-		MerchantClass::updateById($merchantId, ['defaultShopId' => $shopId]);
-		
-		//创建管理员角色
-		$hasRole = AdminRoleClass::getByCondition(['merchantId' => $merchantId]);
-		if (empty($hasRole)) {
-			AdminRoleClass::addAdminRole(['roleName' => '店员', 'merchantId' => $merchantId, 'auth' => '*']);
-			$roleReturn = AdminRoleClass::addAdminRole(['roleName' => '老板', 'merchantId' => $merchantId, 'auth' => '*']);
-			$roleId = $roleReturn['id'];
-		}
-		
-		//创建管理员
-		$shopAdmin = ShopAdminClass::getByCondition(['shopId' => $shopId, 'adminId' => $adminId]);
-		if (empty($shopAdmin)) {
-			$adminData = [
-				'password' => password_hash($mobile, PASSWORD_BCRYPT),
-				'confirmPassword' => password_hash($mobile, PASSWORD_BCRYPT),
-				'mobile' => $mobile
-			];
-			AdminClass::updateById($adminId, $adminData);
-			$shopData = [
-				'adminId' => $adminId,
-				'shopId' => $shopId,
-				'merchantId' => $merchantId,
-				'remind' => 1,
-				'roleId' => $roleId,
-				'default' => 1,
-				'addTime' => $time,
-			];
-			print_r($shopData);
-			ShopAdminClass::add($shopData);
-		}
-		
-		//商品和分类初始化
-		CategoryClass::initCategoryGoods($merchantId);
-		
-		//商城和门店广告初始化
-		AdClass::initAdd($merchantId);
-		
-		//优惠券资产与配置信息初始化
-		CouponAssetClass::add(['merchantId' => $merchantId, 'switch' => 1]);
-		
-		return $merchant;
-	}
-	
-	//h5商城链接二维码 shish 2020.4.30
-	public static function getH5MallQrCode($id)
-	{
-		$url = Yii::$app->params['mallDomain'] . "/#/?account=" . $id;
-		//强制转成https
-		$url = httpUtil::becomeHttps($url);
-		$respond = qrCodeUtil::generateH5MallQrCode($url);
-		return isset($respond['url']) ? $respond['url'] : '';
-	}
+
+    public static $baseFile = '\biz\merchant\models\Merchant';
+
+    //常用链接
+    public static $commonUrl = [
+        1 => ['id' => 1, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '商城'],
+        2 => ['id' => 2, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '申请会员'],
+        3 => ['id' => 3, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '点我付款'],
+    ];
+
+    //商家信息组合 shish 2019.12.20
+    public static function groupMerchantBaseInfo($list)
+    {
+        return $list;
+    }
+
+    public static function getMerchantByIds($ids)
+    {
+        return self::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
+    }
+
+    public static function getMerchantById($id)
+    {
+        $merchant = self::getById($id);
+        if (empty($merchant)) {
+            return $merchant;
+        }
+        $list = self::groupBaseInfo([$merchant]);
+        return current($list);
+    }
+
+    public static function groupBaseInfo($list)
+    {
+        foreach ($list as $key => $val) {
+            $list[$key] = business::formatMerchantLogo($list[$key]);
+            $list[$key]['address'] = '福建省厦门市思明区上湖社1017号';
+        }
+        return $list;
+    }
+
+    //创建商家信息 shish 2020.2.11
+    public static function generateMerchant($data)
+    {
+        //生成商家
+        $date = date("Y-m-d H:i:s");
+        $time = time();
+        $data['accountStyle'] = 0;//认证服务号
+        $data['status'] = 0;//待审核
+        $data['createTime'] = $date;
+        $data['updateTime'] = $date;
+        $data['shopLat'] = isset($data['lat']) ? $data['lat'] : (string)0;
+        $data['shopLong'] = isset($data['long']) ? $data['long'] : (string)0;
+        $data['shopPrecision'] = (string)0;
+        $data['wxToken'] = stringUtil::buildWxToken(0);
+        $data['shopPhotoList'] = isset($data['shopPhotoList']) ? $data['shopPhotoList'] : '';
+        $data['merchantName'] = isset($data['merchantName']) ? $data['merchantName'] : '';
+        $data['shopProvince'] = isset($data['province']) ? $data['province'] : '';
+        $data['shopCity'] = isset($data['city']) ? $data['city'] : '';
+        $data['shopDist'] = isset($data['dist']) ? $data['dist'] : '';
+        $data['shopAddress'] = isset($data['address']) ? $data['address'] : '';
+        $data['alipayAccount'] = isset($data['alipayAccount']) ? $data['alipayAccount'] : '';
+        $data['alipayAccountName'] = isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '';
+        //默认设置为代理商
+        $data['agentLevel'] = 1;
+        //申请表的id去掉,商家有自己的id
+        unset($data['id']);
+        $merchant = self::add($data);
+        $adminId = $data['adminId'];
+        $merchantId = $merchant['id'];
+        $mobile = $data['mobile'];
+        //生成商家资产
+        $assetData = [
+            'balance' => 0,
+            'totalVisit' => 0,
+            'totalUser' => 0,
+            'totalMember' => 0,
+            'totalFans' => 0,
+            'totalWeixinFans' => 0,
+            'totalIntegral' => 0,
+            'totalPoint' => 0,
+            'totalGoods' => 0,
+            'totalRecharge' => 0,
+            'totalOrder' => 0,
+            'totalDeal' => 0,
+            'merchantId' => $merchantId,
+            'totalIncome' => 0,
+            'totalExpend' => 0,
+            'createTime' => $date,
+            'updateTime' => $date,
+        ];
+        //商家资产表
+        MerchantAssetClass::add($assetData);
+
+        //生成商家拓展信息
+        $extendData = [
+            'merchantId' => $merchantId,
+            'wxAppId' => isset($data['wxAppId']) ? $data['wxAppId'] : '',
+            'webTitle' => isset($data['merchantName']) ? $data['merchantName'] : '',
+            'webKeyword' => isset($data['merchantName']) ? $data['merchantName'] : '',
+            'webDescription' => isset($data['merchantName']) ? $data['merchantName'] : '',
+            'wxMenuInit' => 0,
+            'wxTMessageInit' => 0,
+            'payment' => 0,//支付功能关闭
+            'recharge' => 0,//充值功能关闭
+            'giveCoupon' => 1,//默认赠送代金劵
+            'giveCouponPrice' => 5,//代金劵金额5元
+            'couponMeetPrice' => 180,//满足金额
+            'couponValidity' => 30,//代金劵有效期30天
+            'alipayAccount' => isset($data['alipayAccount']) ? $data['alipayAccount'] : '',//提现的支付宝帐号
+            'alipayAccountName' => isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '',//提现支付宝帐号姓名
+            'gradeList' => '1_2000_0.9I2_5000_0.88I3_10000_0.85I4_20000_0.8',//1 级会员需要满 2000 积分 购物享9折;2 级会员需要满 5000 积分 购物享88折
+            'createTime' => $date,
+            'updateTime' => $date,
+        ];
+        MerchantExtendClass::add($extendData);
+
+        MerchantInitClass::add(['merchantId' => $merchantId]);
+
+        //商家商品配置信息
+        $setData = [
+            'merchantId' => $merchantId,
+            'riseType' => 0,
+            'riseAmount' => 0,
+            'addTime' => time(),
+        ];
+        GoodsSettingClass::add($setData);
+
+        //创建门店
+        $shopData = [
+            'shopName' => $merchant['merchantName'],
+            'merchantId' => $merchantId,
+            'addTime' => $time,
+            'createTime' => $date,
+            'updateTime' => $date,
+            'openTime' => '8:00 - 23:00',
+            'telephone' => $mobile,
+            'introduction' => '欢迎光临',
+            'province' => isset($data['province']) ? $data['province'] : '',
+            'city' => isset($data['city']) ? $data['city'] : '',
+            'dist' => isset($data['dist']) ? $data['dist'] : '',
+            'default' => 1,
+            'address' => isset($data['address']) ? $data['address'] : '',
+            'fullAddress' => isset($data['fullAddress']) ? $data['fullAddress'] : '',
+        ];
+        $shopReturn = ShopClass::addShop($shopData);
+        $shopId = $shopReturn['id'];
+        //设置商家默认门店
+        MerchantClass::updateById($merchantId, ['defaultShopId' => $shopId]);
+
+        //创建管理员角色
+        $hasRole = AdminRoleClass::getByCondition(['merchantId' => $merchantId]);
+        if (empty($hasRole)) {
+            AdminRoleClass::addAdminRole(['roleName' => '店员', 'merchantId' => $merchantId, 'auth' => '*']);
+            $roleReturn = AdminRoleClass::addAdminRole(['roleName' => '老板', 'merchantId' => $merchantId, 'auth' => '*']);
+            $roleId = $roleReturn['id'];
+        }
+
+        //创建管理员
+        $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $shopId, 'adminId' => $adminId]);
+        if (empty($shopAdmin)) {
+            $adminData = [
+                'password' => password_hash($mobile, PASSWORD_BCRYPT),
+                'confirmPassword' => password_hash($mobile, PASSWORD_BCRYPT),
+                'mobile' => $mobile
+            ];
+            AdminClass::updateById($adminId, $adminData);
+            $shopData = [
+                'adminId' => $adminId,
+                'shopId' => $shopId,
+                'merchantId' => $merchantId,
+                'remind' => 1,
+                'roleId' => $roleId,
+                'default' => 1,
+                'addTime' => $time,
+            ];
+            print_r($shopData);
+            ShopAdminClass::add($shopData);
+        }
+
+        //商品和分类初始化
+        CategoryClass::initCategoryGoods($merchantId);
+
+        //商城和门店广告初始化
+        AdClass::initAdd($merchantId);
+
+        //优惠券资产与配置信息初始化
+        CouponAssetClass::add(['merchantId' => $merchantId, 'switch' => 1]);
+
+        return $merchant;
+    }
+
+    //h5商城链接二维码 shish 2020.4.30
+    public static function getH5MallQrCode($id)
+    {
+        $url = Yii::$app->params['mallDomain'] . "/#/?account=" . $id;
+        //强制转成https
+        $url = httpUtil::becomeHttps($url);
+        $respond = qrCodeUtil::generateH5MallQrCode($url);
+        return isset($respond['url']) ? $respond['url'] : '';
+    }
+
+    public static function getDefaultShopId($merchant)
+    {
+        $defaultShopId = isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
+        return $defaultShopId;
+    }
 
 }

+ 197 - 198
biz/merchant/services/MerchantService.php

@@ -25,202 +25,201 @@ use Yii;
 
 class MerchantService extends BaseService
 {
-	
-	public static $baseFile = '\biz\merchant\classes\MerchantClass';
-	
-	//商家在业务端的权限 shish 2019.11.25
-	public static function getAuthIdList($merchantId, $endId)
-	{
-		$merchant = self::getById($merchantId);
-		$setId = $merchant['setId'];
-		if (empty($setId)) {
-			util::fail('没有找到商家的套餐');
-		}
-		
-		//业务端总共有哪些权限
-		$idList = AuthService::getListId($endId);
-		
-		//套餐在业务端有哪些权限
-		$setIdList = SetAuthService::getAuthIdList($setId, $endId);
-		
-		//有*号表示有所有的权限
-		$commonIdList = in_array('*', $setIdList) ? $idList : array_intersect($idList, $setIdList);
-		
-		return $commonIdList;
-		
-	}
-	
-	//获取默认门店
-	public static function getDefaultShopId($merchant)
-	{
-		$defaultShopId = isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
-		return $defaultShopId;
-	}
-	
-	//商家基本信息,$sensitive true 除敏感信息 shish 2019.12.8
-	public static function getInfo($merchant, $extend, $sensitive = true)
-	{
-		if ($sensitive) {
-			$delete = ['miniAppId', 'miniAppSecret', 'wxAppId', 'wxAppSecret', 'openAppId', 'wxToken', 'wxJsApiTicket', 'wxAccessToken', 'wxRefreshToken'];
-			foreach ($delete as $del) {
-				unset($merchant[$del]);
-			}
-			$deleteExtend = ['miniAppId', 'miniAccessToken', 'miniRefreshToken', 'wxPayKey', 'wxPayMerchantId', 'wxAppId'];
-			foreach ($deleteExtend as $delExtend) {
-				unset($extend[$delExtend]);
-			}
-		}
-		$merchant['extend'] = $extend;
-		return $merchant;
-	}
-	
-	//常用链接 shish 2019.12.19
-	public static function getCommonUrlList()
-	{
-		$list = MerchantClass::$commonUrl;
-		return array_values($list);
-	}
-	
-	//取指定常用链接 shish 2019.12.28
-	public static function getCommonUrl($id)
-	{
-		$list = MerchantClass::$commonUrl;
-		return isset($list[$id]) ? $list[$id] : [];
-	}
-	
-	//取平台下的商家 shish 2019.12.20
-	public static function getSaasMerchant($where)
-	{
-		$data = MerchantClass::getList('*', $where, 'addTime DESC');
-		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
-		if (empty($list)) {
-			return $data;
-		}
-		
-		//管理员
-		$adminIdList = array_column($list, 'adminId');
-		$admin = AdminService::getAdminByIds($adminIdList, null, 'id');
-		//商家资产
-		$merchantIdList = array_column($list, 'id');
-		$asset = MerchantAssetService::getAssetByMerchantIds($merchantIdList);
-		//套餐
-		$setIdList = array_column($list, 'setId');
-		$set = SetMealService::getSetByIds($setIdList);
-		//拓展
-		$ext = MerchantExtendService::getExtendByMerchantIds($merchantIdList);
-		foreach ($list as $key => $val) {
-			$adminId = $val['adminId'];
-			$merchantId = $val['id'];
-			$setId = $val['setId'];
-			$val['adminName'] = isset($admin[$adminId]['adminName']) ? $admin[$adminId]['adminName'] : '';
-			$val['merchantAsset'] = isset($asset[$merchantId]) ? $asset[$merchantId] : [];
-			$val['setMealName'] = isset($set[$setId]) ? $set[$setId]['name'] : '';
-			$val['extend'] = isset($ext[$merchantId]) ? $ext[$merchantId] : [];
-			$list[$key] = business::formatMerchantLogo($val);
-		}
-		$data['list'] = $list;
-		return $data;
-	}
-	
-	//根据id批量取商家 shish 2019.12.20
-	public static function getMerchantByIds($ids)
-	{
-		return MerchantClass::getMerchantByIds($ids);
-	}
-	
-	//获取商家 shish 2019.12.30
-	public static function getMerchantById($id)
-	{
-		return MerchantClass::getMerchantById($id);
-	}
-	
-	public static function getCurrentSetId($id)
-	{
-		return MerchantClass::getCurrentSetId($id);
-	}
-	
-	//开店公众号授权之后初始化 shish 2020.2.7
-	public static function openShopInit($data)
-	{
-		$merchantId = $data['merchantId'];
-		$merchant = MerchantClass::getMerchantById($merchantId);
-		if (empty($merchant)) {
-			return false;
-		}
-		$extend = MerchantExtendClass::getByMerchantId($merchantId);
-		if (isset($extend['init']) && $extend['init'] == 1) {
-			return true;
-		}
-		//事务处理
-		$connection = Yii::$app->db;
-		$transaction = $connection->beginTransaction();
-		try {
-			
-			//初始化微信菜单
-			$hasMenu = WxMenuService::getByCondition(['merchantId' => $merchantId]);
-			if (empty($hasMenu)) {
-				xhWxMenuService::applyInit($merchant);
-			}
-			
-			//微信客户初始化
-			$hasUser = UserService::getByCondition(['merchantId' => $merchantId]);
-			if (empty($hasUser)) {
-				$return = UserService::syncWxAllUser($merchantId);
-				$totalNum = isset($return['total']) ? $return['total'] : 0;
-				MerchantAssetClass::updateByCondition(['merchantId' => $merchantId], ['totalFans' => $totalNum, 'totalUser' => $totalNum]);
-			}
-			
-			//模板消息
-			$hasMessage = TMessageService::getByCondition(['merchantId' => $merchantId]);
-			if (empty($hasMessage)) {
-				xhTMessageService::init($merchant);
-			}
-			
-			//完成初始化标识
-			MerchantExtendClass::updateByCondition(['merchantId' => $merchantId], ['init' => 1]);
-			
-			//代理资产
-			AgentAssetClass::add(['merchantId' => $merchantId]);
-			
-			$transaction->commit();
-			return true;
-		} catch (Exception $e) {
-			$transaction->rollBack();
-			return false;
-		}
-	}
-	
-	//初始化平台的商家 shish 2020.2.11
-	public static function initOpenMerchant()
-	{
-		$open = WxOpenClass::getOpen();
-		if (isset($open['wx_base_id']) && !empty($open['wx_base_id']) && isset($open['wx_mini_base_id']) && !empty($open['wx_mini_base_id'])) {
-			util::stop('已初始化,无需重复操作');
-		}
-		$env = getenv('YII_ENV');
-		switch ($env) {
-			case 'local':
-				$merchantName = '花美灵';
-				break;
-			case 'dev':
-				$merchantName = '花美灵';
-				break;
-			case 'test':
-				$merchantName = '花掌柜';
-				break;
-			case 'production':
-				$merchantName = '花卉宝';
-				break;
-			default:
-				$merchantName = '花卉宝';
-		}
-		echo $merchantName;
-	}
-	
-	//获取商家的h5商城二维码 shish 2020.4.30
-	public static function getH5MallQrCode($id)
-	{
-		return MerchantClass::getH5MallQrCode($id);
-	}
-	
+
+    public static $baseFile = '\biz\merchant\classes\MerchantClass';
+
+    //商家在业务端的权限 shish 2019.11.25
+    public static function getAuthIdList($merchantId, $endId)
+    {
+        $merchant = self::getById($merchantId);
+        $setId = $merchant['setId'];
+        if (empty($setId)) {
+            util::fail('没有找到商家的套餐');
+        }
+
+        //业务端总共有哪些权限
+        $idList = AuthService::getListId($endId);
+
+        //套餐在业务端有哪些权限
+        $setIdList = SetAuthService::getAuthIdList($setId, $endId);
+
+        //有*号表示有所有的权限
+        $commonIdList = in_array('*', $setIdList) ? $idList : array_intersect($idList, $setIdList);
+
+        return $commonIdList;
+
+    }
+
+    //获取默认门店
+    public static function getDefaultShopId($merchant)
+    {
+        return MerchantClass::getDefaultShopId($merchant);
+    }
+
+    //商家基本信息,$sensitive true 除敏感信息 shish 2019.12.8
+    public static function getInfo($merchant, $extend, $sensitive = true)
+    {
+        if ($sensitive) {
+            $delete = ['miniAppId', 'miniAppSecret', 'wxAppId', 'wxAppSecret', 'openAppId', 'wxToken', 'wxJsApiTicket', 'wxAccessToken', 'wxRefreshToken'];
+            foreach ($delete as $del) {
+                unset($merchant[$del]);
+            }
+            $deleteExtend = ['miniAppId', 'miniAccessToken', 'miniRefreshToken', 'wxPayKey', 'wxPayMerchantId', 'wxAppId'];
+            foreach ($deleteExtend as $delExtend) {
+                unset($extend[$delExtend]);
+            }
+        }
+        $merchant['extend'] = $extend;
+        return $merchant;
+    }
+
+    //常用链接 shish 2019.12.19
+    public static function getCommonUrlList()
+    {
+        $list = MerchantClass::$commonUrl;
+        return array_values($list);
+    }
+
+    //取指定常用链接 shish 2019.12.28
+    public static function getCommonUrl($id)
+    {
+        $list = MerchantClass::$commonUrl;
+        return isset($list[$id]) ? $list[$id] : [];
+    }
+
+    //取平台下的商家 shish 2019.12.20
+    public static function getSaasMerchant($where)
+    {
+        $data = MerchantClass::getList('*', $where, 'addTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+
+        //管理员
+        $adminIdList = array_column($list, 'adminId');
+        $admin = AdminService::getAdminByIds($adminIdList, null, 'id');
+        //商家资产
+        $merchantIdList = array_column($list, 'id');
+        $asset = MerchantAssetService::getAssetByMerchantIds($merchantIdList);
+        //套餐
+        $setIdList = array_column($list, 'setId');
+        $set = SetMealService::getSetByIds($setIdList);
+        //拓展
+        $ext = MerchantExtendService::getExtendByMerchantIds($merchantIdList);
+        foreach ($list as $key => $val) {
+            $adminId = $val['adminId'];
+            $merchantId = $val['id'];
+            $setId = $val['setId'];
+            $val['adminName'] = isset($admin[$adminId]['adminName']) ? $admin[$adminId]['adminName'] : '';
+            $val['merchantAsset'] = isset($asset[$merchantId]) ? $asset[$merchantId] : [];
+            $val['setMealName'] = isset($set[$setId]) ? $set[$setId]['name'] : '';
+            $val['extend'] = isset($ext[$merchantId]) ? $ext[$merchantId] : [];
+            $list[$key] = business::formatMerchantLogo($val);
+        }
+        $data['list'] = $list;
+        return $data;
+    }
+
+    //根据id批量取商家 shish 2019.12.20
+    public static function getMerchantByIds($ids)
+    {
+        return MerchantClass::getMerchantByIds($ids);
+    }
+
+    //获取商家 shish 2019.12.30
+    public static function getMerchantById($id)
+    {
+        return MerchantClass::getMerchantById($id);
+    }
+
+    public static function getCurrentSetId($id)
+    {
+        return MerchantClass::getCurrentSetId($id);
+    }
+
+    //开店公众号授权之后初始化 shish 2020.2.7
+    public static function openShopInit($data)
+    {
+        $merchantId = $data['merchantId'];
+        $merchant = MerchantClass::getMerchantById($merchantId);
+        if (empty($merchant)) {
+            return false;
+        }
+        $extend = MerchantExtendClass::getByMerchantId($merchantId);
+        if (isset($extend['init']) && $extend['init'] == 1) {
+            return true;
+        }
+        //事务处理
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+
+            //初始化微信菜单
+            $hasMenu = WxMenuService::getByCondition(['merchantId' => $merchantId]);
+            if (empty($hasMenu)) {
+                xhWxMenuService::applyInit($merchant);
+            }
+
+            //微信客户初始化
+            $hasUser = UserService::getByCondition(['merchantId' => $merchantId]);
+            if (empty($hasUser)) {
+                $return = UserService::syncWxAllUser($merchantId);
+                $totalNum = isset($return['total']) ? $return['total'] : 0;
+                MerchantAssetClass::updateByCondition(['merchantId' => $merchantId], ['totalFans' => $totalNum, 'totalUser' => $totalNum]);
+            }
+
+            //模板消息
+            $hasMessage = TMessageService::getByCondition(['merchantId' => $merchantId]);
+            if (empty($hasMessage)) {
+                xhTMessageService::init($merchant);
+            }
+
+            //完成初始化标识
+            MerchantExtendClass::updateByCondition(['merchantId' => $merchantId], ['init' => 1]);
+
+            //代理资产
+            AgentAssetClass::add(['merchantId' => $merchantId]);
+
+            $transaction->commit();
+            return true;
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            return false;
+        }
+    }
+
+    //初始化平台的商家 shish 2020.2.11
+    public static function initOpenMerchant()
+    {
+        $open = WxOpenClass::getOpen();
+        if (isset($open['wx_base_id']) && !empty($open['wx_base_id']) && isset($open['wx_mini_base_id']) && !empty($open['wx_mini_base_id'])) {
+            util::stop('已初始化,无需重复操作');
+        }
+        $env = getenv('YII_ENV');
+        switch ($env) {
+            case 'local':
+                $merchantName = '花美灵';
+                break;
+            case 'dev':
+                $merchantName = '花美灵';
+                break;
+            case 'test':
+                $merchantName = '花掌柜';
+                break;
+            case 'production':
+                $merchantName = '花卉宝';
+                break;
+            default:
+                $merchantName = '花卉宝';
+        }
+        echo $merchantName;
+    }
+
+    //获取商家的h5商城二维码 shish 2020.4.30
+    public static function getH5MallQrCode($id)
+    {
+        return MerchantClass::getH5MallQrCode($id);
+    }
+
 }

+ 9 - 5
biz/message/classes/InformAdminClass.php

@@ -4,6 +4,7 @@ namespace biz\message\classes;
 
 use biz\admin\classes\AdminClass;
 use biz\admin\services\ShopAdminService;
+use biz\merchant\classes\MerchantClass;
 use biz\user\classes\UserClass;
 use biz\wx\classes\WxOpenClass;
 use common\components\httpUtil;
@@ -191,12 +192,15 @@ class InformAdminClass extends BaseClass
     //订单完成通知店长 shish 2020.3.19
     public static function sendComplete($order)
     {
-        $merchant = WxOpenClass::getWxInfo();
-        $merchantId = 0;
+        $open = WxOpenClass::getWxInfo();
+        $merchantId = $order['merchantId'];
         $orderId = $order['id'];
         $shopId = $order['shopId'];
+        if (empty($shopId)) {
+            $shopId = MerchantClass::getDefaultShopId($merchantId);
+        }
         $adminList = ShopAdminService::getNoticeAdminList($shopId);
-        $tm = xhTMessageService::getList($merchantId);
+        $tm = xhTMessageService::getList(0);
         $shortTempId = 'OPENTM201205968';//订单送达通知
         $tempId = $tm[$shortTempId];
         if (!empty($adminList)) {
@@ -219,12 +223,12 @@ class InformAdminClass extends BaseClass
                         ]
                     ];
                     if (!empty($miniOpenId)) {
-                        $data['miniprogram']['appid'] = $merchant['miniAppId'];
+                        $data['miniprogram']['appid'] = $open['miniAppId'];
                         $data['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
                     }
                     echo '<pre>';
                     print_r($data);
-                    wxUtil::sendTaskInform($data, $merchant);
+                    wxUtil::sendTaskInform($data, $open);
                 }
             }
         }