CustomerVisitLog.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class CustomerVisitLog extends Model
  5. {
  6. /**
  7. * 关联用户
  8. */
  9. public function user()
  10. {
  11. return $this->belongsTo(User::class, 'user_id');
  12. }
  13. /**
  14. * 关联员工
  15. */
  16. public function employee()
  17. {
  18. return $this->belongsTo(Employee::class, 'employee_id');
  19. }
  20. /**
  21. * 图片处理
  22. */
  23. public function getImgAttr($value)
  24. {
  25. if (empty($value)) return [];
  26. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  27. $value = explode(',', $value);
  28. if (!is_array($value))
  29. $value = [$value];
  30. foreach ($value as &$it) {
  31. $it = 'https://' . $ali_oss_bindurl . '/' . $it;
  32. }
  33. return $value;
  34. }
  35. /**
  36. * 图片处理
  37. */
  38. public function getImg1Attr($value)
  39. {
  40. if (empty($value)) return [];
  41. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  42. $value = explode(',', $value);
  43. if (!is_array($value))
  44. $value = [$value];
  45. foreach ($value as &$it) {
  46. $it = 'https://' . $ali_oss_bindurl . '/' . $it;
  47. }
  48. return $value;
  49. }
  50. public function activity()
  51. {
  52. return $this->hasOne(Activity::class, 'id', 'aid');
  53. }
  54. public function activitys()
  55. {
  56. return $this->belongsTo(Activity::class, 'aid', 'id');
  57. }
  58. /** 统一状态 */
  59. public static $states = [
  60. ['n' => 1, 'chaos' => [1, '回访', '待确认', '预约回访', '1'], 'state' => '回访'],
  61. ['n' => 2, 'chaos' => [2, '交定', '定金', '已交定', '收定', '2'], 'state' => '已交定'],
  62. ['n' => 3, 'chaos' => [3, '签单', '已签单', '3'], 'state' => '已签单'],
  63. ['n' => 4, 'chaos' => [4, '预约到店', '4'], 'state' => '预约到店'],
  64. ['n' => 5, 'chaos' => [5, '预约量房', '5'], 'state' => '预约量房'],
  65. ['n' => 6, 'chaos' => [6, '预约活动', '6'], 'state' => '预约活动'],
  66. ['n' => 7, 'chaos' => [7, '已到访', '已到店', '确定到店', '确认到店', '7'], 'state' => '已到店'],
  67. ['n' => 8, 'chaos' => [8, '已量房', '确定量房', '确认量房', '8'], 'state' => '已量房'],
  68. ['n' => 9, 'chaos' => [9, '到场', '已到场', '确定到场', '确认到场', '9'], 'state' => '已到场'],
  69. ['n' => 10, 'chaos' => [10, '未到访', 10], 'state' => '未到访'],
  70. ['n' => 11, 'chaos' => [11, '无效', '11'], 'state' => '无效'],
  71. ['n' => 12, 'chaos' => [12, '未到店', '12'], 'state' => '未到店'],
  72. ['n' => 13, 'chaos' => [13, '未量房', '13'], 'state' => '未量房'],
  73. ['n' => 14, 'chaos' => [14, '未到场', '14'], 'state' => '未到场'],
  74. ['n' => 15, 'chaos' => [15, '已卖卡', '15', '无忧'], 'state' => '无忧']
  75. ];
  76. public function getStateAttr($value)
  77. {
  78. if (is_numeric($value)) $value = intval($value);
  79. foreach (static::$states as $s) {
  80. if ($value === $s['n'] || in_array($value, $s['chaos'], true)) return $s['state'];
  81. }
  82. return '';
  83. }
  84. public function setStateAttr($value)
  85. {
  86. if (is_numeric($value)) $value = intval($value);
  87. foreach (static::$states as $s) {
  88. if ($value === $s['n'] || in_array($value, $s['chaos'], true)) return $s['n'];
  89. }
  90. return 1;
  91. }
  92. /**
  93. * 变更跟踪记录中的查询条件
  94. */
  95. public static function changeState($state, $type = 'state')
  96. {
  97. if (is_array($state) && count($state) == 3) {
  98. if ($state[0] !== 'state') return $state;
  99. if ($state[1] == '=') $state[1] = 'in';
  100. foreach (static::$states as $s) {
  101. if (in_array($state[2], $s['chaos'], true)) $state[2] = $s['chaos'];
  102. }
  103. return $state;
  104. } else {
  105. foreach (static::$states as $s) {
  106. if (in_array($state, $s['chaos'], true)) return $s[$type];
  107. }
  108. return $type == 'chaos' ? [] : '';
  109. }
  110. }
  111. public function customer()
  112. {
  113. return $this->belongsTo(Customer::class);
  114. }
  115. /**
  116. * 交定凭证
  117. */
  118. public function getDeliveryImgAttr($value)
  119. {
  120. if (empty($value)) return [];
  121. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  122. $value = explode(',', $value);
  123. if (!is_array($value))
  124. $value = [$value];
  125. foreach ($value as &$it) {
  126. $it = 'https://' . $ali_oss_bindurl . '/' . $it;
  127. }
  128. return $value;
  129. }
  130. /**
  131. * 签单凭证
  132. */
  133. public function getSignImgAttr($value)
  134. {
  135. if (empty($value)) return [];
  136. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  137. $value = explode(',', $value);
  138. if (!is_array($value))
  139. $value = [$value];
  140. foreach ($value as &$it) {
  141. $it = 'https://' . $ali_oss_bindurl . '/' . $it;
  142. }
  143. return $value;
  144. }
  145. /**
  146. * 记录扩展字段修改的图片处理
  147. */
  148. public function getSavePortraitFieldAttr($value)
  149. {
  150. if (empty($value)) return $value;
  151. $saveall = json_decode($value, true);
  152. foreach ($saveall as $key => $val) {
  153. if ($val['type'] == 6) {
  154. $arr = explode(',', $val['value']);
  155. $domain = config('app.ali_oss_bindurl');
  156. $fields = '';
  157. foreach ($arr as $item) {
  158. $fields .= 'https://' . $domain . '/' . $item . ',';
  159. }
  160. $saveall[$key]['value'] = trim($fields, ',');
  161. $saveall[$key]['valname'] = trim($fields, ',');
  162. }
  163. }
  164. return json_encode($saveall);
  165. }
  166. /**
  167. * 下次回访时间处理
  168. */
  169. public function getNextContactDateAttr($value,$data)
  170. {
  171. $cusdata = Customer::with(['org'])->where('id',$data['customer_id'])->find();
  172. if(empty($cusdata['org'])) return $value;
  173. $orgids = explode('-',rtrim($cusdata['org']['path'],'-'));
  174. $root_id = $orgids[0];
  175. $is_set = Setting::where([['root_id','=',$root_id],['name','=','nextVisitTimeIsOk']])->value('content');
  176. if(!$is_set){
  177. $value = $value ? $value : '暂未设置下次回访时间';
  178. }
  179. return $value;
  180. }
  181. }