ProjectService.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_amount');
  22. $max_amount = $this->pg('max_amount');
  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. ->append(['participants'])
  40. ->field('p.*')
  41. ->field('a.real_name as responsibility_person')
  42. ->join('admin a', 'a.id = p.responsibility_person_id', 'LEFT')
  43. ->where($where)
  44. ->paginate($this->tp6Page());
  45. }
  46. public function create($param = [])
  47. {
  48. $param = $this->autoParams($param);
  49. return Project::create($param);
  50. }
  51. public function info($param = [])
  52. {
  53. $this->autoParams($param);
  54. $project = $this->one(Project::class);
  55. $project->append(['contracts', 'schedules']);
  56. return $project;
  57. }
  58. public function update($param = [])
  59. {
  60. $param = $this->autoParams($param);
  61. return Project::update($param);
  62. }
  63. public function delete($param = [])
  64. {
  65. $this->autoParams($param);
  66. $project = $this->one(Project::class);
  67. return $project->delete();
  68. }
  69. }