MerchantService.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. namespace biz\sj\services;
  3. use biz\sj\classes\SjClass;
  4. use bizGhs\custom\services\CustomService;
  5. use bizHd\agent\classes\AgentAssetClass;
  6. use bizHd\auth\services\AuthService;
  7. use bizHd\saas\classes\ApplyClass;
  8. use bizGhs\custom\classes\CustomClass;
  9. use biz\base\services\BaseService;
  10. use biz\sj\classes\MerchantAssetClass;
  11. use biz\sj\classes\MerchantClass;
  12. use biz\sj\classes\MerchantExtendClass;
  13. use bizHd\message\services\TMessageService;
  14. use bizHd\saas\services\SetAuthService;
  15. use bizHd\user\services\UserService;
  16. use bizHd\wx\services\WxMenuService;
  17. use biz\sj\classes\MerchantInitClass;
  18. use bizJd\shop\classes\ShopClass;
  19. use common\components\business;
  20. use common\components\dict;
  21. use common\components\stringUtil;
  22. use common\components\util;
  23. use common\services\xhTMessageService;
  24. use common\services\xhWxMenuService;
  25. use Yii;
  26. class MerchantService extends BaseService
  27. {
  28. public static $baseFile = '\biz\sj\classes\MerchantClass';
  29. //补充营业执照后变更商家信息 ssh 2021.2.28
  30. public static function certChangeSjInfo($applyData)
  31. {
  32. if ($applyData['style'] != SjClass::STYLE_RETAIL) {
  33. return false;
  34. }
  35. $applyId = $applyData['id'] ?? 0;
  36. $apply = ApplyClass::getById($applyId);
  37. $customId = $apply['customId'] ?? 0;
  38. $custom = CustomClass::getById($customId);
  39. if (empty($custom)) {
  40. util::fail('补充营业执照时没有找到客户');
  41. }
  42. $sjId = $custom['sjId'] ?? 0;
  43. $shopId = $custom['shopId'] ?? 0;
  44. MerchantClass::initHdMore($apply, $sjId, $shopId);
  45. //标识有客户关系的开店状态
  46. CustomClass::updateByCondition(['sjId' => $sjId], ['isOpen' => 1]);
  47. }
  48. //商家在业务端的权限 ssh 2019.11.25
  49. public static function getAuthIdList($sjId, $endId)
  50. {
  51. $merchant = self::getById($sjId);
  52. $setId = $merchant['setId'];
  53. if (empty($setId)) {
  54. util::fail('没有找到商家的套餐');
  55. }
  56. //业务端总共有哪些权限
  57. $idList = AuthService::getListId($endId);
  58. //套餐在业务端有哪些权限
  59. $setIdList = SetAuthService::getAuthIdList($setId, $endId);
  60. //有*号表示有所有的权限
  61. $commonIdList = in_array('*', $setIdList) ? $idList : array_intersect($idList, $setIdList);
  62. return $commonIdList;
  63. }
  64. //获取默认门店
  65. public static function getDefaultShopId($merchant)
  66. {
  67. return MerchantClass::getDefaultShopId($merchant);
  68. }
  69. //商家基本信息 ssh 2019.12.8
  70. public static function getInfo($merchant, $extend)
  71. {
  72. $merchant['extend'] = $extend;
  73. return $merchant;
  74. }
  75. //常用链接 ssh 2019.12.19
  76. public static function getCommonUrlList()
  77. {
  78. $list = MerchantClass::$commonUrl;
  79. return array_values($list);
  80. }
  81. //取指定常用链接 ssh 2019.12.28
  82. public static function getCommonUrl($id)
  83. {
  84. $list = MerchantClass::$commonUrl;
  85. return isset($list[$id]) ? $list[$id] : [];
  86. }
  87. //商家列表 ssh 2019.12.20
  88. public static function getMerchantList($where)
  89. {
  90. $data = MerchantClass::getList(['id', 'name', 'style', 'shopNum', 'deadline'], $where, 'addTime DESC');
  91. $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
  92. if (empty($list)) {
  93. return $data;
  94. }
  95. $styleList = [1 => '花店', 2 => '供货商', 4 => '昆明供货商'];
  96. foreach ($list as $key => $val) {
  97. $val['adminName'] = '';
  98. $val['city'] = '厦门';
  99. $val['credit'] = '良好';
  100. $val['setName'] = '基础版';
  101. $val['status'] = '正常';
  102. $val['currentStyle'] = $styleList[$val['style']] ?? '';
  103. $list[$key] = business::formatMerchantLogo($val);
  104. }
  105. $data['list'] = $list;
  106. return $data;
  107. }
  108. //根据id批量取商家 ssh 2019.12.20
  109. public static function getMerchantByIds($ids)
  110. {
  111. return MerchantClass::getMerchantByIds($ids);
  112. }
  113. //获取商家 ssh 2019.12.30
  114. public static function getMerchantById($id)
  115. {
  116. return MerchantClass::getMerchantById($id);
  117. }
  118. public static function getCurrentSetId($id)
  119. {
  120. return MerchantClass::getCurrentSetId($id);
  121. }
  122. //开店公众号授权之后初始化 ssh 2020.2.7
  123. public static function openShopInit($data)
  124. {
  125. $sjId = $data['sjId'];
  126. $merchant = MerchantClass::getMerchantById($sjId);
  127. if (empty($merchant)) {
  128. return false;
  129. }
  130. $extend = MerchantExtendClass::getBySjId($sjId);
  131. if (isset($extend['init']) && $extend['init'] == 1) {
  132. return true;
  133. }
  134. //事务处理
  135. $connection = Yii::$app->db;
  136. $transaction = $connection->beginTransaction();
  137. try {
  138. //初始化微信菜单
  139. $hasMenu = WxMenuService::getByCondition(['sjId' => $sjId]);
  140. if (empty($hasMenu)) {
  141. xhWxMenuService::applyInit($merchant);
  142. }
  143. //微信客户初始化
  144. $hasUser = UserService::getByCondition(['sjId' => $sjId]);
  145. if (empty($hasUser)) {
  146. $return = UserService::syncWxAllUser($sjId);
  147. $totalNum = isset($return['total']) ? $return['total'] : 0;
  148. MerchantAssetClass::updateByCondition(['sjId' => $sjId], ['totalFans' => $totalNum, 'totalUser' => $totalNum]);
  149. }
  150. //模板消息
  151. $hasMessage = TMessageService::getByCondition(['sjId' => $sjId]);
  152. if (empty($hasMessage)) {
  153. xhTMessageService::init($merchant);
  154. }
  155. //完成初始化标识
  156. MerchantExtendClass::updateByCondition(['sjId' => $sjId], ['init' => 1]);
  157. //代理资产
  158. AgentAssetClass::add(['sjId' => $sjId]);
  159. $transaction->commit();
  160. return true;
  161. } catch (Exception $e) {
  162. $transaction->rollBack();
  163. return false;
  164. }
  165. }
  166. //获取商家的h5商城二维码 ssh 2020.4.30
  167. public static function getH5MallQrCode($id)
  168. {
  169. return MerchantClass::getH5MallQrCode($id);
  170. }
  171. }