ProjectService.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\Project;
  4. use app\common\service\Service;
  5. use app\common\util\WhereBuilder;
  6. use Carbon\Carbon;
  7. class ProjectService extends Service
  8. {
  9. public function page($param = [])
  10. {
  11. $this->autoParams($param);
  12. $status = $this->array('status');
  13. $keyword = $this->pg('keyword');
  14. $responsibility_person_id = $this->pg('responsibility_person_id');
  15. $create_time_begin_time = $this->pg('create_time_begin_time');
  16. $create_time_end_time = $this->pg('create_time_end_time');
  17. $update_time_begin_time = $this->pg('update_time_begin_time');
  18. $update_time_end_time = $this->pg('update_time_end_time');
  19. $min_amount = $this->pg('min_amount');
  20. $max_amount = $this->pg('max_amount');
  21. $min_dev_time_days = $this->pg('min_dev_time_days');
  22. $max_dev_time_days = $this->pg('max_dev_time_days');
  23. $min_maintain_time_days = $this->pg('min_maintain_time_days');
  24. $max_maintain_time_days = $this->pg('max_maintain_time_days');
  25. $where = WhereBuilder::builder()
  26. ->like('p.name|p.source', $keyword)
  27. ->in('p.status', $status)
  28. ->eq('p.responsibility_person_id', $responsibility_person_id)
  29. ->between('p.create_time', $create_time_begin_time, $create_time_end_time)
  30. ->between('p.update_time', $update_time_begin_time, $update_time_end_time)
  31. ->between('p.pre_dev_time', $min_dev_time_days, $max_dev_time_days)
  32. ->between('p.pre_maintain_time', $min_maintain_time_days, $max_maintain_time_days)
  33. ->between('p.estimated_amount', $min_amount, $max_amount)
  34. ->build();
  35. return (new Project)->alias('p')
  36. ->with(['schedules'])
  37. ->append(['participants'])
  38. ->field('p.*')
  39. ->field('a.real_name as responsibility_person')
  40. ->join('admin a', 'a.id = p.responsibility_person_id', 'LEFT')
  41. ->where($where)
  42. ->paginate($this->tp6Page());
  43. }
  44. public function create($param = [])
  45. {
  46. $param = $this->autoParams($param);
  47. return Project::create($param);
  48. }
  49. public function info($param = [])
  50. {
  51. $this->autoParams($param);
  52. $project = $this->one(Project::class);
  53. $project->append(['contracts', 'schedules']);
  54. return $project;
  55. }
  56. public function update($param = [])
  57. {
  58. $param = $this->autoParams($param);
  59. return Project::update($param);
  60. }
  61. public function delete($param = [])
  62. {
  63. $this->autoParams($param);
  64. $project = $this->one(Project::class);
  65. return $project->delete();
  66. }
  67. }