|
|
@@ -2,135 +2,201 @@
|
|
|
|
|
|
namespace biz\merchant\services;
|
|
|
|
|
|
+use biz\admin\classes\AdminRoleClass;
|
|
|
use biz\auth\services\AuthService;
|
|
|
use biz\base\services\BaseService;
|
|
|
+use biz\merchant\classes\AdminClass;
|
|
|
+use biz\merchant\classes\MerchantAssetClass;
|
|
|
use biz\merchant\classes\MerchantClass;
|
|
|
+use biz\merchant\classes\ShopClass;
|
|
|
use biz\saas\services\SetAuthService;
|
|
|
use biz\saas\services\SetMealService;
|
|
|
+use biz\user\services\UserService;
|
|
|
use common\components\business;
|
|
|
use common\components\util;
|
|
|
+use common\services\xhWxMenuService;
|
|
|
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;
|
|
|
- }
|
|
|
-
|
|
|
- //商家基本信息,去除敏感信息 shish 2019.12.8
|
|
|
- public static function getInfo($merchant, $extend)
|
|
|
- {
|
|
|
- $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]);
|
|
|
- }
|
|
|
-
|
|
|
- //设置计算方式
|
|
|
- $freight = $extend['freight'];
|
|
|
- $freightList = explode('_', $freight);
|
|
|
- $extend['freightFirst'] = isset($freightList[0]) && is_numeric($freightList[0]) ? $freightList[0] : 5;
|
|
|
- $extend['freightAdd'] = isset($freightList[1]) && is_numeric($freightList[1]) ? $freightList[1] : 2;
|
|
|
- $merchant['extend'] = $extend;
|
|
|
- $merchant['logoUrl'] = 'http://a.huahb.com/images/avatar.jpg';
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ //商家基本信息,去除敏感信息 shish 2019.12.8
|
|
|
+ public static function getInfo($merchant, $extend)
|
|
|
+ {
|
|
|
+ $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]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //设置计算方式
|
|
|
+ $freight = $extend['freight'];
|
|
|
+ $freightList = explode('_', $freight);
|
|
|
+ $extend['freightFirst'] = isset($freightList[0]) && is_numeric($freightList[0]) ? $freightList[0] : 5;
|
|
|
+ $extend['freightAdd'] = isset($freightList[1]) && is_numeric($freightList[1]) ? $freightList[1] : 2;
|
|
|
+ $merchant['extend'] = $extend;
|
|
|
+ $merchant['logoUrl'] = 'http://a.huahb.com/images/avatar.jpg';
|
|
|
+ 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 authInit($data)
|
|
|
+ {
|
|
|
+ $merchantId = $data['merchantId'];
|
|
|
+ $platform = $data['platform'];
|
|
|
+ $merchant = MerchantClass::getMerchantById($merchantId);
|
|
|
+ if (empty($merchant)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ $time = time();
|
|
|
+ $date = date("Y-m-d H:i:s");
|
|
|
+ $connection = Yii::$app->db;//事务处理
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ //平台使用的公众号
|
|
|
+ if ($platform == 1) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ xhWxMenuService::applyInit($merchant);
|
|
|
+
|
|
|
+ //商品、分类、首页幻灯片、门店图片
|
|
|
+
|
|
|
+ //创建管理员
|
|
|
+
|
|
|
+ //初始化微信菜单
|
|
|
+ xhWxMenuService::applyInit($merchant);
|
|
|
+ //微信客户初始化
|
|
|
+ $return = UserService::syncWxAllUser($merchantId);
|
|
|
+ $totalNum = isset($return['total']) ? $return['total'] : 0;
|
|
|
+ MerchantAssetClass::updateByCondition(['merchantId' => $merchantId, ['totalFans' => $totalNum, 'totalUser' => $totalNum]]);
|
|
|
+
|
|
|
+ //创建门店
|
|
|
+ $shopData = ['shopName' => $merchant['merchantName'], 'merchantName' => $merchant['merchantName'], 'merchantId' => $merchantId, 'addTime' => $time, 'createTime' => $date, 'updateTime' => $date];
|
|
|
+ $shopReturn = ShopClass::addShop($shopData);
|
|
|
+ $shopId = $shopReturn['id'];
|
|
|
+
|
|
|
+ //创建管理员角色
|
|
|
+ AdminRoleClass::addAdminRole(['roleName' => '店员', 'merchantId' => $merchantId, 'auth' => '*']);
|
|
|
+ $roleReturn = AdminRoleClass::addAdminRole(['roleName' => '店长', 'merchantId' => $merchantId, 'auth' => '*']);
|
|
|
+ $roleId = $roleReturn['id'];
|
|
|
+
|
|
|
+ //创建管理员
|
|
|
+ $adminData = [
|
|
|
+ 'mobile' => 15280215347,
|
|
|
+ 'adminName' => '石少华',
|
|
|
+ 'password' => password_hash('123456', PASSWORD_BCRYPT),
|
|
|
+ 'confirmPassword' => password_hash('123456', PASSWORD_BCRYPT),
|
|
|
+ 'merchantId' => $merchantId,
|
|
|
+ 'roleId' => $roleId,
|
|
|
+ 'defaultShopId' => $shopId,
|
|
|
+ 'currentShopId' => $shopId,
|
|
|
+ 'super' => 1,
|
|
|
+ 'addTime' => $time,
|
|
|
+ ];
|
|
|
+ AdminClass::addAdmin($adminData);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|