PropertyGroupOrderLists.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\api\lists\property;
  3. use think\facade\Db;
  4. use app\api\lists\BaseApiDataLists;
  5. use app\common\lists\ListsSearchInterface;
  6. use app\common\model\property\PropertyHead;
  7. use app\common\model\group_activity\GroupUserOrder;
  8. /**
  9. * 代理人拼团订单列表
  10. * Class PropertyGroupOrderLists
  11. * @package app\api\lists\property
  12. */
  13. class PropertyGroupOrderLists extends BaseApiDataLists implements ListsSearchInterface
  14. {
  15. /**
  16. * @notes 设置搜索条件
  17. * @return \string[][]
  18. * @author likeadmin
  19. * @date 2024/07/07 18:37
  20. */
  21. public function setSearch(): array
  22. {
  23. return [
  24. '=' => [],
  25. ];
  26. }
  27. public function queryWhere()
  28. {
  29. // 指定用户
  30. $propertyHeadId = (int)PropertyHead::where('user_id',$this->userId)->value('id');
  31. $where[] = ['b.property_head_id', '=', $propertyHeadId];
  32. if (isset($this->params['status'])) {
  33. if ($this->params['status'] == 0) {
  34. //待完成
  35. $where[] = ['a.status', '=', 1];
  36. $where[] = ['c.service_status', 'exp', Db::Raw('IS NULL OR c.service_status <> 3')];
  37. } elseif ($this->params['status'] == 1) {
  38. //工单已完成
  39. $where[] = ['c.service_status', '=', 3];
  40. } else {
  41. //已退款
  42. $where[] = ['a.status', 'in', [2,3]];
  43. }
  44. }
  45. if (isset($this->params['start_time']) && !empty($this->params['start_time'])) {
  46. $monthStart = strtotime(date("Y-m-01",strtotime($this->params['start_time'])));
  47. $monthEnd = strtotime(date("Y-m-t 23:59:59",strtotime($this->params['start_time'])));
  48. $where[] = ['a.create_time', 'between', [$monthStart, $monthEnd]];
  49. }
  50. return $where;
  51. }
  52. /**
  53. * @notes 获取列表
  54. * @return array
  55. */
  56. public function lists(): array
  57. {
  58. $lists = GroupUserOrder::alias('a')
  59. ->leftJoin('group_order b','a.group_order_id=b.id')
  60. ->leftJoin('group_service_work c','a.id=c.group_user_order_id')
  61. ->leftJoin('group_activity d','a.group_activity_id=d.id')
  62. ->field('a.id,a.status,a.order_amount,a.mobile,a.area,a.address,a.create_time,a.group_activity_id,a.num,c.service_status,d.title')
  63. ->where($this->queryWhere())
  64. ->limit($this->limitOffset, $this->limitLength)
  65. ->order('a.create_time', 'desc')
  66. ->select()
  67. ->toArray();
  68. foreach($lists as &$item) {
  69. if ($item['status'] == 0) {
  70. $item['status_txt'] = '未支付';
  71. } else if ($item['status'] == 2 || $item['status'] == 3) {
  72. $item['status_txt'] = '已退款';
  73. } else if ($item['status'] == 4) {
  74. $item['status_txt'] = '已取消';
  75. } else if ($item['service_status'] == 3) {
  76. $item['status_txt'] = '已完成';
  77. } else {
  78. $item['status_txt'] = '待完成';
  79. }
  80. }
  81. return $lists;
  82. }
  83. /**
  84. * @notes 获取数量
  85. * @return int
  86. */
  87. public function count(): int
  88. {
  89. return GroupUserOrder::alias('a')
  90. ->leftJoin('group_order b','a.group_order_id=b.id')
  91. ->leftJoin('group_service_work c','a.id=c.group_user_order_id')
  92. ->where($this->queryWhere())
  93. ->count();
  94. }
  95. }