ShopOrderLists.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\workerapi\lists\shops;
  3. use app\common\model\shops\ShopOrders;
  4. use app\workerapi\lists\BaseWorkerDataLists;
  5. use think\db\Query;
  6. class ShopOrderLists extends BaseWorkerDataLists
  7. {
  8. protected $count = 0;
  9. public function querySearch():array
  10. {
  11. $where = [];
  12. $where[] = ['worker_id', '=', $this->userId];
  13. if(isset($this->params['shop_order_type']) && $this->params['shop_order_type'] != 'all'){
  14. $where[] = ['shop_order_type', '=', $this->params['shop_order_type']];
  15. }
  16. return $where;
  17. }
  18. public function lists():array
  19. {
  20. $lists = ShopOrders::with(['orderGoods'=>function(Query $query){
  21. $query->field(['sn','goods_name','goods_image','number','service_fee','company_name','delivery_type','shop_goods_type','goods_specs_inventory_id','specs_type','custom_attribute_items','specs'])->append(['spec_arr','delivery_type_text','shop_goods_type_text']);
  22. $query->with(['goodsSpecsInventory'=>function (Query $query) {
  23. $query->field(['id','remaining_inventory']);
  24. }]);
  25. }])
  26. ->where($this->querySearch())
  27. ->field('id, sn, pay_time, paw_way, pay_status, refund_status, create_time, amount_total, amount')
  28. ->append(['pay_way_text','pay_status_text','refund_status_text'])
  29. ->limit($this->limitOffset, $this->limitLength)
  30. ->order('id', 'desc')
  31. ->select()
  32. ->toArray();
  33. foreach($lists as &$item){
  34. foreach($item['orderGoods'] as &$val){
  35. $val['remaining_inventory'] = isset($val['goodsSpecsInventory']['remaining_inventory']) ? $val['goodsSpecsInventory']['remaining_inventory']:0;
  36. unset($val['goodsSpecsInventory'],$val['custom_attribute_items'],$val['specs'],$val['sn'],$val['goods_specs_inventory_id']);
  37. }
  38. }
  39. return $lists;
  40. }
  41. public function count(): int
  42. {
  43. return ShopOrders::where($this->querySearch())->count();
  44. }
  45. }