| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php
- namespace biz\sj\services;
- use biz\sj\classes\SjClass;
- use bizGhs\custom\services\CustomService;
- use bizHd\agent\classes\AgentAssetClass;
- use bizHd\auth\services\AuthService;
- use bizHd\saas\classes\ApplyClass;
- use bizGhs\custom\classes\CustomClass;
- use biz\base\services\BaseService;
- use biz\sj\classes\MerchantAssetClass;
- use biz\sj\classes\MerchantClass;
- use biz\sj\classes\MerchantExtendClass;
- use bizHd\message\services\TMessageService;
- use bizHd\saas\services\SetAuthService;
- use bizHd\user\services\UserService;
- use bizHd\wx\services\WxMenuService;
- use biz\sj\classes\MerchantInitClass;
- use bizJd\shop\classes\ShopClass;
- use common\components\business;
- use common\components\dict;
- use common\components\stringUtil;
- use common\components\util;
- use common\services\xhTMessageService;
- use common\services\xhWxMenuService;
- use Yii;
- class MerchantService extends BaseService
- {
- public static $baseFile = '\biz\sj\classes\MerchantClass';
- //补充营业执照后变更商家信息 ssh 2021.2.28
- public static function certChangeSjInfo($applyData)
- {
- if ($applyData['style'] != SjClass::STYLE_RETAIL) {
- return false;
- }
- $applyId = $applyData['id'] ?? 0;
- $apply = ApplyClass::getById($applyId);
- $customId = $apply['customId'] ?? 0;
- $custom = CustomClass::getById($customId);
- if (empty($custom)) {
- util::fail('补充营业执照时没有找到客户');
- }
- $sjId = $custom['sjId'] ?? 0;
- $shopId = $custom['shopId'] ?? 0;
- MerchantClass::initHdMore($apply, $sjId, $shopId);
- //标识有客户关系的开店状态
- CustomClass::updateByCondition(['sjId' => $sjId], ['isOpen' => 1]);
- }
- //商家在业务端的权限 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 getMerchantList($where)
- {
- $data = MerchantClass::getList(['id', 'name', 'style', 'shopNum', 'deadline'], $where, 'addTime DESC');
- $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
- if (empty($list)) {
- return $data;
- }
- $styleList = [1 => '花店', 2 => '供货商', 4 => '昆明供货商'];
- foreach ($list as $key => $val) {
- $val['adminName'] = '';
- $val['city'] = '厦门';
- $val['credit'] = '良好';
- $val['setName'] = '基础版';
- $val['status'] = '正常';
- $val['currentStyle'] = $styleList[$val['style']] ?? '';
- $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;
- }
- }
- //获取商家的h5商城二维码 ssh 2020.4.30
- public static function getH5MallQrCode($id)
- {
- return MerchantClass::getH5MallQrCode($id);
- }
- }
|