MemberServer.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. namespace App\Servers;
  3. use App\Jobs\RelevanceJob;
  4. use App\Jobs\UploadingImgJob;
  5. use App\Models\CoinType;
  6. use App\Models\ErrorRecord;
  7. use App\Models\ImService;
  8. use App\Models\Level;
  9. use App\Models\Member;
  10. use App\Models\MemberClan;
  11. use App\Models\MemberCoins;
  12. use App\Models\MemberOpenId;
  13. use App\Models\MoneyDetail;
  14. use App\Models\MoneyRecord;
  15. use App\Models\Order;
  16. use App\Models\Shop;
  17. use App\Models\ShopBean;
  18. use App\Models\ShopCommission;
  19. use App\Models\ShopFans;
  20. use App\Models\ShopMoney;
  21. use App\Models\ShopSet;
  22. use App\Models\ShopUser;
  23. use Illuminate\Support\Facades\Auth;
  24. use Intervention\Image\Facades\Image;
  25. /**
  26. * 会员
  27. */
  28. class MemberServer
  29. {
  30. /**
  31. * 错误信息
  32. * @var string
  33. */
  34. private $errorMsg = '';
  35. static private $server = '';
  36. private $level_arr = [
  37. 0 => 'L0',
  38. 1 => '省级代理',
  39. 2 => '市级代理',
  40. 3 => '区级代理',
  41. 4 => '分销商',
  42. 5 => '实体店',
  43. 6 => '自营店',
  44. 7 => '厂家',
  45. 8 => '会员',
  46. ];
  47. private $sex_arr = [
  48. 1 => '男',
  49. 2 => '女',
  50. 3 => '保密',
  51. ];
  52. private function __construct()
  53. {
  54. }
  55. /**
  56. * 创建对象
  57. * @return MemberServer
  58. */
  59. static function creatServer()
  60. {
  61. if (empty(self::$server)) {
  62. self::$server = new MemberServer();
  63. }
  64. return self::$server;
  65. }
  66. /**
  67. * 获取对应类型名称
  68. * @param $level_id
  69. * @return string
  70. */
  71. public function getLevelName($level_id)
  72. {
  73. return empty($this->level_arr[$level_id]) ? '' : $this->level_arr[$level_id];
  74. }
  75. /**
  76. * 获取性别
  77. * @param $sex
  78. * @return string
  79. */
  80. public function getSexArr($sex)
  81. {
  82. return empty($this->sex_arr[$sex]) ? '' : $this->sex_arr[$sex];
  83. }
  84. /**
  85. * 注册会员
  86. * @param $address
  87. * @param $p_id
  88. * @param string $password
  89. * @param string $level_id
  90. * @return array|false
  91. */
  92. function register($address, $p_id, $password = '', $level_id = '0')
  93. {
  94. $member_info = [];
  95. $pass_server = PassServer::creatServer($password);
  96. if ($password) {
  97. $member_info = $pass_server->creatPassword();
  98. }
  99. $member_info['nickname'] = '游客';
  100. $member_info['address'] = $address;
  101. $member_info['invite_code'] = $pass_server->getInviteCode();
  102. $member_info['recom_id'] = $p_id;
  103. $member_info['recom_address'] = Member::where('id',$p_id)->value('address')?:'无';
  104. $member_info['status'] = 0;
  105. $member_info['level_id'] = empty($level_id)?0:$level_id;
  106. $member_info = Member::create($member_info);
  107. if (empty($member_info)) {
  108. return false;
  109. }
  110. MemberClanServer::creatServer()->creatRelevance($member_info);
  111. $token_str = PassServer::creatServer()->getMemberToken($member_info->{'id'});
  112. Member::where('id', $member_info->{'id'})->update(['token_str' => $token_str]);
  113. // $coins=CoinType::where('status',1)->select(['id','coin_name'])->get();
  114. // $codeImg=ImgServer::creatServer()->setCoinImg($address);
  115. // foreach ($coins as $coin){
  116. // MemberCoins::create([
  117. // 'm_id' => $member_info->{'id'},
  118. // 'coin_id' => $coin->{'id'},
  119. // 'coin_name' => $coin->{'coin_name'},
  120. // 'num' => 0,
  121. // 'lock_num' => 0,
  122. // 'address' => $address,
  123. // 'private' => '',
  124. // 'code_img' => $codeImg,
  125. // ]);
  126. // }
  127. return [ 'token' => $token_str];
  128. }
  129. /**
  130. * 清除会员缓存
  131. * @param $m_id
  132. */
  133. function delMemberCache($m_id)
  134. {
  135. RedisDataServer::creatServer()->delData('member_' . $m_id);
  136. RedisDataServer::creatServer()->delData('login_' . $m_id);
  137. RedisDataServer::creatServer()->delData('my_shop_'.$m_id);
  138. }
  139. function getMemberId(){
  140. return request()->member['id'];
  141. }
  142. /**
  143. * 截取掉微信表情
  144. * @param $str
  145. * @return mixed|string
  146. */
  147. function emojiFilter($str)
  148. {
  149. if ($str) {
  150. $nickname = $str;
  151. $nickname = preg_replace('/[\x{1F600}-\x{1F64F}]/u', '', $nickname);
  152. $nickname = preg_replace('/[\x{1F300}-\x{1F5FF}]/u', '', $nickname);
  153. $nickname = preg_replace('/[\x{1F680}-\x{1F6FF}]/u', '', $nickname);
  154. $nickname = preg_replace('/[\x{2600}-\x{26FF}]/u', '', $nickname);
  155. $nickname = preg_replace('/[\x{2700}-\x{27BF}]/u', '', $nickname);
  156. $nickname = str_replace(array('"','\''), '', $nickname);
  157. return addslashes(trim($nickname));
  158. } else {
  159. $return = '';
  160. }
  161. return $return;
  162. }
  163. /**
  164. * 会员等级校验
  165. * @param $pIds
  166. */
  167. function verificationLevel($pIds){
  168. foreach ($pIds as $pId){
  169. $member=Member::where('id',$pId)->select(['id','address','level_id'])->first();
  170. $contractNum=ContractServer::creatServer()->getTeamContractNum($pId);
  171. $newLevelId=Level::where('total_num','<=',$contractNum)->where('id','>',$member->{'level_id'})->orderBy('id','desc')->value('id');
  172. if(!empty($newLevelId) && $newLevelId>$member->{'level_id'}){
  173. $member->update(['level_id'=>$newLevelId]);
  174. }
  175. }
  176. }
  177. }