|
|
@@ -25,196 +25,202 @@ 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;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|