123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- declare (strict_types = 1);
- namespace app\store\model;
- use app\common\model\Provider as ProviderModel;
- use app\store\model\OrderGoods as OrderGoodsModel;
- /**
- * 供应商模型
- * Class Provider
- * @package app\common\model
- */
- class Provider extends ProviderModel
- {
- public function getProviderList($params){
- $model = $this->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;
- }
- }
|