FollowUpRecordService.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Service;
  3. use App\Model\Employee;
  4. use App\Model\FollowUpRecord;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Hash;
  7. class FollowUpRecordService extends Service
  8. {
  9. public function followUpRecordEdit($data,$user){
  10. list($status,$msg) = $this->followUpRecordRule($data,false);
  11. if(!$status) return [$status,$msg];
  12. $model = new FollowUpRecord();
  13. $model = $model->where('id',$data['id'])->first();
  14. $model->customer_id = $data['customer_id'];
  15. $model->basic_type_id = $data['basic_type_id'] ;
  16. $model->visit_time = $data['visit_time'];
  17. $model->content = $data['content'];
  18. $model->is_remind = $data['is_remind'];
  19. $model->save();
  20. return [true,''];
  21. }
  22. public function followUpRecordAdd($data,$user){
  23. list($status,$msg) = $this->followUpRecordRule($data);
  24. if(!$status) return [$status,$msg];
  25. $model = new FollowUpRecord();
  26. $model->customer_id = $data['customer_id'];
  27. $model->basic_type_id = $data['basic_type_id'] ;
  28. $model->visit_time = $data['visit_time'];
  29. $model->content = $data['content'];
  30. $model->is_remind = $data['is_remind'];
  31. $model->crt_id = $user['id'];
  32. $model->save();
  33. return [true,''];
  34. }
  35. public function followUpRecordDel($data){
  36. if($this->isEmpty($data,'id')) return [false,'ID必须!'];
  37. FollowUpRecord::where('id',$data['id'])->update([
  38. 'del_time'=>time()
  39. ]);
  40. return [true,'删除成功'];
  41. }
  42. public function followUpRecordList($data,$user){
  43. $model = FollowUpRecord::where('del_time',0)
  44. ->select('customer_id','basic_type_id','visit_time','id','content','is_remind','crt_time','crt_id')
  45. ->orderBy('id','desc');
  46. if(! empty($data['customer_id'])) $model->where('customer_id',$data['customer_id']);
  47. if(! empty($data['basic_type_id'])) $model->where('basic_type_id', $data['basic_type_id']);
  48. if(! empty($data['crt_id'])) $model->where('crt_id',$data['crt_id']);
  49. $list = $this->limit($model,'',$data);
  50. //组织数据
  51. $list = $this->organizationData($list);
  52. return [true, $list];
  53. }
  54. public function organizationData($data) {
  55. if (empty($data['data'])) return $data;
  56. foreach ($data['data'] as $key => $value){
  57. }
  58. return $data;
  59. }
  60. public function followUpRecordRule(&$data,$is_add = true){
  61. if($this->isEmpty($data,'customer_id')) return [false,'客户不能为空'];
  62. if($this->isEmpty($data,'basic_type_id')) return [false,'跟进方式不能为空'];
  63. if($this->isEmpty($data,'visit_time')) return [false,'拜访时间不能为空'];
  64. if($this->isEmpty($data,'content')) return [false,'跟进内容不能为空'];
  65. if(! $is_add){
  66. if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
  67. }
  68. $data['visit_time'] = $this->changeDateToDate($data['visit_time']);
  69. return [true,''];
  70. }
  71. }