MarketCustomer.php 5.9 KB

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