getKey(); } /** * 添加到JWT的任何自定义声明 */ public function getJWTCustomClaims() { return []; } /*生成支付二维码*/ public static function getPayCode(string $code_url) { if(substr($code_url, 0, 6) == "weixin"){ $im= QRcode::format('png')->generate($code_url); return $im; } return ''; } // /** // * 获得此用户的角色。 // */ // public function Roles() // { // return $this->belongsToMany('App\Modes\SystemRoles', null, 'model_id', 'role_id'); // } /**************************************静态方法******************************************/ /** * 获取邀请码 * @author lyh * @date 2019/3/19 * @param $mobile * @return string * @description */ private static function getInviteCode($mobile) { return md5($mobile); } /* * 代理费折合点币 * author wsl * 20190709 * $uid 用户id * $money 缴费金额 * $type 升级1 升级区域代理4 * */ public static function conversionCoin($uid,$money,$type=1){ $userinfo=User::whereId($uid)->first(); $setting=Proxy::getSettingByAreaAndLevel($userinfo->level,$userinfo->province,$userinfo->city,$userinfo->district); if(!empty($setting)){ \DB::beginTransaction(); try { //添加点币到账户 $coin=$money*$setting['coin']/100; User::whereId($uid)->increment('coin', $coin); //添加记录 if($type==4){ $remark='【id:'.$uid.'】花费'.$money.'元升级区域代理审核通过获得点币'.$coin.'个'; }else{ $remark='【id:'.$uid.'】花费'.$money.'升级审核通过获得点币'.$coin.'个'; } $remark.=',折合率:'.$setting['coin'].'%'; AccountLog::saveDataByPost($uid,45,$coin,$userinfo->coin,1,1,$remark); //消息通知 $msgarr=['title'=>'点币到账通知','uid'=>$uid,'type'=>13,'content'=>'您的点币到账了哦']; UserMsg::insert($msgarr); \DB::commit(); } catch (\Exception $exception) { \DB::rollBack(); } } } /** * 获取二维码 * @author lyh * @date 2019/3/19 * @param string $invite_code * @return string * @description */ public static function getInviteImage(string $invite_code) { $name = '/image/invite/' . $invite_code . '.png'; if (is_numeric(QrCode::format('png')->size(400)->generate(env('APP_URL') . '/h5/#/register?inviteCode=' . $invite_code, public_path($name)))) { return $name; } return ''; } /** * 获取用户列表 * @author lyh * @date 2019/3/19 * @param $ids * @param array $array * @description */ public static function getList($ids, array $array = ['*']) { $user = User::whereIn('id', $ids)->select($array)->paginate(perPage()); return $user; } /** * 获取今天的用户量 * @author lyh * @date 2019/4/3 * @description */ public static function getRegByInToday() { $start = Carbon::today(); $end = Carbon::today()->subDay(-1)->subSecond(1); $user = User::whereBetween('created_at', [$start, $end])->whereNotNull('level'); if (\Auth::user()->is_super == 3) { $user = $user->whereIn('id', getIds()); } return $user->count('id') ?? 0; } public static function getIsApply(int $apply_level) { switch ($apply_level) { case 6: $isApply = 1; break; case 7: $isApply = 2; break; default; $isApply = 0; } return $isApply; } /** * 查找用户 * @author fatty * @date 2018/12/13 * @param $param * @return User|\Illuminate\Database\Eloquent\Model|int|null|object * @description */ public static function findUser($param) { $user = User::where([ 'account_no' => $param['account_no'], 'password' => bcrypt($param['password']) ]) ->first(); if (!$user) { return 10003; } return $user; } /** * 添加用户 * @author lyh * @date 2019/3/19 * @description */ public static function addGetId($param) { $id = User::insertGetId([ 'mobile' => $param['mobile'], 'invitor' => $param['invitor'], 'password' => self::encodePassword($param['password']), 'invite_code' => User::getInviteCode($param['mobile']), 'is_frontend' => 1 ]); // todo 待定 分销佣金分润,升级 条件在升级条件数据返回显示 //User::upgrade($param['invitor']); return $id; } /** * 加密密码 * @author lyh * @date 2019/3/19 * @param $password * @return string * @description */ public static function encodePassword($password) { return bcrypt($password); } /** * 获取所有直推用户id * @author lyh * @date 2019/3/19 * @description */ public static function getInvitee($uid, $start_time = null, $end_time = null) { $user = User::whereInvitor($uid); if ($start_time != null && $end_time != null) { $user->whereBetween('created_at', [$start_time, $end_time]); } else if ($start_time != null && $end_time = null) { $user->where('created_at', '>', $start_time); } else if ($start_time == null && $end_time != null) { $user->where('created_at', '<', $end_time); } $ids = $user->pluck('id'); if (empty($ids)) { return []; } return $ids; } /** * 获取所有间推一用户id * @author lyh * @date 2019/3/19 * @description */ public static function getInviteeOne($uid, $start_time = null, $end_time = null) { // 直推 $invitee = self::getInvitee($uid, $start_time, $end_time); if (empty($invitee)) { return []; } $user = User::whereIn('invitor', $invitee); if ($start_time != null && $end_time != null) { $user->whereBetween('created_at', [$start_time, $end_time]); } $inviteeOne = $user->pluck('id'); if (empty($inviteeOne)) { return []; } return $inviteeOne; } /** * 获取所有间推二用户id * @author lyh * @date 2019/3/19 * @description */ public static function getInviteeTwo($uid, $start_time = null, $end_time = null) { // 间推一 $inviteeOne = self::getInviteeOne($uid, $start_time, $end_time); if (empty($inviteeOne)) { return []; } $user = User::whereIn('invitor', $inviteeOne); if ($start_time != null && $end_time != null) { $user->whereBetween('created_at', [$start_time, $end_time]); } $inviteeTwo = $user->pluck('id'); if (empty($inviteeTwo)) { return []; } return $inviteeTwo; } /** * 获取三级以内所有的被邀请人id(包括自身) * @author lyh * @date 2019/3/25 * @description */ public static function getAllInvite($uid, $start_time = null, $end_time = null, $isMy = true) { $ids = []; if ($isMy == true) { $ids[] = $uid; } $invitee = self::getInvitee($uid, $start_time, $end_time); if (!empty($invitee)) { $ids = array_merge($ids, $invitee->toArray()); $inviteOne = self::getInviteeOne($uid, $start_time, $end_time); if (!empty($inviteOne)) { $ids = array_merge($ids, $inviteOne->toArray()); $inviteTwo = self::getInviteeTwo($uid, $start_time, $end_time); if (!empty($inviteTwo)) { $ids = array_merge($ids, $inviteTwo->toArray()); } } } return $ids; } /** *根据条件获取下三级代理的id * author wsl * 20190628 * * * */ public static function getAllChilds($uid,$endtime=null){ $user=User::whereInvitor($uid)->select('id','mobile','nick_name'); if ($endtime != null) { $user->where('created_at', '<',$endtime); } $childsarr=$user->get();//直推 $i=0; $arr=[]; if(!empty($childsarr)){ foreach($childsarr as $key=>$value){ $arr[]=$value->id; $childsarr1=User::whereInvitor($value->id)->select('id','mobile','nick_name')->get();//间1 if(!empty($childsarr1)){ foreach($childsarr1 as $k1=>$v1){ $arr[]=$v1->id; $childsarr2=User::whereInvitor($v1->id)->select('id','mobile','nick_name')->get();//间2 if(!empty($childsarr2)){ foreach($childsarr2 as $k2=>$v2){ $arr[]=$v2->id; } } } } } } return $arr; } /** * 获取用户信息 * @author lyh * @date 2019/3/19 * @param int $invitor * @param array $array * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|null|object * @description */ public static function getInfo(int $invitor, array $array = ['*']) { return User::whereId($invitor)->select($array)->first(); } /**************************************模型关联******************************************/ /** * [get_business_goal 统计用户的业务量:6直推投放广告交费+6自己投放广告交费+7自己所交代理费+32自己点币充值费] * @author lgs * @DateTime 2019-05-23T15:05:22+0800 * @param [type] $uid [用户id] * @param string $start_date [开始日期] * @param string $end_date [结束日期] * @return [type] [description] */ public static function get_business_goal($uid,$start_date='',$end_date=''){ $rec_uids = self::getInvitee($uid);//所有直推用户id $rec_ad = AccountLog::whereIn('type', [6])->whereBetween('created_at', [$start_date, $end_date])->whereIn('uid', $rec_uids)->whereStatus(1)->sum('money');//直推的广告费业绩 $self = AccountLog::whereIn('type', [6,7,32])->whereBetween('created_at', [$start_date, $end_date])->whereUid($uid)->whereStatus(1)->sum('money');//自己的业绩 $total = abs($rec_ad + $self);//都是负数 return $total; } }