ServiceOrderLists.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\lists\recharge;
  15. use app\api\lists\BaseApiDataLists;
  16. use app\common\enum\PayEnum;
  17. use app\common\model\recharge\RechargeOrder;
  18. use app\common\model\works\ServiceWork;
  19. /**
  20. * 服务订单列别
  21. * Class RechargeLists
  22. * @package app\api\lists\recharge
  23. */
  24. class ServiceOrderLists extends BaseApiDataLists
  25. {
  26. protected $count = 0;
  27. public function setSearch(): array
  28. {
  29. return [
  30. '=' => ['service_status'],
  31. ];
  32. }
  33. public function queryWhere()
  34. {
  35. $where = [];
  36. if (isset($this->params['service_status'])) {
  37. $work_ids = ServiceWork::where(['user_id' => $this->userId])->where(function ($query) {
  38. if($this->params['service_status'] != 'all'){
  39. $query->where(['service_status' => $this->params['service_status']]);
  40. }
  41. })->column('id');
  42. $where['work_id'] = ['in', $work_ids];
  43. }
  44. return $where;
  45. }
  46. /**
  47. * @notes 获取列表
  48. * @return array
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function lists(): array
  54. {
  55. $lists = RechargeOrder::with(['order_goods'=>function ($query) {
  56. $query->visible(['goods_name','goods_image','goods_number','good_unit']);
  57. },'service_work'=>function ($query) {
  58. $query->visible(['service_status']);
  59. }])
  60. ->where($this->queryWhere())
  61. ->visible(['id','sn','order_total','order_amount','pay_status','create_time'])
  62. ->where([
  63. 'order_type' => 0,
  64. 'user_id' => $this->userId,
  65. ])
  66. ->limit($this->limitOffset, $this->limitLength)
  67. ->group('work_id')
  68. ->order('id', 'desc')
  69. ->select()
  70. ->toArray();
  71. $this->count = RechargeOrder::where([
  72. 'order_type' => 0,
  73. 'user_id' => $this->userId,
  74. ])
  75. ->group('work_id')
  76. ->count();
  77. return $lists;
  78. }
  79. /**
  80. * @notes 获取数量
  81. * @return int
  82. */
  83. public function count(): int
  84. {
  85. return $this->count;
  86. }
  87. }