TechnologyService.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. $list = Technology::where('del_time',0)->select('*');
  45. $list = $this->limit($list,'',$data);
  46. return [200,$list];
  47. }
  48. public function technologyRule($data){
  49. if($this->isEmpty($data,'title')) return [false,'名称不能为空!'];
  50. if($this->isEmpty($data,'process_id')) return [false,'工序不能为空!'];
  51. return [true,''];
  52. }
  53. }