ServiceOrderLists.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\enum\WorkEnum;
  18. use app\common\model\recharge\RechargeOrder;
  19. use app\common\model\works\ServiceWork;
  20. /**
  21. * 服务订单列别
  22. * Class RechargeLists
  23. * @package app\api\lists\recharge
  24. */
  25. class ServiceOrderLists extends BaseApiDataLists
  26. {
  27. protected $count = 0;
  28. /**
  29. * @notes 获取列表
  30. * @return array
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\DbException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. */
  35. public function lists(): array
  36. {
  37. $where = [];
  38. $service_status = $this->params['service_status'];
  39. $work_ids = ServiceWork::where(['user_id' => $this->userId])->where(function ($query) use($service_status) {
  40. if($service_status != 'all'){
  41. $query->where(['service_status' => $service_status]);
  42. }
  43. })->column('id');
  44. if($service_status != 'all'){
  45. $where['pay_status'] = 1;
  46. }
  47. $work_ids = !empty($work_ids)?implode(',',$work_ids):'999999';
  48. $lists = RechargeOrder::with(['order_goods'=>function ($query) {
  49. $query->visible(['goods_name','goods_image','goods_number','good_unit']);
  50. },'service_work'=>function ($query) {
  51. $query->visible(['service_status','work_status','user_confirm_status','appointment_time'])->append(['service_status_text','work_status_text','user_confirm_status_text','user_service_status','user_service_status_text']);
  52. }])
  53. ->where($where)
  54. ->whereIn('work_id',$work_ids)
  55. ->visible(['id','sn','payment_type','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()->each(function ($item) {
  64. //用户按钮状态显示
  65. })
  66. ->toArray();
  67. $this->count = RechargeOrder::where([
  68. 'order_type' => 0,
  69. 'user_id' => $this->userId,
  70. ])
  71. ->where($where)
  72. ->whereIn('work_id',$work_ids)
  73. ->group('work_id')
  74. ->count();
  75. return $lists;
  76. }
  77. /**
  78. * @notes 获取数量
  79. * @return int
  80. */
  81. public function count(): int
  82. {
  83. return $this->count;
  84. }
  85. }