CustomerRecycle.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. use toolkits\Aec;
  5. class CustomerRecycle extends Model
  6. {
  7. /**
  8. * 关联员工
  9. */
  10. public function employee()
  11. {
  12. return $this->belongsTo(Employee::class, 'employee_id');
  13. }
  14. /**
  15. * 销售部门关联
  16. */
  17. public function employeeOrg()
  18. {
  19. return $this->hasOneThrough(Org::class, Employee::class, 'id', 'id', 'employee_id', 'org_id');
  20. }
  21. /**
  22. * 关联部门
  23. */
  24. public function org()
  25. {
  26. return $this->belongsTo(Org::class, 'org_id')->bind(['org_name' => 'name']);
  27. }
  28. /**
  29. * 关联公海
  30. */
  31. public function pool()
  32. {
  33. return $this->belongsTo(Pool::class, 'org_id')->bind(['pool_name' => 'name']);
  34. }
  35. /**
  36. * 来源
  37. */
  38. public function source()
  39. {
  40. return $this->belongsTo(CustomerSource::class, 'source_id');
  41. }
  42. /**
  43. * 设计师
  44. */
  45. public function designer()
  46. {
  47. return $this->belongsTo(Employee::class, 'designer_id');
  48. }
  49. /**
  50. * 设计师部门
  51. */
  52. public function designerOrg()
  53. {
  54. return $this->hasOneThrough(Org::class, Employee::class, 'id', 'id', 'employee_id', 'org_id');
  55. }
  56. /**
  57. * 客户产品
  58. */
  59. public function package()
  60. {
  61. return $this->belongsTo(CustomerPackage::class, 'package_id');
  62. }
  63. /**
  64. * 建档机制
  65. * 1,拿到手机号的才能建档
  66. * 2,档案中有该手机号也不能建档
  67. */
  68. public static function onBeforeInsert($customer)
  69. {
  70. // 没有手机号不能建档
  71. if (empty($customer->phone)) return false;
  72. // 手机号已经存在无法建档
  73. $condition = [
  74. 'employee_id' => $customer->employee_id,
  75. 'phone' => $customer->phone
  76. ];
  77. $had = self::where($condition)->find();
  78. if ($had) return false;
  79. return true;
  80. }
  81. /**
  82. * 手机号解密
  83. */
  84. public function getPhoneAttr($value)
  85. {
  86. if (preg_match('/^1[\d]{10}$/', $value)) return $value;
  87. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  88. $value = $aec->decrypt($value);
  89. return $value;
  90. }
  91. /**
  92. * 手机号加密
  93. */
  94. public function setPhoneAttr($value)
  95. {
  96. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  97. $value = $aec->encrypt($value);
  98. return $value;
  99. }
  100. //protected $json = ['ext'];
  101. // private $extAttr = [
  102. // 'ext1' => '年龄',
  103. // 'ext2' => '是否首次装修',
  104. // 'ext3' => '消费能力',
  105. // 'ext4' => '预计装修时间',
  106. // 'ext5' => '爱好',
  107. // 'ext6' => '微信',
  108. // 'ext7' => '客户空闲时间段',
  109. // 'ext8' => '家庭结构',
  110. // 'ext9' => '家庭成员意见',
  111. // 'ext10' => '户型',
  112. // 'ext11' => '决策人',
  113. // 'ext12' => '喜欢色调',
  114. // 'ext13' => '房屋结构',
  115. // 'ext14' => '装修方式',
  116. // 'ext15' => '客户需求',
  117. // 'ext16' => '客户痛点',
  118. // 'ext17' => '重视环保',
  119. // 'ext18' => '重视设计',
  120. // 'ext19' => '关注的工艺',
  121. // 'ext20' => '特别在意的空间设计',
  122. // 'ext21' => '汽车价格',
  123. // 'ext22' => '房屋价格',
  124. // 'ext23' => '买小区的原因',
  125. // 'ext24' => '周边配置',
  126. // 'ext25' => '设计师服务满意度',
  127. // 'ext26' => '方案满意度',
  128. // 'ext27' => '报价满意度',
  129. // 'ext28' => '意向程度',
  130. // 'ext29' => '是否到店',
  131. // 'ext30' => '预计到店时间',
  132. // 'ext31' => '是否交定',
  133. // 'ext32' => '客户其他需求',
  134. // 'ext33' => '当前所在区域',
  135. // 'ext34' => '加微类型',
  136. // 'ext35' => '建群情况',
  137. // 'ext36' => '直播情况',
  138. // 'ext37' => '直播人员',
  139. // 'ext38' => '房屋用途',
  140. // 'ext39' => '房屋位置',
  141. // 'ext40' => '其他房屋信息备注',
  142. // 'ext41' => '谈单时长',
  143. // 'ext42' => '门牌单元号',
  144. // 'ext43' => '1对1业务人员',
  145. // 'ext44' => '1对1设计人员'
  146. // ];
  147. /**
  148. * 客户扩展属性
  149. */
  150. // public function getExtAttr($ext)
  151. // {
  152. // $data = [];
  153. // foreach ($this->extAttr as $k => $v) {
  154. // $data[$v] = isset($ext->$k) ? $ext->$k : '';
  155. // }
  156. // return $data;
  157. // }
  158. // public function setExtAttr($ext)
  159. // {
  160. // $data = [];
  161. // foreach ($this->extAttr as $k => $v) {
  162. // if(isset($ext[$v])) $data[$k] = $ext[$v];
  163. // }
  164. // return $data;
  165. // }
  166. public function getStateAttr($value)
  167. {
  168. $states = Customer::$states;
  169. if (is_numeric($value)) $value = intval($value);
  170. foreach ($states as $s) {
  171. if ($value === $s['n'] || in_array($value, $s['chaos'], true)) return $s['state'];
  172. }
  173. return '';
  174. }
  175. public function setStateAttr($value)
  176. {
  177. $states = Customer::$states;
  178. if (is_numeric($value)) $value = intval($value);
  179. foreach ($states as $s) {
  180. if ($value === $s['n'] || in_array($value, $s['chaos'], true)) return $s['n'];
  181. }
  182. return 0;
  183. }
  184. /**
  185. * 收定金额转换单位
  186. */
  187. public function getDepositMoneyAttr($value)
  188. {
  189. if (empty($value)) return $value;
  190. $length = strlen($value);
  191. if ($length < 5) return $value.'元';
  192. if ($length > 4){
  193. $num = $value/10000;
  194. $value = sprintf("%.2f",substr(sprintf("%.3f", $num), 0, -2)).'万元';
  195. return $value;
  196. }
  197. }
  198. /**
  199. * 签单金额转换单位
  200. */
  201. public function getSignedMoneyAttr($value)
  202. {
  203. if (empty($value)) return $value;
  204. $length = strlen($value);
  205. if ($length < 5) return $value.'元';
  206. if ($length > 4){
  207. $num = $value/10000;
  208. $value = sprintf("%.2f",substr(sprintf("%.3f", $num), 0, -2)).'万元';
  209. return $value;
  210. }
  211. }
  212. }