123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- namespace App\Servers;
- use App\Jobs\RelevanceJob;
- use App\Jobs\UploadingImgJob;
- use App\Models\CoinType;
- use App\Models\Contract;
- use App\Models\ErrorRecord;
- use App\Models\ImService;
- use App\Models\Level;
- use App\Models\Member;
- use App\Models\MemberClan;
- use App\Models\MemberCoins;
- use App\Models\MemberOpenId;
- use App\Models\MoneyDetail;
- use App\Models\MoneyRecord;
- use App\Models\Order;
- use App\Models\Shop;
- use App\Models\ShopBean;
- use App\Models\ShopCommission;
- use App\Models\ShopFans;
- use App\Models\ShopMoney;
- use App\Models\ShopSet;
- use App\Models\ShopUser;
- use Illuminate\Support\Facades\Auth;
- use Intervention\Image\Facades\Image;
- /**
- * 会员
- */
- class MemberServer
- {
- /**
- * 错误信息
- * @var string
- */
- private $errorMsg = '';
- static private $server = '';
- private $level_arr = [
- 0 => '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]);
- }
- }
- }
- }
- }
|