MemberController.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\FrontController;
  4. use App\Jobs\BarrageJob;
  5. use App\Jobs\MemberShareJob;
  6. use App\Jobs\SaveImGroup;
  7. use App\Models\Comment;
  8. use App\Models\Contract;
  9. use App\Models\Express;
  10. use App\Models\Goods;
  11. use App\Models\GoodsBrowse;
  12. use App\Models\GoodsCollect;
  13. use App\Models\Level;
  14. use App\Models\Member;
  15. use App\Models\MemberAddress;
  16. use App\Models\MemberClan;
  17. use App\Models\MemberCoins;
  18. use App\Models\MemberCoupon;
  19. use App\Models\MemberOpenId;
  20. use App\Models\Members;
  21. use App\Models\MoneyDetail;
  22. use App\Models\MoneyRecord;
  23. use App\Models\Order;
  24. use App\Models\RefundOrder;
  25. use App\Models\SeckillGoods;
  26. use App\Models\Shop;
  27. use App\Models\ShopCollect;
  28. use App\Models\ShopOrder;
  29. use App\Servers\AddressServer;
  30. use App\Servers\CommonServer;
  31. use App\Servers\ExpressServer;
  32. use App\Servers\GoodsServer;
  33. use App\Servers\Icon\Address;
  34. use App\Servers\ImgServer;
  35. use App\Servers\KdnServer;
  36. use App\Servers\MemberLogsServer;
  37. use App\Servers\MemberServer;
  38. use App\Servers\MergeServer;
  39. use App\Servers\MoneyDetailServer;
  40. use App\Servers\PassServer;
  41. use App\Servers\RedisDataServer;
  42. use App\Servers\SensitiveServer;
  43. use App\Servers\SmsServer;
  44. use App\Servers\WeixinServer;
  45. use App\Servers\WxTemplateServer;
  46. use Carbon\Carbon;
  47. use SimpleSoftwareIO\QrCode\Facades\QrCode;
  48. use SwooleTW\Http\Websocket\Facades\Websocket;
  49. class MemberController extends FrontController
  50. {
  51. public function __construct()
  52. {
  53. parent::__construct();
  54. }
  55. function index()
  56. {
  57. }
  58. /**
  59. * 会员注册
  60. * @return \Illuminate\Http\JsonResponse
  61. */
  62. function register()
  63. {
  64. $invite_code = request()->input('inviteCode', '');
  65. if (!empty($invite_code)) {
  66. $p_member = Member::where([['invite_code','=', $invite_code,'or'],['address','=', $invite_code,'or']])->select(['id', 'address'])->first();
  67. }
  68. if (empty($p_member)) {
  69. return $this->apiResponseError('member.no_invite');
  70. }
  71. $address = request()->input('address', '');
  72. if (empty($address)) {
  73. return $this->apiResponseError('地址信息异常');
  74. }
  75. $member = Member::where('address', $address)->where('status',1)->select(['id', 'token_str'])->first();
  76. if ($member) {
  77. $token_str = PassServer::creatServer()->getMemberToken($member->{'id'});
  78. Member::where('id', $member->{'id'})->update(['token_str' => $token_str]);
  79. return $this->apiResponseSuccess('登陆成功', [ 'token' => $token_str]);
  80. } else {
  81. $ret = MemberServer::creatServer()->register($address, $p_member->{'id'}, '', '');
  82. if (empty($ret)) {
  83. return $this->apiResponseError('注册失败');
  84. } else {
  85. return $this->apiResponseSuccess('注册成功', $ret);
  86. }
  87. }
  88. }
  89. /**
  90. * 会员登录
  91. * @return \Illuminate\Http\JsonResponse
  92. */
  93. function login()
  94. {
  95. $mobile = request()->input('address', '');
  96. if (empty($mobile)) {
  97. return $this->apiResponseError('地址信息错误');
  98. }
  99. $member = Member::where('address', $mobile)->select(['id', 'password', 'encrypt'])->first();
  100. if (empty($member)) {
  101. return $this->apiResponseError('当前账户未注册');
  102. }
  103. $token_str = PassServer::creatServer()->getMemberToken($member->{'id'});
  104. Member::where('id', $member->{'id'})->update(['token_str' => $token_str]);
  105. return $this->apiResponseSuccess('登陆成功', ['token' => $token_str]);
  106. }
  107. /**
  108. * 设置支付密码
  109. * @return \Illuminate\Http\JsonResponse
  110. */
  111. function setPayPass()
  112. {
  113. $password = request()->input('pay_pass', '123456');
  114. $password = str_replace(' ', '', $password);
  115. if (empty($password)) {
  116. return $this->apiResponseError('请设置登录密码');
  117. }
  118. $pass_two = request()->input('pass_two', '123456');
  119. if ($password != $pass_two) {
  120. return $this->apiResponseError('两次密码输入不一致');
  121. }
  122. if (!is_numeric($password) || strlen($password) != 6) {
  123. return $this->apiResponseError('支付密码必须为6为数字');
  124. }
  125. $member = Member::where('id', request()->member['id'])->where('status',1)->select(['id', 'password', 'encrypt', 'phone'])->first();
  126. $update=[];
  127. $code = request()->input('code', '1234');
  128. if (empty($code)) {
  129. return $this->apiResponseError('请输入验证码');
  130. }
  131. $ret = SmsServer::creatServer()->verifyCode($member->{'phone'}, $code, 'set_pay_pass');
  132. if (empty($ret)) {
  133. return $this->apiResponseError('验证码错误');
  134. }
  135. $pass_server = PassServer::creatServer($password, $member->{'encrypt'});
  136. $new_pass = $pass_server->creatPassword();
  137. $update['pay_pass']=$new_pass['password'];
  138. $update['encrypt']=$new_pass['encrypt'];
  139. $ret = $member->update($update);
  140. if (empty($ret)) {
  141. return $this->apiResponseError('支付密码修改失败');
  142. } else {
  143. MemberServer::creatServer()->delMemberCache($member->{'id'});
  144. return $this->apiResponseSuccess('支付密码修改成功');
  145. }
  146. }
  147. function getIconList(){
  148. $mId=request()->member['id'];
  149. $totalPrice=0;
  150. $totalUsdt=0;
  151. $usdtPrice=CommonServer::creatServer()->getConfigValue('usdt');
  152. $luckyPrice=CommonServer::creatServer()->getConfigValue('lucky');
  153. $list=MemberCoins::where('m_id',$mId)->select(['coin_name','coin_id','num','lock_num'])->get();
  154. foreach ($list as $value){
  155. if($value->{'coin_id'}==1){
  156. $value->{'price'}=round(($value->{'num'}+$value->{'lock_num'})*$usdtPrice*$luckyPrice,6);
  157. $value->{'totalUsdt'}=round(($value->{'num'}+$value->{'lock_num'})*$luckyPrice,6);
  158. }else{
  159. $value->{'price'}=round(($value->{'num'}+$value->{'lock_num'})*$usdtPrice,6);
  160. $value->{'totalUsdt'}=round($value->{'num'}+$value->{'lock_num'},6);
  161. }
  162. $totalPrice+=$value->{'price'};
  163. $totalUsdt+=$value->{'totalUsdt'};
  164. }
  165. return $this->apiResponseSuccess('获取信息成功',['totalPrice'=>$totalPrice,'totalUsdt'=>$totalUsdt,'list'=>$list]);
  166. }
  167. /**
  168. * 获取用户资产信息
  169. */
  170. function getMoneyInfo()
  171. {
  172. $member = Member::where('id', request()->member['id'])->where('status',1)->select(['id', 'money'])->first();
  173. return $this->apiResponseSuccess('获取成功', $member);
  174. }
  175. /**
  176. * 获取会员详情
  177. */
  178. function getMemberInfo()
  179. {
  180. $m_id = request()->member['id'];
  181. $member = RedisDataServer::creatServer()->getData('member_' . $m_id, 'json');
  182. if (empty($member) ) {
  183. $member = Member::where('id', $m_id)->select(['id', 'address', 'invite_code', 'level_id'])->first();
  184. if (empty($member)) {
  185. return $this->apiResponseError('账户信息错误', 401);
  186. }
  187. //获取推荐关联信息
  188. if($member->{'level_id'}<=0){
  189. $member->{'levelName'}='V0';
  190. }else{
  191. $member->{'levelName'}=Level::where('id',$member->{'level_id'})->value('name');
  192. }
  193. $member->{'recommendNum'}=Member::where('recom_id',$member->{'id'})->count();
  194. $teamIds=MemberClan::where('m_id',$member->{'id'})->value('m_ids');
  195. $teamIds=array_filter(explode(',',$teamIds));
  196. $member->{'teamNum'}=count($teamIds);
  197. $member->{'orderNum'}=Contract::where('m_id',$member->{'id'})->whereIn('status',[2,4])->count();
  198. RedisDataServer::creatServer()->setData('member_' . $m_id, $member, 'json', 30);
  199. }
  200. return $this->apiResponseSuccess('获取信息成功', $member);
  201. }
  202. /**
  203. * 获取推广团队基本信息
  204. * @return \Illuminate\Http\JsonResponse
  205. */
  206. function getTeamInfo()
  207. {
  208. $m_id = request()->member['id'];
  209. $member = Member::where('id', $m_id)->select(['id', 'address', 'level_id', 'recom_id'])->first();
  210. $member->{'team_num'} = MemberClan::from('member_clans as c')
  211. ->leftJoin('members as m', 'm.id', '=', 'c.m_id')
  212. ->where('c.one_m_id', $m_id)
  213. ->count();
  214. return $this->apiResponseSuccess('获取数据成功', $member);
  215. }
  216. /**
  217. * 获取团队列表
  218. * @return \Illuminate\Http\JsonResponse
  219. */
  220. function getTeamList()
  221. {
  222. $type = request()->input('type', '1');
  223. $m_id = request()->member['id'];
  224. $where = [];
  225. if ($type == 1) {
  226. $where[] = ['c.one_m_id', $m_id];
  227. } elseif ($type == 2) {
  228. $where[] = ['c.two_m_id', $m_id];
  229. } else {
  230. $where[] = ['c.one_m_id', '=', $m_id, 'or'];
  231. $where[] = ['c.two_m_id', '=', $m_id, 'or'];
  232. }
  233. $list = MemberClan::from('member_clans as c')
  234. ->leftJoin('members as m', 'm.id', '=', 'c.m_id')
  235. ->where($where)
  236. ->select(['m.id', 'm.address', 'level_id', 'm.created_at'])
  237. ->paginate(15);
  238. return $this->apiResponseSuccess('获取数据成功', ['total_num' => $list->total(), 'items' => $list->items()]);
  239. }
  240. }