ApplyService.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. namespace bizHd\saas\services;
  3. use biz\sj\classes\SjClass;
  4. use bizHd\ad\classes\AdClass;
  5. use bizHd\admin\classes\AdminClass;
  6. use bizHd\base\services\BaseService;
  7. use bizGhs\custom\classes\CustomClass;
  8. use biz\shop\classes\ShopAdminClass;
  9. use biz\sj\classes\MerchantClass;
  10. use bizHd\goods\classes\CategoryClass;
  11. use bizHd\goods\classes\GoodsSettingClass;
  12. use bizHd\item\services\ItemService;
  13. use bizHd\merchant\services\SjService;
  14. use bizHd\saas\classes\ApplyClass;
  15. use bizHd\saas\classes\ApplyExtendClass;
  16. use biz\sj\services\MerchantService;
  17. use bizHd\shop\classes\MainClass;
  18. use common\components\dict;
  19. use common\components\imgUtil;
  20. use common\components\noticeUtil;
  21. use common\components\stringUtil;
  22. use common\components\util;
  23. class ApplyService extends BaseService
  24. {
  25. public static $baseFile = '\bizHd\saas\classes\ApplyClass';
  26. //申请列表 ssh 2021.1.28
  27. public static function getApplyList($where)
  28. {
  29. $data = ApplyClass::getList('*', $where, 'updateTime DESC');
  30. $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
  31. if (empty($list)) {
  32. return $data;
  33. }
  34. //商家信息
  35. $oldList = array_column($list, 'introSjId');
  36. $sjIdList = array_column($list, 'sjId');
  37. $ids = array_merge($sjIdList, $oldList);
  38. $ids = array_unique(array_filter($ids));
  39. $sj = MerchantClass::getMerchantByIds($ids);
  40. $applyIds = array_unique(array_filter(array_column($list, 'id')));
  41. $extend = ApplyExtendClass::getExtendByIds($applyIds);
  42. $prefix = imgUtil::getPrefix();
  43. foreach ($list as $key => $val) {
  44. $currentId = $val['id'] ?? 0;
  45. $list[$key]['licenseNo'] = $extend[$currentId]['licenseNo'] ?? '';
  46. $list[$key]['license'] = $extend[$currentId]['license'] ?? '';
  47. $introSjId = $val['introSjId'];
  48. $introSjName = $sj[$introSjId]['name'] ?? '';
  49. $list[$key]['introSjName'] = $introSjName;
  50. $avatar = $prefix . 'hhb_small.png';
  51. if (isset($val['avatar']) && !empty($val['avatar'])) {
  52. $avatar = $prefix . $val['avatar'];
  53. }
  54. $list[$key]['fullAvatar'] = $avatar;
  55. }
  56. $data['list'] = $list;
  57. $data['invitedNum'] = 0;
  58. $data['payNum'] = 0;
  59. $data['income'] = 0;
  60. return $data;
  61. }
  62. //审核通过,商家初始化 ssh 2021.2.23
  63. public static function pass($id, $remark = '')
  64. {
  65. $apply = ApplyClass::getById($id);
  66. if (empty($apply)) {
  67. util::fail('没有找到申请记录');
  68. }
  69. $applyId = $apply['id'];
  70. ApplyClass::updateById($applyId, ['status' => ApplyClass::STATUS_PASS, 'remark' => $remark]);
  71. $apply['name'] = isset($apply['name']) ? $apply['name'] : '';
  72. $main = MainClass::addMain();
  73. MainClass::addMainInitItem($main);
  74. $respond = SjService::initHdBaseInfo($apply, $main, true);
  75. return $respond;
  76. }
  77. //新增或修改申请开店 ssh 2021.2.27
  78. public static function replaceRetail($data)
  79. {
  80. $mobile = $data['mobile'] ?? 0;
  81. if (empty($mobile)) {
  82. util::fail('请填写手机号');
  83. }
  84. if (stringUtil::isMobile($mobile) == false) {
  85. util::fail('请填写正确手机号');
  86. }
  87. //引荐的员工
  88. $currentShopAdminId = 0;
  89. $ghsShopAdminId = $data['ghsShopAdminId'] ?? 0;
  90. if (!empty($ghsShopAdminId)) {
  91. $currentShopAdminId = $ghsShopAdminId;
  92. } else {
  93. $hdShopAdminId = $data['hdShopAdminId'] ?? 0;
  94. if (!empty($hdShopAdminId)) {
  95. $currentShopAdminId = $hdShopAdminId;
  96. }
  97. }
  98. if (!empty($currentShopAdminId)) {
  99. $shopAdmin = ShopAdminClass::getById($currentShopAdminId);
  100. if (!empty($shopAdmin)) {
  101. $sjId = $shopAdmin['sjId'] ?? 0;
  102. $sj = MerchantClass::getMerchantById($sjId);
  103. $data['introSjId'] = $sjId;
  104. $data['introStyle'] = $sj['style'] ?? SjClass::STYLE_SUPPLIER;
  105. $data['introSjName'] = $sj['name'] ?? '';
  106. $data['introShopId'] = $shopAdmin['shopId'] ?? 0;
  107. }
  108. }
  109. $mobile = $data['mobile'] ?? '';
  110. $data['licenseNo'] = $mobile;
  111. $adminId = $data['adminId'] ?? 0;
  112. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  113. if (!empty($has)) {
  114. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店
  115. util::fail('您已经申请过了');
  116. }
  117. $respond = ApplyClass::addRetail($data);
  118. //已提交开店申请,待审核
  119. \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 2]);
  120. return $respond;
  121. }
  122. //供货商申请开店 ssh 2021.01.28
  123. public static function replaceGhs($data)
  124. {
  125. $mobile = $data['mobile'] ?? 0;
  126. if (empty($mobile)) {
  127. util::fail('请填写手机号');
  128. }
  129. if (stringUtil::isMobile($mobile) == false) {
  130. util::fail('请填写正确手机号');
  131. }
  132. $from = $data['from'] ?? 0;
  133. if (in_array($from, [ApplyClass::FROM_GHS, ApplyClass::FROM_RETAIL]) == false) {
  134. util::fail('请填写来源');
  135. }
  136. //暂时不需要提供证件
  137. $data['hasLicense'] = 2;
  138. $data['licenseNo'] = $mobile;
  139. $adminId = $data['adminId'];
  140. $has = ApplyClass::getByCondition(['adminId' => $adminId, 'style' => ApplyClass::FROM_GHS]);
  141. if (!empty($has)) {
  142. util::fail('您已经申请过');
  143. }
  144. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  145. if (!empty($has)) {
  146. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店
  147. util::fail('手机号已经使用过了');
  148. }
  149. //引荐的员工
  150. $currentShopAdminId = 0;
  151. $ghsShopAdminId = $data['ghsShopAdminId'] ?? 0;
  152. if (!empty($ghsShopAdminId)) {
  153. $currentShopAdminId = $ghsShopAdminId;
  154. } else {
  155. $hdShopAdminId = $data['hdShopAdminId'] ?? 0;
  156. if (!empty($hdShopAdminId)) {
  157. $currentShopAdminId = $hdShopAdminId;
  158. }
  159. }
  160. if (!empty($currentShopAdminId)) {
  161. $shopAdmin = ShopAdminClass::getById($currentShopAdminId);
  162. if (!empty($shopAdmin)) {
  163. $sjId = $shopAdmin['sjId'] ?? 0;
  164. $sj = MerchantClass::getMerchantById($sjId);
  165. $data['introSjId'] = $sjId;
  166. $data['introStyle'] = $sj['style'] ?? SjClass::STYLE_SUPPLIER;
  167. $data['introSjName'] = $sj['name'] ?? '';
  168. $data['introShopId'] = $shopAdmin['shopId'] ?? 0;
  169. }
  170. }
  171. $dist = $data['dist'] ?? '';
  172. $floor = $data['floor'] ?? '';
  173. $address = $data['address'] ?? '';
  174. $data['fullAddress'] = $data['city'] . $dist . $address . $floor;
  175. $respond = ApplyClass::addGhs($data);
  176. //已提交开店申请,待审核
  177. \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 2]);
  178. return $respond;
  179. }
  180. //供货商申请开店 ssh 2021.01.28
  181. public static function replaceKmGhs($data)
  182. {
  183. $mobile = $data['mobile'] ?? 0;
  184. if (empty($mobile)) {
  185. util::fail('请填写手机号');
  186. }
  187. if (stringUtil::isMobile($mobile) == false) {
  188. util::fail('请填写正确手机号');
  189. }
  190. $from = $data['from'] ?? ApplyClass::FROM_GHS;
  191. if (in_array($from, [ApplyClass::FROM_GHS, ApplyClass::FROM_RETAIL]) == false) {
  192. util::fail('请填写来源');
  193. }
  194. $data['licenseNo'] = $mobile;
  195. $adminId = $data['adminId'] ?? 0;
  196. if (!empty($adminId)) {
  197. $has = ApplyClass::getByCondition(['adminId' => $adminId, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  198. if (!empty($has)) {
  199. util::fail('您已经申请过');
  200. }
  201. }
  202. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  203. if (!empty($has)) {
  204. util::fail('手机号已经使用过了');
  205. }
  206. $respond = ApplyClass::addKmGhs($data);
  207. if (!empty($adminId)) {
  208. //已提交开店申请,待审核
  209. \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 2]);
  210. }
  211. return $respond;
  212. }
  213. }