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