ApplyService.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. namespace bizHd\saas\services;
  3. use biz\shop\classes\MainClass;
  4. use biz\sj\classes\SjClass;
  5. use bizHd\ad\classes\AdClass;
  6. use bizHd\admin\classes\AdminClass;
  7. use bizHd\base\services\BaseService;
  8. use bizGhs\custom\classes\CustomClass;
  9. use biz\shop\classes\ShopAdminClass;
  10. use biz\sj\classes\MerchantClass;
  11. use bizHd\goods\classes\CategoryClass;
  12. use bizHd\goods\classes\GoodsSettingClass;
  13. use bizHd\item\services\ItemService;
  14. use bizHd\merchant\services\SjService;
  15. use bizHd\saas\classes\ApplyClass;
  16. use bizHd\saas\classes\ApplyExtendClass;
  17. use biz\sj\services\MerchantService;
  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, 'addTime 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 = \bizHd\shop\classes\MainClass::addMainInitItem();
  73. $respond = SjService::initHdBaseInfo($apply, $main, true);
  74. return $respond;
  75. }
  76. //新增或修改申请开店 ssh 2021.2.27
  77. public static function replaceRetail($data)
  78. {
  79. $mobile = $data['mobile'] ?? 0;
  80. if (empty($mobile)) {
  81. util::fail('请填写手机号');
  82. }
  83. if (stringUtil::isMobile($mobile) == false) {
  84. util::fail('请填写正确手机号');
  85. }
  86. //引荐的员工
  87. $currentShopAdminId = 0;
  88. $ghsShopAdminId = $data['ghsShopAdminId'] ?? 0;
  89. if (!empty($ghsShopAdminId)) {
  90. $currentShopAdminId = $ghsShopAdminId;
  91. } else {
  92. $hdShopAdminId = $data['hdShopAdminId'] ?? 0;
  93. if (!empty($hdShopAdminId)) {
  94. $currentShopAdminId = $hdShopAdminId;
  95. }
  96. }
  97. if (!empty($currentShopAdminId)) {
  98. $shopAdmin = ShopAdminClass::getById($currentShopAdminId);
  99. if (!empty($shopAdmin)) {
  100. $sjId = $shopAdmin['sjId'] ?? 0;
  101. $sj = MerchantClass::getMerchantById($sjId);
  102. $data['introSjId'] = $sjId;
  103. $data['introStyle'] = $sj['style'] ?? SjClass::STYLE_SUPPLIER;
  104. $data['introSjName'] = $sj['name'] ?? '';
  105. $data['introShopId'] = $shopAdmin['shopId'] ?? 0;
  106. }
  107. }
  108. $mobile = $data['mobile'] ?? '';
  109. $data['licenseNo'] = $mobile;
  110. $adminId = $data['adminId'] ?? 0;
  111. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  112. if (!empty($has)) {
  113. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店
  114. util::fail('您已经申请过了');
  115. }
  116. $respond = ApplyClass::addRetail($data);
  117. //已提交开店申请,待审核
  118. \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 2]);
  119. return $respond;
  120. }
  121. //供货商申请开店 ssh 2021.01.28
  122. public static function replaceGhs($data)
  123. {
  124. $mobile = $data['mobile'] ?? 0;
  125. if (empty($mobile)) {
  126. util::fail('请填写手机号');
  127. }
  128. if (stringUtil::isMobile($mobile) == false) {
  129. util::fail('请填写正确手机号');
  130. }
  131. $from = $data['from'] ?? 0;
  132. if (in_array($from, [ApplyClass::FROM_GHS, ApplyClass::FROM_RETAIL]) == false) {
  133. util::fail('请填写来源');
  134. }
  135. //暂时不需要提供证件
  136. $data['hasLicense'] = 2;
  137. $data['licenseNo'] = $mobile;
  138. $adminId = $data['adminId'];
  139. $has = ApplyClass::getByCondition(['adminId' => $adminId, 'style' => ApplyClass::FROM_GHS]);
  140. if (!empty($has)) {
  141. util::fail('您已经申请过');
  142. }
  143. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  144. if (!empty($has)) {
  145. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店
  146. util::fail('手机号已经使用过了');
  147. }
  148. //引荐的员工
  149. $currentShopAdminId = 0;
  150. $ghsShopAdminId = $data['ghsShopAdminId'] ?? 0;
  151. if (!empty($ghsShopAdminId)) {
  152. $currentShopAdminId = $ghsShopAdminId;
  153. } else {
  154. $hdShopAdminId = $data['hdShopAdminId'] ?? 0;
  155. if (!empty($hdShopAdminId)) {
  156. $currentShopAdminId = $hdShopAdminId;
  157. }
  158. }
  159. if (!empty($currentShopAdminId)) {
  160. $shopAdmin = ShopAdminClass::getById($currentShopAdminId);
  161. if (!empty($shopAdmin)) {
  162. $sjId = $shopAdmin['sjId'] ?? 0;
  163. $sj = MerchantClass::getMerchantById($sjId);
  164. $data['introSjId'] = $sjId;
  165. $data['introStyle'] = $sj['style'] ?? SjClass::STYLE_SUPPLIER;
  166. $data['introSjName'] = $sj['name'] ?? '';
  167. $data['introShopId'] = $shopAdmin['shopId'] ?? 0;
  168. }
  169. }
  170. $dist = $data['dist'] ?? '';
  171. $floor = $data['floor'] ?? '';
  172. $address = $data['address'] ?? '';
  173. $data['fullAddress'] = $data['city'] . $dist . $address . $floor;
  174. $respond = ApplyClass::addGhs($data);
  175. //已提交开店申请,待审核
  176. \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 2]);
  177. return $respond;
  178. }
  179. //供货商申请开店 ssh 2021.01.28
  180. public static function replaceKmGhs($data)
  181. {
  182. $mobile = $data['mobile'] ?? 0;
  183. if (empty($mobile)) {
  184. util::fail('请填写手机号');
  185. }
  186. if (stringUtil::isMobile($mobile) == false) {
  187. util::fail('请填写正确手机号');
  188. }
  189. $from = $data['from'] ?? ApplyClass::FROM_GHS;
  190. if (in_array($from, [ApplyClass::FROM_GHS, ApplyClass::FROM_RETAIL]) == false) {
  191. util::fail('请填写来源');
  192. }
  193. $data['licenseNo'] = $mobile;
  194. $adminId = $data['adminId'] ?? 0;
  195. if (!empty($adminId)) {
  196. $has = ApplyClass::getByCondition(['adminId' => $adminId, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  197. if (!empty($has)) {
  198. util::fail('您已经申请过');
  199. }
  200. }
  201. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  202. if (!empty($has)) {
  203. util::fail('手机号已经使用过了');
  204. }
  205. $respond = ApplyClass::addKmGhs($data);
  206. if (!empty($adminId)) {
  207. //已提交开店申请,待审核
  208. \biz\admin\classes\AdminClass::updateById($adminId, ['openShop' => 2]);
  209. }
  210. return $respond;
  211. }
  212. }