| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- <?php
- namespace App\Modes;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Notifications\Notifiable;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use SimpleSoftwareIO\QrCode\Facades\QrCode;
- use Spatie\Permission\Traits\HasRoles;
- use Tymon\JWTAuth\Contracts\JWTSubject;
- /**
- * App\Modes\User
- *
- * @property int $id
- * @property int|null $mobile 手机号码
- * @property string $nick_name 昵称
- * @property string $avatar 头像
- * @property string $password 密码
- * @property string $real_name 真实姓名
- * @property string $id_card 真实姓名
- * @property float $balance 余额
- * @property float $coin 点币
- * @property string $ssid session_id
- * @property int $province 省份(area.id)
- * @property int $city 市(area.id)
- * @property int $district 区(area.id)
- * @property int $invitor 邀请人id
- * @property string $invite_code 邀请码
- * @property int $level 等级:1-A 2-B 3-C 4-D 5-E 6-F 7-G 8-H
- * @property int $is_frontend 是否前端用户 1-是
- * @property int $status 状态 1-启用 2-禁用
- * @property int $full_status 是否完成资料填写 0-否 1-完成
- * @property int $is_super 是否超级管理员 0-否 1-是 2-普通管理员 3-代理管理员
- * @property int $shadow 影子用户 1-是
- * @property int $commission_status 是否修改分佣比例状态 1-未修改 2-修改
- * @property int $sadmin_uid 地区代理管理员id
- * @property \Illuminate\Support\Carbon $created_at
- * @property \Illuminate\Support\Carbon $updated_at
- * @property string|null $deleted_at 是否删除
- * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
- * @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Permission\Models\Permission[] $permissions
- * @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Permission\Models\Role[] $roles
- * @method static bool|null forceDelete()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User newModelQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User newQuery()
- * @method static \Illuminate\Database\Query\Builder|\App\Modes\User onlyTrashed()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User permission($permissions)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User query()
- * @method static bool|null restore()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User role($roles, $guard = null)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereAvatar($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereSsid($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereBalance($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereCity($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereCoin($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereCommissionStatus($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereCreatedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereDeletedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereDistrict($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereFullStatus($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereIdCard($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereInviteCode($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereInvitor($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereIsFrontend($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereIsSuper($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereLevel($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereMobile($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereNickName($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User wherePassword($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereProvince($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereRealName($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereSadminUid($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereShadow($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereStatus($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereUpdatedAt($value)
- * @method static \Illuminate\Database\Query\Builder|\App\Modes\User withTrashed()
- * @method static \Illuminate\Database\Query\Builder|\App\Modes\User withoutTrashed()
- * @mixin \Eloquent
- * @property int $is_apply 是否可以申请成为区域代理 0-否 n-是(1-县区级 2-市级)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User whereIsApply($value)
- * @property string $pay_password 支付密码
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\User wherePayPassword($value)
- */
- class User extends Authenticatable implements JWTSubject
- {
- use HasRoles, SoftDeletes, Notifiable;
- protected $table = 'user';
- protected $guarded = [
- ];
- protected $guard_name = 'backendGuard';
- protected $dates = ['created_at'];
- protected static $ids = [];
- protected $hidden = [
- // 'password'
- ];
- public function getJWTIdentifier()
- {
- return $this->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;
- }
- }
|