MemberServer.php 5.8 KB

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