FollowUpRecordService.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Service;
  3. use App\Model\Depart;
  4. use App\Model\Employee;
  5. use App\Model\EmployeeRole;
  6. use App\Model\FollowUpRecord;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Hash;
  9. class FollowUpRecordService extends Service
  10. {
  11. public function followUpRecordEdit($data,$user){
  12. list($status,$msg) = $this->followUpRecordRule($data,false);
  13. if(!$status) return [$status,$msg];
  14. $model = new FollowUpRecord();
  15. $model = $model->where('id',$data['id'])->first();
  16. $model->id_card = $data['id_card']??'';
  17. $model->number = $data['number'] ;
  18. $model->mobile = $data['mobile'];
  19. $model->emp_name = $data['emp_name'];
  20. $model->is_admin = $data['is_admin'];
  21. if($model->is_admin == 1){
  22. $model->account = $data['account'];
  23. if($data['password'] !== '********'){
  24. $model->password = Hash::make($data['password']);
  25. }
  26. }
  27. $model->save();
  28. return [true,'保存成功!'];
  29. }
  30. public function followUpRecordAdd($data,$user){
  31. list($status,$msg) = $this->followUpRecordRule($data);
  32. if(!$status) return [$status,$msg];
  33. $model = new FollowUpRecord();
  34. $model->id_card = $data['id_card']??'';
  35. $model->number = $data['number'] ;
  36. $model->mobile = $data['mobile'];
  37. $model->emp_name = $data['emp_name'];
  38. $model->state = 1;
  39. $model->crt_id = $user['id'];
  40. $model->is_admin = $data['is_admin'];
  41. if($model->is_admin == 1){
  42. $model->account = $data['account'];
  43. $model->password = Hash::make($data['password']);
  44. }
  45. $model->save();
  46. return [true,'保存成功!'];
  47. }
  48. public function followUpRecordDel($data,){
  49. if($this->isEmpty($data,'id')) return [false,'ID必须!'];
  50. FollowUpRecord::where('id',$data['id'])->update([
  51. 'del_time'=>time()
  52. ]);
  53. return [true,'删除成功'];
  54. }
  55. public function followUpRecordList($data,$user){
  56. $model = FollowUpRecord::where('del_time',0)
  57. ->select('number','mobile','emp_name','id','entry_time','leave_time','is_technical','is_admin','state')
  58. ->orderBy('id','desc');
  59. if(! empty($data['state'])) $model->where('state',$data['state']);
  60. if(! empty($data['mobile'])) $model->where('mobile', 'LIKE', '%'.$data['mobile'].'%');
  61. if(! isset($data['all_emp'])) $model->where('id','<>',Employee::SPECIAL_ADMIN);
  62. $list = $this->limit($model,'',$data);
  63. //组织数据
  64. $list = $this->organizationData($list);
  65. return [true, $list];
  66. }
  67. public function organizationData($data) {
  68. if (empty($data['data'])) return $data;
  69. foreach ($data['data'] as $key => $value){
  70. }
  71. return $data;
  72. }
  73. public function followUpRecordRule($data,$is_add = true){
  74. if($this->isEmpty($data,'number')) return [false,'工号不存在!'];
  75. if($this->isEmpty($data,'mobile')) return [false,'手机号不存在!'];
  76. if($this->isEmpty($data,'emp_name')) return [false,'姓名不存在!'];
  77. if(! $is_add){
  78. if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
  79. }else{
  80. }
  81. return [true,''];
  82. }
  83. }