ServiceOrderLists.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 queryWhere()
  28. {
  29. $where = [];
  30. if (isset($this->params['service_status'])) {
  31. $service_status = $this->params['service_status'];
  32. $work_ids = ServiceWork::where(['user_id' => $this->userId])->where(function ($query) use($service_status) {
  33. if($service_status != 'all'){
  34. $query->where(['service_status' => $service_status]);
  35. }
  36. })->column('id');
  37. $where['work_id'] = ['in', !empty($work_ids)?$work_ids:5];
  38. }
  39. return $where;
  40. }
  41. /**
  42. * @notes 获取列表
  43. * @return array
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. public function lists(): array
  49. {
  50. $lists = RechargeOrder::with(['order_goods'=>function ($query) {
  51. $query->visible(['goods_name','goods_image','goods_number','good_unit']);
  52. },'service_work'=>function ($query) {
  53. $query->visible(['service_status']);
  54. }])
  55. ->where($this->queryWhere())
  56. ->visible(['id','sn','order_total','order_amount','pay_status','create_time'])
  57. ->where([
  58. 'order_type' => 0,
  59. 'user_id' => $this->userId,
  60. ])
  61. ->limit($this->limitOffset, $this->limitLength)
  62. ->group('work_id')
  63. ->order('id', 'desc')
  64. ->select()
  65. ->toArray();
  66. $this->count = RechargeOrder::where([
  67. 'order_type' => 0,
  68. 'user_id' => $this->userId,
  69. ])
  70. ->group('work_id')
  71. ->count();
  72. return $lists;
  73. }
  74. /**
  75. * @notes 获取数量
  76. * @return int
  77. */
  78. public function count(): int
  79. {
  80. return $this->count;
  81. }
  82. }