OrderLists.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\businessapi\lists;
  20. use app\common\{enum\DeliveryEnum, enum\OrderEnum, enum\TeamEnum, lists\ListsExtendInterface, model\Order};
  21. /**
  22. * 订单列表接口
  23. * Class GoodsLists
  24. * @package app\adminapi\lists\goods
  25. */
  26. class OrderLists extends BaseBusinesseDataLists implements ListsExtendInterface{
  27. public function searchWhere()
  28. {
  29. $where = [];
  30. if(isset($this->params['type']) && '' != $this->params['type']) {
  31. $where[] = ['order_status','=',$this->params['type']];
  32. }
  33. if(isset($this->params['keyword']) && $this->params['keyword']) {
  34. $where[] = ['o.sn|og.goods_name','like','%'.$this->params['keyword'].'%'];
  35. }
  36. return $where;
  37. }
  38. /**
  39. * @notes 实现数据列表
  40. * @return array
  41. * @author 令狐冲
  42. * @date 2021/7/6 00:33
  43. */
  44. public function lists(): array
  45. {
  46. $lists = Order::alias('o')->where($this->searchWhere())
  47. ->join('order_goods og','o.id = og.order_id')
  48. ->with(['order_goods' => function ($query) {
  49. $query->field('goods_id,order_id,goods_snap,goods_name,goods_price,goods_num,is_comment,original_price')
  50. ->append(['goods_image', 'spec_value_str'])
  51. ->hidden(['goods_snap']);
  52. },'user'])
  53. ->field(['o.id', 'o.sn', 'o.user_id','o.order_type', 'o.order_status', 'o.total_num', 'o.order_amount', 'o.delivery_type', 'o.is_team_success', 'o.pay_status', 'o.express_status','o.delivery_content', 'o.create_time', 'o.pay_way'])
  54. ->append(['businesse_btn'])
  55. ->order(['o.id' => 'desc'])
  56. ->group('o.id')
  57. ->limit($this->limitOffset, $this->limitLength)
  58. ->select()->toArray();
  59. foreach ($lists as &$list){
  60. //查看提货码按钮
  61. // $list['businesse_btn']['pickup_btn'] = ($list['order_status'] == OrderEnum::STATUS_WAIT_DELIVERY && $list['delivery_type'] == DeliveryEnum::SELF_DELIVERY) ? 1 : 0;
  62. //订单状态描述
  63. $list['order_status_desc'] = ($list['order_status'] == OrderEnum::STATUS_WAIT_DELIVERY && $list['delivery_type'] == DeliveryEnum::SELF_DELIVERY) ? '待取货' : OrderEnum::getOrderStatusDesc($list['order_status']);
  64. if ($list['order_type'] == OrderEnum::TEAM_ORDER && $list['is_team_success'] != TeamEnum::TEAM_FOUND_SUCCESS){
  65. // $list['btn']['pickup_btn'] = 0;
  66. $list['order_status_desc'] = ($list['order_status'] == OrderEnum::STATUS_WAIT_DELIVERY) ? TeamEnum::getStatusDesc($list['is_team_success']) : OrderEnum::getOrderStatusDesc($list['order_status']);
  67. }
  68. //订单类型
  69. $list['order_type_desc'] = ($list['delivery_type'] == DeliveryEnum::SELF_DELIVERY) ? '自提订单' : OrderEnum::getOrderTypeDesc($list['order_type']);
  70. }
  71. return $lists;
  72. }
  73. /**
  74. * @notes 实现数据列表记录数
  75. * @return int
  76. * @author 令狐冲
  77. * @date 2021/7/6 00:34
  78. */
  79. public function count(): int
  80. {
  81. return Order::alias('o')
  82. ->join('order_goods og','o.id = og.order_id')
  83. ->group('o.id')
  84. ->where($this->searchWhere())->count();
  85. }
  86. /**
  87. * @notes 扩展字段
  88. * @return mixed
  89. * @author 令狐冲
  90. * @date 2021/7/21 17:45
  91. */
  92. public function extend(): array
  93. {
  94. $lists = (new Order)::alias('o')
  95. ->join('user u','o.user_id = u.id')
  96. ->join('order_goods og','o.id = og.order_id')
  97. ->group('o.id')
  98. ->field('o.id,o.order_status')
  99. ->select()
  100. ->toArray();
  101. $data['all_count'] = 0;
  102. $data['pay_count'] = 0;
  103. $data['delivery_count'] = 0;
  104. $data['receive_count'] = 0;
  105. $data['finish_count'] = 0;
  106. $data['close_count'] = 0;
  107. foreach ($lists as $val) {
  108. $data['all_count'] += 1;
  109. if ($val['order_status'] == 0) {
  110. $data['pay_count'] += 1;
  111. }
  112. if ($val['order_status'] == 1) {
  113. $data['delivery_count'] += 1;
  114. }
  115. if ($val['order_status'] == 2) {
  116. $data['receive_count'] += 1;
  117. }
  118. if ($val['order_status'] == 3) {
  119. $data['finish_count'] += 1;
  120. }
  121. if ($val['order_status'] == 4) {
  122. $data['close_count'] += 1;
  123. }
  124. }
  125. return $data;
  126. }
  127. }