ProjectService.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_begin_time');
  17. $corret_create_end_time = $create_time_end_time ? Carbon::createFromTimeString($create_time_end_time)->endOfDay()->toDateTimeString() : null;
  18. $update_time_begin_time = $this->pg('update_time_begin_time');
  19. $update_time_end_time = $this->pg('update_time_begin_time');
  20. $corret_update_end_time = $update_time_end_time ? Carbon::createFromTimeString($update_time_end_time)->endOfDay()->toDateTimeString() : null;
  21. $min_amount = $this->pg('min_price');
  22. $max_amount = $this->pg('max_price');
  23. $min_dev_time_days = $this->pg('min_dev_time_days');
  24. $max_dev_time_days = $this->pg('max_dev_time_days');
  25. $min_maintain_time_days = $this->pg('min_maintain_time_days');
  26. $max_maintain_time_days = $this->pg('max_maintain_time_days');
  27. $where = WhereBuilder::builder()
  28. ->like('p.name|p.source', $keyword)
  29. ->in('p.status', $status)
  30. ->eq('p.responsibility_person_id', $responsibility_person_id)
  31. ->between('p.create_time', $create_time_begin_time, $corret_create_end_time)
  32. ->between('p.update_time', $update_time_begin_time, $corret_update_end_time)
  33. ->between('p.pre_dev_time', $min_dev_time_days, $max_dev_time_days)
  34. ->between('p.pre_maintain_time', $min_maintain_time_days, $max_maintain_time_days)
  35. ->between('p.estimated_amount', $min_amount, $max_amount)
  36. ->build();
  37. return (new Project)->alias('p')
  38. ->with(['schedules'])
  39. ->field('p.*')
  40. ->field('a.real_name as responsibility_person')
  41. ->join('admin a', 'a.id = p.responsibility_person_id', 'LEFT')
  42. ->where($where)
  43. ->paginate($this->tp6Page());
  44. }
  45. public function create($param = [])
  46. {
  47. $param = $this->autoParams($param);
  48. return Project::create($param);
  49. }
  50. public function info($param = [])
  51. {
  52. $this->autoParams($param);
  53. $project = $this->one(Project::class);
  54. $project->append(['contracts', 'schedules']);
  55. return $project;
  56. }
  57. public function update($param = [])
  58. {
  59. $param = $this->autoParams($param);
  60. return Project::update($param);
  61. }
  62. public function delete($param = [])
  63. {
  64. $this->autoParams($param);
  65. $project = $this->one(Project::class);
  66. return $project->delete();
  67. }
  68. }