ServiceOrderLists.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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'] = $service_status==4?2: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(['work_sn','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. ->field('id, sn, payment_type, order_total,work_id, pay_status, create_time, SUM(order_amount) as order_amount')
  56. ->visible(['id','sn','payment_type','order_total','pay_status','create_time','order_amount'])
  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()->each(function ($item) {
  65. //用户按钮状态显示
  66. })
  67. ->toArray();
  68. $this->count = RechargeOrder::where([
  69. 'order_type' => 0,
  70. 'user_id' => $this->userId,
  71. ])
  72. ->where($where)
  73. ->whereIn('work_id',$work_ids)
  74. ->group('work_id')
  75. ->count();
  76. return $lists;
  77. }
  78. /**
  79. * @notes 获取数量
  80. * @return int
  81. */
  82. public function count(): int
  83. {
  84. return $this->count;
  85. }
  86. }