'L0', 1 => '省级代理', 2 => '市级代理', 3 => '区级代理', 4 => '分销商', 5 => '实体店', 6 => '自营店', 7 => '厂家', 8 => '会员', ]; private $sex_arr = [ 1 => '男', 2 => '女', 3 => '保密', ]; private function __construct() { } /** * 创建对象 * @return MemberServer */ static function creatServer() { if (empty(self::$server)) { self::$server = new MemberServer(); } return self::$server; } /** * 获取对应类型名称 * @param $level_id * @return string */ public function getLevelName($level_id) { return empty($this->level_arr[$level_id]) ? '' : $this->level_arr[$level_id]; } /** * 获取性别 * @param $sex * @return string */ public function getSexArr($sex) { return empty($this->sex_arr[$sex]) ? '' : $this->sex_arr[$sex]; } /** * 注册会员 * @param $address * @param $p_id * @param string $password * @param string $level_id * @return array|false */ function register($address, $p_id, $password = '', $level_id = '0') { $member_info = []; $pass_server = PassServer::creatServer($password); if ($password) { $member_info = $pass_server->creatPassword(); } $member_info['nickname'] = '游客'; $member_info['address'] = $address; $member_info['invite_code'] = $pass_server->getInviteCode(); $member_info['recom_id'] = $p_id; $member_info['recom_address'] = Member::where('id',$p_id)->value('address')?:'无'; $member_info['status'] = 0; $member_info['level_id'] = empty($level_id)?0:$level_id; $member_info = Member::create($member_info); if (empty($member_info)) { return false; } MemberClanServer::creatServer()->creatRelevance($member_info); $token_str = PassServer::creatServer()->getMemberToken($member_info->{'id'}); Member::where('id', $member_info->{'id'})->update(['token_str' => $token_str]); // $coins=CoinType::where('status',1)->select(['id','coin_name'])->get(); // $codeImg=ImgServer::creatServer()->setCoinImg($address); // foreach ($coins as $coin){ // MemberCoins::create([ // 'm_id' => $member_info->{'id'}, // 'coin_id' => $coin->{'id'}, // 'coin_name' => $coin->{'coin_name'}, // 'num' => 0, // 'lock_num' => 0, // 'address' => $address, // 'private' => '', // 'code_img' => $codeImg, // ]); // } return [ 'token' => $token_str]; } /** * 清除会员缓存 * @param $m_id */ function delMemberCache($m_id) { RedisDataServer::creatServer()->delData('member_' . $m_id); RedisDataServer::creatServer()->delData('login_' . $m_id); RedisDataServer::creatServer()->delData('my_shop_'.$m_id); } function getMemberId(){ return request()->member['id']; } /** * 截取掉微信表情 * @param $str * @return mixed|string */ function emojiFilter($str) { if ($str) { $nickname = $str; $nickname = preg_replace('/[\x{1F600}-\x{1F64F}]/u', '', $nickname); $nickname = preg_replace('/[\x{1F300}-\x{1F5FF}]/u', '', $nickname); $nickname = preg_replace('/[\x{1F680}-\x{1F6FF}]/u', '', $nickname); $nickname = preg_replace('/[\x{2600}-\x{26FF}]/u', '', $nickname); $nickname = preg_replace('/[\x{2700}-\x{27BF}]/u', '', $nickname); $nickname = str_replace(array('"','\''), '', $nickname); return addslashes(trim($nickname)); } else { $return = ''; } return $return; } /** * 会员等级校验 * @param $pIds */ function verificationLevel($pIds){ foreach ($pIds as $pId){ $member=Member::where('id',$pId)->select(['id','address','level_id','recom_id'])->first(); $contractNum=ContractServer::creatServer()->getTeamContractNum($pId); $newLevelId=Level::where('total_num','<=',$contractNum)->where('id','>',$member->{'level_id'})->orderBy('id','desc')->value('id'); if(!empty($newLevelId) && $newLevelId>$member->{'level_id'}){ $member->update(['level_id'=>$newLevelId]); } $recomIds=Member::where('recom_id',$pId)->pluck('id')->toArray(); if($recomIds){ $contractList=Contract::whereIn('status',[2,4])->whereIn('m_id',$recomIds)->select(['m_id'])->groupBy(['m_id','status'])->get(); $contractNum=$contractList->count(); if($contractNum>=2){ $member->update(['is_boss' => 1]); } } } } }