MarketCustomer.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace app\model;
  3. use DateTimeInterface;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use support\Model;
  6. use Illuminate\Database\Eloquent\Casts\Attribute;
  7. class MarketCustomer extends Model
  8. {
  9. use SoftDeletes;
  10. protected $table = 'market_customer';
  11. protected $dateFormat = 'U';
  12. public function serializeDate(DateTimeInterface $date)
  13. {
  14. return $date->format('Y-m-d H:i:s');
  15. }
  16. protected function visitTime():Attribute
  17. {
  18. return Attribute::get(function ($value) {
  19. return date('Y-m-d H:i:s', $value);
  20. });
  21. }
  22. public static function config()
  23. {
  24. $config = [
  25. 'requirement' => ['康养公寓', '颐养公寓', '商业', '其他'],
  26. 'require_area' => ['40㎡以下', '40㎡-50㎡', '51㎡-60㎡', '61㎡-80㎡', '81㎡-100㎡', '101㎡-120㎡', '121㎡-150㎡', '150㎡以上'],
  27. 'age_range' => ['20岁以下', '21岁-30岁', '31岁-40岁', '41岁-50岁', '51岁-60岁', '61岁-80岁', '80岁以上'],
  28. 'visit_type' => [
  29. 'common' => ['', '路过', '分销', '朋友介绍', '安居客、房天下', '微信朋友圈', '户外', '微信公众号', '工地围挡', '老带新', '圈层营销', '自拓'],
  30. 'type1' => ['100' => '派单', '101' => '城市展厅', '102' => '活动'],
  31. 'type2' => ['200' => '内渠', '201' => '自渠']
  32. ],
  33. 'focus' => ['位置', '交通', '配套', '价格', '品牌', '适老化', '物业', '医疗', '运营'],
  34. 'region' => ['唐冶', '历城', '历下', '高新', '天桥', '槐荫', '市中', '其他'],
  35. 'purpose' => ['自买自用', '自买他用'],
  36. 'level' => ['A类', 'B类', 'C类', 'D类'],
  37. 'current_status' => ['首次到访', '已到访', '无效客户', '已成交'],
  38. ];
  39. //处理config中的visit_type
  40. $visitType = [];
  41. $visitTypeCommon = $config['visit_type']['common'];
  42. $visitType1 = $config['visit_type']['type1'];
  43. $visitType2 = $config['visit_type']['type2'];
  44. foreach ($visitTypeCommon as $key => $item) {
  45. if (!empty($item)) {
  46. $visitType['type1']["{$key}"] = $item;
  47. $visitType['type2']["{$key}"] = $item;
  48. }
  49. }
  50. $visitType['type1'] += $visitType1;
  51. $visitType['type2'] += $visitType2;
  52. $config['visit_type'] = $visitType;
  53. return $config;
  54. }
  55. /**
  56. * Notes: 处理参数
  57. * User: yb
  58. * Date: 2024/8/6
  59. * Time: 11:43
  60. * @param $data
  61. * @return mixed
  62. */
  63. public static function handleNumParams($data)
  64. {
  65. $setField = ['require_area', 'requirement', 'age_range', 'region'];
  66. foreach ($data as $k => $v) {
  67. if (in_array($k, $setField)) {
  68. if (is_numeric($v)) {
  69. $data[$k] = $v + 1;
  70. } else {
  71. $data[$k] = null;
  72. }
  73. }
  74. }
  75. if ($data['type'] == 1) {
  76. //来电
  77. if (!empty($data['area'])) {
  78. $area = $data['area'];
  79. $requireArea = 1;
  80. if ($area >= 40 && $area < 51) {
  81. $requireArea = 2;
  82. } else if ($area >= 51 && $area < 61) {
  83. $requireArea = 3;
  84. } else if ($area >= 61 && $area < 81) {
  85. $requireArea = 4;
  86. } else if ($area >= 81 && $area < 101) {
  87. $requireArea = 5;
  88. } else if ($area >= 101 && $area < 121) {
  89. $requireArea = 6;
  90. } else if ($area >= 121 && $area < 151) {
  91. $requireArea = 7;
  92. } else if ($area >= 151) {
  93. $requireArea = 8;
  94. }
  95. $data['require_area'] = $requireArea;
  96. $data['age_range'] = null;
  97. } else {
  98. $data['area'] = null;
  99. }
  100. } else {
  101. //来访
  102. $data['area'] = null;
  103. }
  104. if (!empty($data['visit_time'])) {
  105. $data['visit_time'] = strtotime($data['visit_time']);
  106. }
  107. if (empty($data['visit_type'])) {
  108. $data['visit_type'] = null;
  109. }
  110. if (empty($data['level'])) {
  111. $data['level'] = null;
  112. }
  113. if (empty($data['purpose'])) {
  114. $data['purpose'] = null;
  115. }
  116. if (!empty($data['focus'])) {
  117. $data['focus'] = implode(',', $data['focus']);
  118. } else {
  119. $data['focus'] = null;
  120. }
  121. return $data;
  122. }
  123. /**
  124. * Notes: 检验客户是否可录入
  125. * User: yb
  126. * Date: 2024/8/9
  127. * Time: 21:14
  128. * @param $mobile
  129. * @param int $id
  130. * @return bool
  131. */
  132. public static function checkCustomExists($mobile, $id = 0)
  133. {
  134. $where = [
  135. ['mobile', '=', $mobile],
  136. ['check_status', '=', 2],
  137. [function($query) {
  138. $query->whereIn('current_status', [2,3,4]);
  139. }]
  140. // [function($query) {
  141. // $query->orWhere(function ($query){
  142. // $diffNums = (60 * 60 * 24 * 30);
  143. // $currentTime = time();
  144. // $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 2);
  145. // })->orWhereIn('current_status', [2,3,4]);
  146. // }],
  147. ];
  148. if (!empty($id)) {
  149. $where[] = ['id', '<>', $id];
  150. }
  151. return self::where($where)->exists();
  152. }
  153. public function consultant()
  154. {
  155. return $this->belongsTo(Consultant::class, 'consultant_id');
  156. }
  157. public function report()
  158. {
  159. return $this->belongsTo(Consultant::class, 'report_consultant_id');
  160. }
  161. }