// +---------------------------------------------------------------------- declare (strict_types = 1); namespace app\store\model; use app\common\model\ApplySeller as ApplySellerModel; use app\console\model\user\CommissionsDetail; /** * 配送模板模型 * Class Delivery * @package app\common\model */ class ApplySeller extends ApplySellerModel { /** * 隐藏字段 * @var array */ protected $hidden = [ 'is_delete', 'store_id', //'update_time' ]; public function getList($conditions){ $model = new self; $from = 1633017600 ;$to = time(); if ($conditions and count($conditions)){ foreach ($conditions as $key=>$c){ if ($key =='betweenTime'){ if (isset($c[0]) && $c[0] && isset($c[1]) && $c[1]){ $times = between_time($c); $from = $times['start_time']; $to = $times['end_time'] + 86400; } } if ($key == "mobile" && trim($c,' ')){ $model = $model->whereLike($key,'%'.$c.'%'); } } if ($from && $to){ $model = $model->whereBetweenTime('create_time',$from,$to); } } return $model->where('is_delete',0) ->field('id,user_id,nick_name,mobile,create_time,update_time,state,seller_grade,invite_code') ->order('state','asc')->order('create_time','desc') ->paginate(15)->each(function($item){ $item->sale_volume = 0.00; $item->inviter_sale_volume = 0.00; if ($item->state == 1){ $user = User::where('user_id',$item->user_id)->find(); if ($user){ $from = strtotime('-1 year',$user->seller_expire); $wheres[] = ['user_id','=',$item->user_id]; $wheres[] = ['shop_id','=',0]; $wheres[] = ['role','=',User::COMMISSION_USER]; $wheres[] = ['commission_level','=',1]; $wheres[] = ['order_create_time','>=',$from]; $wheres[] = ['order_create_time','<=',$user->seller_expire]; $wheres[] = ['clearing_status','<',2]; $item->sale_volume = CommissionsDetail::sumOrderSaleVolume($wheres); /* $orderGoodsId = CommissionsDetail::getCommOrderGoodsId($item->user_id,$from,$user->seller_expire); $item->sale_volume = \app\console\model\OrderGoods::sumOrderGoodsVolume($orderGoodsId);*/ } $user_ids = User::where("upper_user_id",$item->user_id)->where('role',99)->column('user_id'); if($user_ids){ $wheres[] = ['user_id','in',$user_ids]; $wheres[] = ['shop_id','=',0]; $wheres[] = ['role','=',User::COMMISSION_USER]; $wheres[] = ['commission_level','=',1]; $wheres[] = ['clearing_status','<',2]; $item->inviter_sale_volume = CommissionsDetail::sumOrderSaleVolume($wheres); } } //下级推荐官数 $item['inviter_cnt'] = User::where("upper_user_id",$item->user_id)->where('role',User::COMMISSION_USER)->count(); //下级用户数 $item['inviter_users'] = User::where("upper_user_id",$item->user_id)->where('role',User::NORMAL_USER)->count(); })->toArray(); } public function edit($data){ if (!isset($data['id']))return false; $m = self::find($data['id']); $m->state = $data['state']; $m->seller_grade = 1; $m->refuse_reason = $data['refuse_reason']??''; $m->save(); //self::where('id',$data['id'])->update(['state'=>$data['state'],'seller_grade'=>1,'refuse_reason'=>$data['refuse_reason']??'']); if ($data['state'] == 1 && isset($data['user_id'])){ $seller_expire = strtotime('+1 year'); User::where('user_id',intval($data['user_id']))->update(['role'=>99,'seller_grade'=>1,'seller_expire'=>$seller_expire]); } return true; } }