ApplyService.php 8.7 KB

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