TechnologyService.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BasicProcess;
  4. use App\Model\Process;
  5. use App\Model\Technology;
  6. /**
  7. * 工艺相关
  8. * @package App\Models
  9. */
  10. class TechnologyService extends Service
  11. {
  12. public function technologyEdit($data){
  13. list($status,$msg) = $this->technologyRule($data);
  14. if(!$status) return [$status,$msg];
  15. if($this->isEmpty($data,'id')) return [false,'ID不存在'];
  16. $first = Technology::where('title',$data['title'])->where('id','<>',$data['id'])->where('del_time',0)->first();
  17. if(!empty($first))return [false,'名称已存在!'];
  18. $model = new Technology();
  19. $model = $model->where('id',$data['id'])->first();
  20. $model->title = $data['title'];
  21. $model->process_id = $data['process_id'];
  22. $model->save();
  23. return [true,'保存成功!'];
  24. }
  25. public function technologyAdd($data,$user){
  26. list($status,$msg) = $this->technologyRule($data);
  27. if(!$status) return [$status,$msg];
  28. $first = Technology::where('title',$data['title'])->where('del_time',0)->first();
  29. if(!empty($first))return [false,'名称已存在!'];
  30. $model = new Technology();
  31. $model->title = $data['title'];
  32. $model->process_id = $data['process_id'];
  33. $model->save();
  34. return [true,'保存成功!'];
  35. }
  36. public function technologyDel($data){
  37. if($this->isEmpty($data,'id')) return [false,'ID必须!'];
  38. Technology::where('id',$data['id'])->update([
  39. 'del_time' => time()
  40. ]);
  41. return [true,'删除成功'];
  42. }
  43. public function technologyList($data){
  44. $model = Technology::where('del_time',0)->select('*');
  45. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  46. $list = $this->limit($model,'',$data);
  47. return [200,$list];
  48. }
  49. public function technologyRule($data){
  50. if($this->isEmpty($data,'title')) return [false,'名称不能为空!'];
  51. if($this->isEmpty($data,'process_id')) return [false,'工序不能为空!'];
  52. return [true,''];
  53. }
  54. public function technologyCopy($data,$user){
  55. list($status,$msg) = $this->technologyCopyRule($data);
  56. if(! $status) return [$status,$msg];
  57. $first = Technology::where('id',$data['id'])->where('del_time',0)->first();
  58. $model = new Technology();
  59. $model->title = $data['title'];
  60. $model->process_id = $first->process_id;
  61. $model->save();
  62. return [true,'保存成功!'];
  63. }
  64. public function technologyCopyRule($data){
  65. if($this->isEmpty($data,'id')) return [false,'复制的工序ID不能为空!'];
  66. if($this->isEmpty($data,'title')) return [false,'名称不能为空!'];
  67. $bool = Technology::where('title',$data['title'])->where('del_time',0)->exists();
  68. if($bool) return [false,'名称已存在!'];
  69. return [true,''];
  70. }
  71. }