CutterTaskService.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\extra\service\cutter;
  3. use app\extra\basic\Service;
  4. use app\extra\dao\cutter\CutterTaskDao;
  5. use DI\Attribute\Inject;
  6. class CutterTaskService extends Service
  7. {
  8. /**
  9. * 设置模型
  10. * @return string
  11. */
  12. public function __construct()
  13. {
  14. $this->dao = new CutterTaskDao();
  15. }
  16. #[Inject]
  17. protected CutterOrderService $orderService;
  18. /**
  19. * 列表
  20. * @param array $param
  21. */
  22. public function getList(array $param = [],string $field = '*', int $page = 0,int $limit = 0,string $order = 'id desc')
  23. {
  24. if(isset($param['order_key']) && $param['order_key']){
  25. $order = ($param['order_key'] == 'time'?'created_at':$param['order_key']).' '.$param['order_sort']??'desc';
  26. }
  27. if(isset($param['id']) && $param['id']){
  28. $order = "id={$param['id']} desc,".$order;
  29. }
  30. $list = $this->dao->getList(function($query)use($param){
  31. $query->where($this->searchFilter($param))->when(isset($param['uid']) && $param['uid'],function ($query)use($param){
  32. $query->whereNotIn('id',function($query)use($param){
  33. $query->name('cutter_order')->where('uid',$param['uid'])->where('status','>=',0)->field('task_id');
  34. });
  35. });
  36. },$field,$page,$limit,$order);
  37. $count = $this->dao->count($this->searchFilter($param));
  38. return compact('list','count');
  39. }
  40. protected function searchFilter(array $param = []): array
  41. {
  42. $filter = [];
  43. !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
  44. !empty($param['grade']) && $filter[] = ["grade", '<=', $param['grade']];
  45. isset($param['is_del']) && $filter[] = ["is_del", '=', $param['is_del']];
  46. !empty($param['type']) && $filter[] = ["type", '=', $param['type']];
  47. return $filter;
  48. }
  49. }