whereStatus(1)->whereUid($uid)->whereAreaType(4)->first(); } if(empty($proxy->id)){ $proxy = Proxy::whereUserLevel($level)->whereStatus(1)->where(['area_type' => 3, 'province' => $province, 'city' => $city, 'district' => $district])->first(); } $num = $proxy? $proxy->free_num : 0; $proxyUid = $proxy? $proxy->uid : 0; $free_num = 0; // 剩余免费次数 // 有活动又有单独设置,按照单独设置为准 // 有活动没有单独设置,按照活动为准 if ($proxyUid == \Auth::id() && $num > 0) { $free_num = $num; //$free_num = $proxyConfig->free_num - AdverActivityLog::whereActivityId(0)->whereUid(\Auth::id())->whereStatus(3)->sum('free_num'); } else { $exist = Advertising::whereUid($uid)->whereIn('status',[3,4,9])->where('activity_id','=',0)->exists(); //不是首次发布,不能参与免费 if ($exist) { return 0; } // 获取活动信息 $now = Carbon::now(); $activity = AdverActivity::where([ ['start_time', '<', $now], ['end_time', '>', $now] ])->orderBy('created_at','desc')->first(); if ($activity) { // 剩余次数 //$free_num = $activity->free_num - AdverActivityLog::whereActivityId($activity->id)->whereUid(\Auth::id())->whereStatus(3)->sum('free_num'); $free_num = $activity->free_num; } } return $free_num > 0 ? $free_num : 0; } /** * 根据地区获取配置信息 * @author lyh * @date 2019/3/25 * @param $uid * @param null $province * @param null $city * @param null $district * @param null $level * @return Proxy|\Illuminate\Database\Eloquent\Builder|Model|null|object * @description */ public static function getConfig($uid, $province = null, $city = null, $district = null, $level = null) { $user = \DB::table('user')->where('id', $uid)->first(); if (!empty($user->province)) { $province = $user->province; } if (!empty($user->city)) { $city = $user->city; } if (!empty($user->district)) { $district = $user->district; } $level = $level !== null ? $level : $user->level; // \DB::connection()->enableQueryLog(); // 获取用户自定义配置 if ($uid && $district == null&&$city == null) { $proxy = Proxy::whereUserLevel($level)->whereStatus(1)->whereUid($uid)->whereAreaType(4)->first(); } // 获取县区代理配置 if ($district != null && empty($proxy)) { $proxy = Proxy::whereUserLevel($level)->whereStatus(1)->where(['area_type' => 3, 'province' => $province, 'city' => $city, 'district' => $district])->first(); } // 获取地级市代理配置 if ($city != null && empty($proxy)) { $proxy = Proxy::whereUserLevel($level)->whereStatus(1)->where(['area_type' => 2, 'province' => $province, 'city' => $city])->first(); } // 获取省级代理配置 if ($proxy != null && empty($proxy)) { $proxy = Proxy::whereUserLevel($level)->whereStatus(1)->where(['area_type' => 1, 'province' => $province])->first(); } // 获取全局配置 if (empty($proxy)) { $proxy = Proxy::whereUserLevel($level)->whereStatus(1)->where(['area_type' => 0])->first(); } if (empty($proxy)) { ErrorLog::saveMsg('获取地区代理配置失败', ['uid' => $user, 'province' => $province, 'city' => $city, 'district' => $district/*, 'queryLog' => \DB::getQueryLog()*/]); } $proxy->invite = \DB::table('proxy_invite')->where('proxy_id', '=', $proxy->id)->orderBy('max','desc')->get(); return $proxy; } /* * 根据用户信息获取jian1jian2的百分比设置 * author wsl * 20190627 * $jiantype * */ public static function getJianPct($userinfo,$jiantype=1,$proxy_type=2,$ids){ $childcount=count($ids); //先找到等级配置 $jiansetting=Proxy::getJian1OrJian2Setting($userinfo['level'],$userinfo['province'],$userinfo['city'],$userinfo['district'],$jiantype,$proxy_type); //获取当前间2配置的百分比 if ($childcount <= $jiansetting[1]['max']) { $pct =$jiansetting[0]['pct']; } elseif ($childcount > $jiansetting[1]['max'] && $childcount < $jiansetting[2]['max']) { $pct = $jiansetting[1]['pct']; } else { $pct = $jiansetting[2]['pct']; } return $pct; } /* * 根据等级和所处区域查找配置 * addby wsl 20190626 * public static function getSettingByAreaAndLevel($level,$province,$city,$district){ $setting=Proxy::where('user_level','=',$level) ->where('uid','=',0) ->where('province','=',$province) ->where('city','=',$city) ->where('district','=',$district) ->first(); //如果对应区域设置为空的话则找全局配置 if(empty($setting)){ $setting=Proxy::where('user_level','=',$level) ->where('uid','=',0) ->where('province','=',0) ->where('city','=',0) ->where('district','=',0) ->first(); } $ss=empty($setting)?array():$setting->toArray(); return $ss; } */ /*根据等级和所处区域查找区域,如果所处区域有空值,则全局配置补上 author:wsl 20190704*/ public static function getSettingByAreaAndLevel($level,$province,$city,$district){ if($level>7){ return array(); } $areasetting=Proxy::whereUserLevel($level)->whereUid(0)->whereStatus(1) ->whereProvince($province)->whereCity($city)->whereDistrict($district) ->first(); $globsetting=Proxy::whereUserLevel($level)->whereUid(0) ->whereProvince(0)->whereCity(0)->whereDistrict(0) ->first()->toArray(); if(!empty($areasetting)){ $areasetting=$areasetting->toArray(); if(!empty($areasetting)){ foreach ($areasetting as $key=>$item){ if(empty($item)||$item=='0.000'||$item==null||$item=='0.00'||$item=='0.0'){ $setting[$key]=$globsetting[$key]; }else{ $setting[$key]=$item; } } }else $setting=$globsetting; }else{ $setting=$globsetting; } return $setting; } /* * 获取间1或者间2配置 * addbywsl * 20190626 * public static function getJian1OrJian2Setting($level,$province=0,$city=0,$district=0,$jiantype=1,$proxy_type=2){ $jiansetting=ProxyInvite::leftJoin('proxy','proxy_invite.proxy_id','proxy.id') ->select('proxy_invite.*','proxy.id') ->where('proxy.user_level','=',$level) ->where('proxy.province','=',$province) ->where('proxy.city','=',$city) ->where('proxy.district','=',$district) ->where('proxy_invite.type','=',$jiantype) ->where('proxy_invite.proxy_type','=',$proxy_type) ->orderBy('proxy_invite.id','asc') ->get()->toArray(); if(empty($jiansetting)){ $jiansetting=ProxyInvite::leftJoin('proxy','proxy_invite.proxy_id','proxy.id') ->select('proxy_invite.*') ->where('proxy.user_level','=',$level) ->where('proxy.province','=',0) ->where('proxy.city','=',0) ->where('proxy.district','=',0) ->where('proxy_invite.type','=',$jiantype) ->where('proxy_invite.proxy_type','=',$proxy_type) ->orderBy('proxy_invite.id','asc') ->get()->toArray(); } return $jiansetting; }*/ /* * 获取间1或者间2配置,当配置为0时就用全局配置 * addbywsl * 20190703 * */ public static function getJian1OrJian2Setting($level,$province=0,$city=0,$district=0,$jiantype=1,$proxy_type=2){ $setting=[]; $jiansetting=ProxyInvite::leftJoin('proxy','proxy_invite.proxy_id','proxy.id') ->select('proxy_invite.*','proxy.id') ->where('proxy.user_level','=',$level) ->where('proxy.province','=',$province) ->where('proxy.city','=',$city) ->where('proxy.uid','=',0) ->where('proxy.status','=',1) ->where('proxy.district','=',$district) ->where('proxy_invite.type','=',$jiantype) ->where('proxy_invite.proxy_type','=',$proxy_type) ->orderBy('proxy_invite.id','asc') ->get()->toArray(); $globaljiansetting=ProxyInvite::leftJoin('proxy','proxy_invite.proxy_id','proxy.id') ->select('proxy_invite.*') ->where('proxy.user_level','=',$level) ->where('proxy.province','=',0) ->where('proxy.city','=',0) ->where('proxy.uid','=',0) ->where('proxy.district','=',0) ->where('proxy_invite.type','=',$jiantype) ->where('proxy_invite.proxy_type','=',$proxy_type) ->orderBy('proxy_invite.id','asc') ->get()->toArray(); if(!empty($jiansetting)){ foreach ($jiansetting as $key=>$item){ foreach ($item as $k=>$v){ if(empty($v)||$v=='0.000'||$v==null||$v=='0.00'||$v=='0.0'){ $setting[$key][$k]=$globaljiansetting[$key][$k]; }else{ $setting[$key][$k]=$v; } } } }else{ $setting=$globaljiansetting; } return $setting; } public static function getApplyMoneyByConfig($province = null, $city = null, $district = null, $level = 6) { $proxy = ''; // 获取县区代理配置 if ($district != null && empty($proxy)) { $proxy = Proxy::whereUserLevel($level)->whereStatus(1)->whereUid(0)->where(['area_type' => 3, 'province' => $province, 'city' => $city, 'district' => $district])->first(); } // 获取地级市代理配置 if ($city != null && empty($proxy)) { $proxy = Proxy::whereUserLevel($level)->whereStatus(1)->whereUid(0)->where(['area_type' => 2, 'province' => $province, 'city' => $city])->first(); } // 获取省级代理配置 if ($province != null && empty($proxy)) { $proxy = Proxy::whereUserLevel($level)->whereStatus(1)->whereUid(0)->where(['area_type' => 1, 'province' => $province])->first(); } $globalproxy = Proxy::whereUserLevel($level)->whereStatus(1)->whereUid(0)->where(['area_type' => 0])->first()->toArray(); if(empty($proxy)){ $proxy=$globalproxy; }else{ $proxy=$proxy->toArray(); foreach($proxy as $k=>$item){ if(empty($item)||$item=='0.0'||$item=='0.00'||$item=='0.000'||$item==null){ $proxy[$k]=$globalproxy[$k]; } } } if (empty($proxy)) { ErrorLog::saveMsg('获取地区代理配置失败', ['province' => $province, 'city' => $city, 'district' => $district/*, 'queryLog' => \DB::getQueryLog()*/]); } return $proxy['apply_money']; } /** * 获取直推,间推1,间推2返佣比 * @author lyh * @date 2019/3/27 * @param int $id * @param int $total 人数 * @param int $type 类型 1-间推1 2-间推2 * @param int $proxyType 类型 1-代理 2-广告 * @description */ public static function getProxyInvite(int $id, int $total, $type = 0, $proxyType = 1) { $config = Proxy::getConfig($id); if ($type == 0) { return $config->proxy_invite; } else { $proxyInvite = $config->invite; foreach ($proxyInvite as $item) { if ($item->type == $type && $proxyType == $item->proxy_type) { if ($total >= $item->max) { return $item->pct; } } } return 0; } } /** * 获取广告剩余免费次数 * @author lyh * @date 2019/4/22 * @param int $id * @param $proxyConfig * @return int|mixed * @description */ public static function getFreeNum(int $id, $proxyConfig) { $free_num = 0; // 剩余免费次数 // 有活动又有单独设置,按照单独设置为准 // 有活动没有单独设置,按照活动为准 if ($proxyConfig->uid = \Auth::id() && $proxyConfig->free_num > 0) { $free_num = $proxyConfig->free_num; //$free_num = $proxyConfig->free_num - AdverActivityLog::whereActivityId(0)->whereUid(\Auth::id())->whereStatus(3)->sum('free_num'); } else { $exist = Advertising::whereUid($id)->whereIn('status',[3,4,9])->where('activity_id','=',0)->exists(); //不是首次发布,不能参与免费 if ($exist) { return 0; } // 获取活动信息 $now = Carbon::now(); $activity = AdverActivity::where([ ['start_time', '<', $now], ['end_time', '>', $now] ])->orderBy('created_at','desc')->first(); if ($activity) { // 剩余次数 //$free_num = $activity->free_num - AdverActivityLog::whereActivityId($activity->id)->whereUid(\Auth::id())->whereStatus(3)->sum('free_num'); $free_num = $activity->free_num; } } return $free_num > 0 ? $free_num : 0; } public function proxyInviteModel() { return $this->hasMany('App\Modes\ProxyInvite', 'proxy_id', 'id'); } }