CustomService.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace app\admin\service\consultant;
  3. use app\model\Consultant;
  4. use app\model\MarketCustomer;
  5. use app\model\Member;
  6. use support\Db;
  7. use support\exception\BusinessException;
  8. class CustomService
  9. {
  10. /**
  11. * Notes: 处理参数
  12. * User: yb
  13. * Date: 2024/8/6
  14. * Time: 11:43
  15. * @param $data
  16. * @return mixed
  17. */
  18. protected static function handleNumParams($data)
  19. {
  20. $setField = ['require_area', 'requirement', 'age_range', 'focus', 'region'];
  21. foreach ($data as $k => $v) {
  22. if (in_array($k, $setField)) {
  23. if (is_numeric($v)) {
  24. $data[$k] = $v + 1;
  25. } else {
  26. $data[$k] = null;
  27. }
  28. }
  29. }
  30. if ($data['type'] == 1) {
  31. //来电
  32. if (!empty($data['area'])) {
  33. $area = $data['area'];
  34. $requireArea = 1;
  35. if ($area >= 40 && $area < 51) {
  36. $requireArea = 2;
  37. } else if ($area >= 51 && $area < 61) {
  38. $requireArea = 3;
  39. } else if ($area >= 61 && $area < 81) {
  40. $requireArea = 4;
  41. } else if ($area >= 81 && $area < 101) {
  42. $requireArea = 5;
  43. } else if ($area >= 101 && $area < 121) {
  44. $requireArea = 6;
  45. } else if ($area >= 121 && $area < 151) {
  46. $requireArea = 7;
  47. } else if ($area >= 151) {
  48. $requireArea = 8;
  49. }
  50. $data['require_area'] = $requireArea;
  51. $data['age_range'] = null;
  52. } else {
  53. $data['area'] = null;
  54. }
  55. } else {
  56. //来访
  57. $data['area'] = null;
  58. }
  59. if (!empty($data['visit_time'])) {
  60. $data['visit_time'] = strtotime($data['visit_time']);
  61. }
  62. if (empty($data['visit_type'])) {
  63. $data['visit_type'] = null;
  64. }
  65. if (empty($data['level'])) {
  66. $data['level'] = null;
  67. }
  68. if (empty($data['purpose'])) {
  69. $data['purpose'] = null;
  70. }
  71. return $data;
  72. }
  73. /**
  74. * Notes: 返回选项配置信息
  75. * User: yb
  76. * Date: 2024/8/5
  77. * Time: 16:05
  78. * @return array
  79. */
  80. public static function config()
  81. {
  82. $config = [
  83. 'requirement' => ['康养公寓', '颐养公寓', '商业', '其他'],
  84. 'require_area' => ['40㎡以下', '40㎡-50㎡', '51㎡-60㎡', '61㎡-80㎡', '81㎡-100㎡', '101㎡-120㎡', '121㎡-150㎡', '150㎡以上'],
  85. 'age_range' => ['40岁以下', '21岁-30岁', '31岁-40岁', '41岁-50岁', '51岁-60岁', '61岁-80岁', '80岁以上'],
  86. 'visit_type' => [
  87. 'common' => ['', '路过', '分销', '朋友介绍', '安居客、房天下', '微信朋友圈', '户外', '微信公众号', '工地围挡', '老带新', '圈层营销', '自拓'],
  88. 'type1' => ['100' => '派单', '101' => '城市展厅', '102' => '活动'],
  89. 'type2' => ['200' => '内渠', '201' => '自渠']
  90. ],
  91. 'focus' => ['位置', '交通', '配套', '价格', '品牌', '适老化', '物业', '医疗', '运营'],
  92. 'region' => ['唐冶', '历城', '历下', '高新', '天桥', '槐荫', '市中', '其他'],
  93. 'purpose' => ['自买自用', '自买他用'],
  94. 'level' => ['A类', 'B类', 'C类', 'D类'],
  95. 'current_status' => ['首次到访', '已到访', '无效客户', '已成交'],
  96. ];
  97. //处理config中的visit_type
  98. $visitType = [];
  99. $visitTypeCommon = $config['visit_type']['common'];
  100. $visitType1 = $config['visit_type']['type1'];
  101. $visitType2 = $config['visit_type']['type2'];
  102. foreach ($visitTypeCommon as $key => $item) {
  103. if (!empty($item)) {
  104. $visitType['type1']["{$key}"] = $item;
  105. $visitType['type2']["{$key}"] = $item;
  106. }
  107. }
  108. $visitType['type1'] += $visitType1;
  109. $visitType['type2'] += $visitType2;
  110. $config['visit_type'] = $visitType;
  111. return $config;
  112. }
  113. /**
  114. * Notes: 添加客户
  115. * User: yb
  116. * Date: 2024/8/6
  117. * Time: 11:20
  118. */
  119. public static function add($params)
  120. {
  121. $params = self::handleNumParams($params);
  122. $mobile = $params['mobile'];
  123. //查询客户手机号是否已经存在
  124. if (MarketCustomer::where('mobile', $mobile)->exists()) {
  125. return json_fail('客户已经登记过了');
  126. }
  127. //查询顾问信息
  128. $consultantId = $params['consultant_id'];
  129. $consultantInfo = Consultant::firstWhere(['id' => $consultantId]);
  130. if (empty($consultantInfo)) {
  131. return json_fail('顾问信息不存在');
  132. }
  133. $deptId = $consultantInfo->dept_id;
  134. $insertData = [
  135. 'name' => $params['name'],
  136. 'mobile' => $mobile,
  137. 'consultant_id' => $consultantId,
  138. 'dept_id' => $deptId,
  139. 'gender' => $params['gender'] ?? null,
  140. 'visit_type' => $params['visit_type'] ?? null,
  141. 'require_area' => $params['require_area'] ?? null,
  142. 'area' => $params['area'] ?? null,
  143. 'requirement' => $params['requirement'] ?? null,
  144. 'age_range' => $params['age_range'] ?? null,
  145. 'focus' => $params['focus'] ?? null,
  146. 'region' => $params['region'] ?? null,
  147. 'purpose' => $params['purpose'] ?? null,
  148. 'level' => $params['level'] ?? null,
  149. 'type' => $params['type'] ?? null,
  150. 'visit_time' => $params['visit_time'] ?? null,
  151. 'note' => $params['note'] ?? '',
  152. ];
  153. Db::beginTransaction();
  154. try {
  155. //查询会员表中是否存在该客户
  156. // $memberId = Member::where('member_mobile', $insertData['mobile'])->value('member_id');
  157. // if (empty($memberId)) {
  158. // //新增会员信息
  159. // }
  160. // $insertData['member_id'] = $memberId;
  161. $customId = MarketCustomer::insertGetId($insertData);
  162. Db::commit();
  163. }catch (BusinessException|\Exception $e){
  164. Db::rollBack();
  165. return json_fail($e->getMessage());
  166. }
  167. if ($customId) {
  168. return json_success('添加成功');
  169. } else {
  170. return json_fail('添加失败');
  171. }
  172. }
  173. }