| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <?php
- namespace bizMall\merchant\services;
- use bizMall\admin\classes\AdminRoleClass;
- use bizMall\agent\classes\AgentAssetClass;
- use bizMall\auth\services\AuthService;
- use bizMall\base\services\BaseService;
- use bizMall\merchant\classes\AdminClass;
- use bizMall\merchant\classes\MerchantAssetClass;
- use bizMall\merchant\classes\MerchantClass;
- use bizMall\merchant\classes\MerchantExtendClass;
- use bizMall\merchant\classes\ShopClass;
- use bizMall\message\services\TMessageService;
- use bizMall\saas\services\SetAuthService;
- use bizMall\saas\services\SetMealService;
- use bizMall\user\services\UserService;
- use bizMall\wx\classes\WxOpenClass;
- use bizMall\wx\services\WxMenuService;
- use common\components\business;
- use common\components\util;
- use common\services\xhTMessageService;
- use common\services\xhWxMenuService;
- use Yii;
- class MerchantService extends BaseService
- {
- public static $baseFile = '\bizMall\merchant\classes\MerchantClass';
- //商家在业务端的权限 ssh 2019.11.25
- public static function getAuthIdList($sjId, $endId)
- {
- $merchant = self::getById($sjId);
- $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);
- }
- //商家基本信息 ssh 2019.12.8
- public static function getInfo($merchant, $extend)
- {
- $merchant['extend'] = $extend;
- return $merchant;
- }
- //常用链接 ssh 2019.12.19
- public static function getCommonUrlList()
- {
- $list = MerchantClass::$commonUrl;
- return array_values($list);
- }
- //取指定常用链接 ssh 2019.12.28
- public static function getCommonUrl($id)
- {
- $list = MerchantClass::$commonUrl;
- return isset($list[$id]) ? $list[$id] : [];
- }
- //取平台下的商家 ssh 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');
- //商家资产
- $sjIdList = array_column($list, 'id');
- $asset = MerchantAssetService::getAssetBySjIds($sjIdList);
- //套餐
- $setIdList = array_column($list, 'setId');
- $set = SetMealService::getSetByIds($setIdList);
- //拓展
- $ext = MerchantExtendService::getExtendByMerchantIds($sjIdList);
- foreach ($list as $key => $val) {
- $adminId = $val['adminId'];
- $sjId = $val['id'];
- $setId = $val['setId'];
- $val['adminName'] = isset($admin[$adminId]['name']) ? $admin[$adminId]['name'] : '';
- $val['merchantAsset'] = isset($asset[$sjId]) ? $asset[$sjId] : [];
- $val['setMealName'] = isset($set[$setId]) ? $set[$setId]['name'] : '';
- $val['extend'] = isset($ext[$sjId]) ? $ext[$sjId] : [];
- $list[$key] = business::formatMerchantLogo($val);
- }
- $data['list'] = $list;
- return $data;
- }
- //根据id批量取商家 ssh 2019.12.20
- public static function getMerchantByIds($ids)
- {
- return MerchantClass::getMerchantByIds($ids);
- }
- //获取商家 ssh 2019.12.30
- public static function getMerchantById($id)
- {
- return MerchantClass::getMerchantById($id);
- }
- public static function getCurrentSetId($id)
- {
- return MerchantClass::getCurrentSetId($id);
- }
- //开店公众号授权之后初始化 ssh 2020.2.7
- public static function openShopInit($data)
- {
- $sjId = $data['sjId'];
- $merchant = MerchantClass::getMerchantById($sjId);
- if (empty($merchant)) {
- return false;
- }
- $extend = MerchantExtendClass::getBySjId($sjId);
- if (isset($extend['init']) && $extend['init'] == 1) {
- return true;
- }
- //事务处理
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- //初始化微信菜单
- $hasMenu = WxMenuService::getByCondition(['sjId' => $sjId]);
- if (empty($hasMenu)) {
- xhWxMenuService::applyInit($merchant);
- }
- //微信客户初始化
- $hasUser = UserService::getByCondition(['sjId' => $sjId]);
- if (empty($hasUser)) {
- $return = UserService::syncWxAllUser($sjId);
- $totalNum = isset($return['total']) ? $return['total'] : 0;
- MerchantAssetClass::updateByCondition(['sjId' => $sjId], ['totalFans' => $totalNum, 'totalUser' => $totalNum]);
- }
- //模板消息
- $hasMessage = TMessageService::getByCondition(['sjId' => $sjId]);
- if (empty($hasMessage)) {
- xhTMessageService::init($merchant);
- }
- //完成初始化标识
- MerchantExtendClass::updateByCondition(['sjId' => $sjId], ['init' => 1]);
- //代理资产
- AgentAssetClass::add(['sjId' => $sjId]);
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- return false;
- }
- }
- //初始化平台的商家 ssh 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':
- $name = '花美灵';
- break;
- case 'dev':
- $name = '花美灵';
- break;
- case 'test':
- $name = '花掌柜';
- break;
- case 'production':
- $name = '花卉宝';
- break;
- default:
- $name = '花卉宝';
- }
- echo $name;
- }
- //获取商家的h5商城二维码 ssh 2020.4.30
- public static function getH5MallQrCode($id)
- {
- return MerchantClass::getH5MallQrCode($id);
- }
- }
|