| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace app\workerapi\lists\shops;
- use app\common\model\shops\ShopOrders;
- use app\workerapi\lists\BaseWorkerDataLists;
- use think\db\Query;
- class ShopOrderLists extends BaseWorkerDataLists
- {
- protected $count = 0;
- public function querySearch():array
- {
- $where = [];
- $where[] = ['worker_id', '=', $this->userId];
- if(isset($this->params['shop_order_type']) && $this->params['shop_order_type'] != 'all'){
- $where[] = ['shop_order_type', '=', $this->params['shop_order_type']];
- }
- return $where;
- }
- public function lists():array
- {
- $lists = ShopOrders::with(['orderGoods'=>function(Query $query){
- $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']);
- $query->with(['goodsSpecsInventory'=>function (Query $query) {
- $query->field(['id','remaining_inventory']);
- }]);
- }])
- ->where($this->querySearch())
- ->field('id, sn, pay_time, paw_way, pay_status, refund_status, create_time, amount_total, amount')
- ->append(['pay_way_text','pay_status_text','refund_status_text'])
- ->limit($this->limitOffset, $this->limitLength)
- ->order('id', 'desc')
- ->select()
- ->toArray();
- foreach($lists as &$item){
- foreach($item['orderGoods'] as &$val){
- $val['remaining_inventory'] = isset($val['goodsSpecsInventory']['remaining_inventory']) ? $val['goodsSpecsInventory']['remaining_inventory']:0;
- unset($val['goodsSpecsInventory'],$val['custom_attribute_items'],$val['specs'],$val['sn'],$val['goods_specs_inventory_id']);
- }
- }
- return $lists;
- }
- public function count(): int
- {
- return ShopOrders::where($this->querySearch())->count();
- }
- }
|