field('provider_id,provider_name,th_province_id,th_city_id,th_region_id,th_address') ->withCount(['orderGoodsWait'=>function($query){ //$query->where('finance_clearing_status',OrderGoods::FINANCE_CLEARING_WAIT); //v1.2 待结算通过结算时间判断 $query->where('provider_settlement_time','>',0) ->where('provider_settlement_time','<',time()) ->where('finance_clearing_status','=',OrderGoods::FINANCE_CLEARING_WAIT); }])->withCount(['orderGoodsDone'=>function($query){ $query->where('finance_clearing_status',OrderGoods::FINANCE_CLEARING_DONE); }])->withCount(['orderGoodsFreeze'=>function($query){ $query->where('finance_clearing_status',OrderGoods::FINANCE_CLEARING_FREEZE); }]); if ($params){ $model = $model->whereLike('provider_name','%'.$params.'%'); } return $model->order('provider_id','desc')->paginate(15)->toArray(); } public function orderGoodsWait(){ return $this->hasMany(OrderGoods::class,'provider_id','provider_id'); } public function orderGoodsDone(){ return $this->hasMany(OrderGoods::class,'provider_id','provider_id'); } public function orderGoodsFreeze(){ return $this->hasMany(OrderGoods::class,'provider_id','provider_id'); } public function orderGoods(){ return $this->hasMany(OrderGoods::class,'provider_id','provider_id'); } /** * 导出待结算的供应商列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function providersExport($params){ $model = $this->field('provider_id,provider_name,th_province_id,th_city_id,th_region_id,th_address') ->withCount(['orderGoodsWait'=>function($query){ //v1.2 待结算通过结算时间判断 $query->where('provider_settlement_time','>',0) ->where('provider_settlement_time','<',time()) ->where('finance_clearing_status','=',OrderGoods::FINANCE_CLEARING_WAIT); }])->withCount(['orderGoodsDone'=>function($query){ $query->where('finance_clearing_status',OrderGoods::FINANCE_CLEARING_DONE); }])->withCount(['orderGoodsFreeze'=>function($query){ $query->where('finance_clearing_status',OrderGoods::FINANCE_CLEARING_FREEZE); }]); if ($params){ $model = $model->whereLike('provider_name','%'.$params.'%'); } $list = $model->order('provider_id','desc')->select()->toArray(); $data['header'] = ['序号', '供应商名称', '待结算', '已结算', '冻结中','待结算金额']; $data['filename'] = '供应商结算列表导出'; $data['data'] = []; foreach ($list as $arr){ $new_list['provider_id'] = $arr['provider_id']; $new_list['provider_name'] = $arr['provider_name']; $new_list['wait_count'] = $arr['order_goods_wait_count']; $new_list['done_count'] = $arr['order_goods_done_count']; $new_list['freeze_count'] = $arr['order_goods_freeze_count']; $new_list['wait_clearing_money'] = OrderGoodsModel::waitClearingMoney($arr['provider_id']); $data['data'][] = $new_list; } return $data; } }