User.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\CoinRate;
  5. use app\common\library\Ems;
  6. use app\common\library\Sms;
  7. use app\common\model\Config;
  8. use think\Db;
  9. use function EasyWeChat\Payment\get_server_ip;
  10. use fast\Random;
  11. use think\Validate;
  12. /**
  13. * 会员接口
  14. */
  15. class User extends Api
  16. {
  17. protected $noNeedLogin = ['login', 'syslogin', 'register', 'findpwd', 'sendMsg', 'mobilelogin', 'resetpwd', 'changeemail', 'changemobile', 'third'];
  18. protected $noNeedRight = '*';
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. }
  23. function syslogin()
  24. {
  25. $id = input('uid');
  26. //直接登录会员
  27. $re = $this->auth->direct($id);
  28. if ($re) {
  29. echo ' <script language="javascript">
  30. window.location.href="/index/index/index";
  31. </script>';
  32. }
  33. }
  34. function sendMsg()
  35. {
  36. if ((time() - session('sendSmsTime')) < 30) {
  37. $this->error('30秒内不能重复发送');
  38. }
  39. $verify=input('verify');
  40. if(empty($verify))
  41. {
  42. $this->error('请输入验证码');
  43. }
  44. if(!captcha_check($verify)){
  45. // 验证失败
  46. $this->error('验证码输入有误');
  47. };
  48. $mobile = input('mobile');
  49. //生成验证码世界名河
  50. $code = randnumber(4);
  51. $content="【轻奢名品汇】你的短信验证码:".$code;
  52. $result=sendmsg($mobile,$content);
  53. if ($result['returnstatus'] == 'Success') {
  54. session('reg_verify', md5($code, $mobile));
  55. session('mobileVerify', $code);
  56. session('sendSmsTime', time());
  57. $this->success('短信已发送成功,请耐心等待~');
  58. } else {
  59. $this->error('发送失败!'.$result['message']);
  60. }
  61. }
  62. /**
  63. * 会员中心
  64. */
  65. public function index()
  66. {
  67. $this->success('', ['welcome' => $this->auth->nickname]);
  68. }
  69. /**
  70. * 会员登录
  71. *
  72. * @param string $account 账号
  73. * @param string $password 密码
  74. */
  75. public function login()
  76. {
  77. $account = $this->request->request('account');
  78. $password = $this->request->request('password');
  79. if (!$account || !$password) {
  80. $this->error(__('Invalid parameters'));
  81. }
  82. $ret = $this->auth->login($account, $password);
  83. if ($ret) {
  84. $data = ['userinfo' => $this->auth->getUserinfo()];
  85. $this->success(__('Logged in successful'), $data);
  86. } else {
  87. $this->error($this->auth->getError());
  88. }
  89. }
  90. /**
  91. * 手机验证码登录
  92. *
  93. * @param string $mobile 手机号
  94. * @param string $captcha 验证码
  95. */
  96. public function mobilelogin()
  97. {
  98. $mobile = $this->request->request('mobile');
  99. $captcha = $this->request->request('captcha');
  100. if (!$mobile || !$captcha) {
  101. $this->error(__('Invalid parameters'));
  102. }
  103. if (!Validate::regex($mobile, "^1\d{10}$")) {
  104. $this->error(__('Mobile is incorrect'));
  105. }
  106. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  107. $this->error(__('Captcha is incorrect'));
  108. }
  109. $user = \app\common\model\User::getByMobile($mobile);
  110. if ($user) {
  111. if ($user->status != 1) {
  112. $this->error(__('Account is locked'));
  113. }
  114. //如果已经有账号则直接登录
  115. $ret = $this->auth->direct($user->id);
  116. } else {
  117. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
  118. }
  119. if ($ret) {
  120. Sms::flush($mobile, 'mobilelogin');
  121. $data = ['userinfo' => $this->auth->getUserinfo()];
  122. $this->success(__('Logged in successful'), $data);
  123. } else {
  124. $this->error($this->auth->getError());
  125. }
  126. }
  127. /* 找回密码 */
  128. function findpwd()
  129. {
  130. $param = $this->request->post();
  131. if (empty($param['mobile'])) {
  132. $this->error(__('请填写手机号'));
  133. }
  134. // if (empty($param['verify'])) {
  135. // $this->error(__('请填写验证码'));
  136. // }
  137. // if($param['verify'] != config('site')['verify_code'])
  138. // {
  139. // if (md5($param['verify'], $param['mobile']) != session('reg_verify')) {
  140. // $this->error(__('验证码输入有误'));
  141. // }
  142. // if ($param['verify'] != session('mobileVerify')) {
  143. // $this->error(__('验证码输入有误'));
  144. // }
  145. // }
  146. $usernameinfo = db('user')->where([ 'mobile' => $param['mobile']])->find();
  147. if (empty($usernameinfo)) {
  148. $this->error(__('请输入的手机号未注册'));
  149. }
  150. $data['password'] = getEncryptPassword($param['password'], $usernameinfo['salt']);
  151. $res = db('user')->where('id', $usernameinfo['id'])->update($data);
  152. if ($res) {
  153. $this->success(__("修改成功"));
  154. } else {
  155. $this->error(__("修改失败"));
  156. }
  157. }
  158. /**
  159. * 注册会员
  160. *
  161. * @param string $username 用户名
  162. * @param string $password 密码
  163. * @param string $email 邮箱
  164. * @param string $mobile 手机号
  165. * @param string $code 验证码
  166. */
  167. function register()
  168. {
  169. $param = $this->request->post();
  170. if (empty($param['mobile'])) {
  171. $this->error(__('请填写手机号'));
  172. }else{
  173. $mob=db('user')->where(['mobile'=>$param['mobile']])->count();
  174. if($mob>0)
  175. {
  176. $this->error('手机号已注册,请更换');
  177. }
  178. }
  179. // if (empty($param['verify'])) {
  180. // $this->error(__('请填写验证码'));
  181. // }
  182. // if($param['verify'] != config('site')['verify_code'])
  183. // {
  184. // if (md5($param['verify'], $param['mobile']) != session('reg_verify')) {
  185. // $this->error(__('验证码输入有误'));
  186. // }
  187. // if ($param['verify'] != session('mobileVerify')) {
  188. // $this->error(__('验证码输入有误'));
  189. // }
  190. // }
  191. $param['username']=str_shuffle(substr(str_shuffle('abcdefghijklmnopqrstuvwxyz1234567890'),0,6));
  192. if (empty($param['username'])) {
  193. $this->error(__('请填写会员账号'));
  194. } else {
  195. $usernameinfo = db('user')->where('username', $param['username'])->find();
  196. if ($usernameinfo) {
  197. $this->error(__('此用户名已注册,请更换'));
  198. }
  199. $reg1='/^[A-Za-z0-9]+$/';
  200. if(!preg_match($reg1,$param['username']))
  201. {
  202. $this->error('账户只能由字母数字组成');
  203. }
  204. if(strlen($param['username'])>8)
  205. {
  206. $this->error('登录账户不能超过8个字符');
  207. }
  208. }
  209. if(empty($param['nickname'])){
  210. $this->error('请填写用户昵称');
  211. }
  212. if(strlen($param['nickname'])<2){
  213. $this->error('昵称至少2个字符');
  214. }
  215. $param['nickname']=$param['nickname']? $param['nickname'] : $param['mobile'];
  216. if (empty($param['password'])) {
  217. $this->error(__('请填写登录密码'));
  218. }
  219. if (empty($param['password2'])) {
  220. $this->error(__('请填写支付密码'));
  221. }
  222. $data = [
  223. 'username' => $param['username'],
  224. 'nickname' => $param['nickname'],
  225. 'email' => '',
  226. 'mobile' => $param['mobile'],
  227. 'level' => 0,
  228. 'salt' => Random::alnum(),
  229. 'createtime' => time(),
  230. 'joinip' => request()->ip(),
  231. 'status' => '1',
  232. ];
  233. $data['password'] = getEncryptPassword($param['password'], $data['salt']);
  234. $data['password2'] = getEncryptPassword($param['password2'], $data['salt']);
  235. $referee = db('user')->where(['username' => $param['referee'], 'status' => 1])->find();
  236. if ($referee) {
  237. $data['refereeid'] = $referee['id'];
  238. $data['referee_name'] = $referee['username'];
  239. $data['refereeids'] = $referee['refereeids']. $referee['id'] . ',' ;
  240. $data['tdeep'] = $referee['tdeep'] + 1;
  241. } else {
  242. $this->error(__('推荐人不可用或输入的推荐编号有误'));
  243. }
  244. $ids = db('user')->insertGetId($data);
  245. if ($ids) {
  246. db('user')->where('id', $data['refereeid'])->setInc('referee_number', 1);
  247. $this->success(__("注册成功"));
  248. } else {
  249. $this->error(__("注册失败"));
  250. }
  251. }
  252. /**
  253. * 注销登录
  254. */
  255. public function logout()
  256. {
  257. $this->auth->logout();
  258. $this->success(__('Logout successful'));
  259. }
  260. function getdetailed()
  261. {
  262. $type = $this->request->post('type');
  263. if ($type == 'all') {
  264. } elseif ($type == 'shop') {
  265. $map['type'] = ['in', '16,17,18'];
  266. } elseif ($type == 'jt') {
  267. $map['type'] = 19;
  268. }
  269. $group = $this->request->post('group');
  270. $map['userid'] = $this->auth->id;
  271. $p = $this->request->post('p');
  272. $data_list = db('detailed' . ucfirst($group))->where($map)->page($p, 15)->order("id desc")->select();
  273. foreach ($data_list as $k => $v) {
  274. $data_list[$k]['money'] = $v['money'] > 0 ? '+' . $v['money'] : $v['money'];
  275. $data_list[$k]['times'] = date("Y-m-d H:i:s", $v['create_time']);
  276. $data_list[$k]['type'] = __(get_detailed_type_text($v['type']));
  277. }
  278. if ($data_list) {
  279. $return['data'] = $data_list;
  280. } else {
  281. $return['data'] = null;
  282. }
  283. $count = db('detailed' . ucfirst($group))->where($map)->count();
  284. $return['total'] = ceil($count / 15);
  285. return $return;
  286. }
  287. function getdetailed2()
  288. {
  289. $type = $this->request->post('type');
  290. if ($type) {
  291. $map['type'] = $type;
  292. }
  293. $group = $this->request->post('group');
  294. $map['userid'] = $this->auth->id;
  295. $p = $this->request->post('p');
  296. $data_list = db('detailed' . ucfirst($group))->where($map)->page($p, 10)->order("id desc")->select();
  297. foreach ($data_list as $k => $v) {
  298. $data_list[$k]['money'] = $v['money'] > 0 ? '+' . $v['money'] : $v['money'];
  299. $data_list[$k]['times'] = date("Y-m-d H:i:s", $v['create_time']);
  300. $data_list[$k]['type'] = __(get_detailed_type_text($v['type']));
  301. }
  302. if ($data_list) {
  303. $return['data'] = $data_list;
  304. } else {
  305. $return['data'] = null;
  306. }
  307. $count = db('detailed' . ucfirst($group))->where($map)->count();
  308. $return['total'] = ceil($count / 10);
  309. return $return;
  310. }
  311. /* 记录 */
  312. function teamwithdrawdetaile()
  313. {
  314. $stuid=get_user_data($this->auth->id,'stuid');
  315. $map['stuid'] = $stuid;
  316. $p = $this->request->post('p');
  317. $map['money_type'] = $this->request->post('money_type');
  318. $data_list = db('withdrawals')->where($map)->page($p, 10)->order("id desc")->select();
  319. foreach ($data_list as $k => $v) {
  320. $data_list[$k]['times'] = date("Y-m-d H:i", $v['withdraw_date']);
  321. $data_list[$k]['click'] = 'onclick="review(\'' . $v['remark'] . '\')"';
  322. $data_list[$k]['payment'] = $v['name'].' '.($v['prc']? '<img src="'.$v['prc'].'" style="width: 80px;height: 80px;">' : '');
  323. }
  324. if ($data_list) {
  325. $return['data'] = $data_list;
  326. } else {
  327. $return['data'] = null;
  328. }
  329. $count = db('withdrawals')->where($map)->count();
  330. $return['total'] = ceil($count / 10);
  331. return $return;
  332. }
  333. function toviewwithdraw()
  334. {
  335. $ids = $this->request->post('id');
  336. $type=$this->request->post('type');
  337. $info=db('withdrawals')->where(['id'=>$ids,'process_status'=>1])->find();
  338. if(!$info)
  339. {
  340. $this->error("信息不存在,或已审核");
  341. }
  342. if($type == 1)
  343. {
  344. $res=db('withdrawals')->where(array('id'=>$ids))->update(['process_status'=>2,'confirm_date'=>time()]);
  345. if($res)
  346. {
  347. $this->success('审核完成');
  348. }else{
  349. $this->error('审核失败');
  350. }
  351. }else{
  352. db()->startTrans();
  353. $res1=$this->model->where('id',$ids)->update(['process_status'=>-1,'confirm_date'=>time()]);
  354. $changedata=[
  355. 'type'=>5,
  356. 'money'=>$info['amount'],
  357. 'userid'=>$info['userid'],
  358. 'relevant_userid'=>-1,
  359. 'remark'=>'拒绝提现返还',
  360. ];
  361. $res=caiwu($changedata, $info['money_type']);
  362. if($res && $res1)
  363. {
  364. db()->commit();
  365. $this->success('审核完成');
  366. }else{
  367. db()->rollback();
  368. $this->error('审核失败');
  369. }
  370. }
  371. }
  372. /* 提现记录 */
  373. function withdrawdetaile()
  374. {
  375. $map['userid'] = $this->auth->id;
  376. $p = $this->request->post('p');
  377. $map['money_type'] = $this->request->post('money_type');
  378. $data_list = db('withdrawals')->where($map)->page($p, 10)->order("id desc")->select();
  379. foreach ($data_list as $k => $v) {
  380. $data_list[$k]['times'] = date("Y-m-d H:i", $v['withdraw_date']);
  381. $data_list[$k]['click'] = 'onclick="review(\'' . $v['remark'] . '\')"';
  382. }
  383. if ($data_list) {
  384. $return['data'] = $data_list;
  385. } else {
  386. $return['data'] = null;
  387. }
  388. $count = db('withdrawals')->where($map)->count();
  389. $return['total'] = ceil($count / 10);
  390. return $return;
  391. }
  392. /* 释放记录 */
  393. function releaselog()
  394. {
  395. $map['a.userid'] = $this->auth->id;
  396. $p = $this->request->post('p');
  397. if($this->request->post('type')){
  398. $map['a.type'] = $this->request->post('type');
  399. }
  400. $config = Config::getConfigByGroup('trade');
  401. $releaseRate = isset($config['release_rate'])? floatval($config['release_rate']['value']) : 0;
  402. $speedRate = isset($config['speed_rate'])? floatval($config['speed_rate']['value']) : 0;
  403. $data_list = db('release_log')->alias('a')
  404. ->join('trade t','t.id=a.orderid','left')
  405. ->where($map)
  406. ->field('a.*,t.release_total_usdt')
  407. ->page($p, 10)
  408. ->order("a.id desc")
  409. ->select();
  410. foreach ($data_list as $k => $v) {
  411. $data_list[$k]['times'] = date("Y-m-d H:i", $v['create_time']);
  412. $data_list[$k]['click'] = 'onclick="review(\'' . $v['remark'] . '\')"';
  413. $data_list[$k]['release_rate'] = $releaseRate;
  414. $data_list[$k]['speed_rate'] = $speedRate;
  415. }
  416. if ($data_list) {
  417. $return['data'] = $data_list;
  418. } else {
  419. $return['data'] = null;
  420. }
  421. $count = db('release_log')->alias('a')->where($map)->count();
  422. $return['total'] = ceil($count / 10);
  423. return $return;
  424. }
  425. /**
  426. * 修改邮箱
  427. *
  428. * @param string $email 邮箱
  429. * @param string $captcha 验证码
  430. */
  431. public function changeemail()
  432. {
  433. $user = $this->auth->getUser();
  434. $email = $this->request->post('email');
  435. $captcha = $this->request->request('captcha');
  436. if (!$email || !$captcha) {
  437. $this->error(__('Invalid parameters'));
  438. }
  439. if (!Validate::is($email, "email")) {
  440. $this->error(__('Email is incorrect'));
  441. }
  442. if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
  443. $this->error(__('Email already exists'));
  444. }
  445. $result = Ems::check($email, $captcha, 'changeemail');
  446. if (!$result) {
  447. $this->error(__('Captcha is incorrect'));
  448. }
  449. $verification = $user->verification;
  450. $verification->email = 1;
  451. $user->verification = $verification;
  452. $user->email = $email;
  453. $user->save();
  454. Ems::flush($email, 'changeemail');
  455. $this->success();
  456. }
  457. /**
  458. * 修改手机号
  459. *
  460. * @param string $email 手机号
  461. * @param string $captcha 验证码
  462. */
  463. public function changemobile()
  464. {
  465. $user = $this->auth->getUser();
  466. $mobile = $this->request->request('mobile');
  467. $captcha = $this->request->request('captcha');
  468. if (!$mobile || !$captcha) {
  469. $this->error(__('Invalid parameters'));
  470. }
  471. if (!Validate::regex($mobile, "^1\d{10}$")) {
  472. $this->error(__('Mobile is incorrect'));
  473. }
  474. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  475. $this->error(__('Mobile already exists'));
  476. }
  477. $result = Sms::check($mobile, $captcha, 'changemobile');
  478. if (!$result) {
  479. $this->error(__('Captcha is incorrect'));
  480. }
  481. $verification = $user->verification;
  482. $verification->mobile = 1;
  483. $user->verification = $verification;
  484. $user->mobile = $mobile;
  485. $user->save();
  486. Sms::flush($mobile, 'changemobile');
  487. $this->success();
  488. }
  489. /**
  490. * 第三方登录
  491. *
  492. * @param string $platform 平台名称
  493. * @param string $code Code码
  494. */
  495. public function third()
  496. {
  497. $url = url('user/index');
  498. $platform = $this->request->request("platform");
  499. $code = $this->request->request("code");
  500. $config = get_addon_config('third');
  501. if (!$config || !isset($config[$platform])) {
  502. $this->error(__('Invalid parameters'));
  503. }
  504. $app = new \addons\third\library\Application($config);
  505. //通过code换access_token和绑定会员
  506. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  507. if ($result) {
  508. $loginret = \addons\third\library\Service::connect($platform, $result);
  509. if ($loginret) {
  510. $data = [
  511. 'userinfo' => $this->auth->getUserinfo(),
  512. 'thirdinfo' => $result
  513. ];
  514. $this->success(__('Logged in successful'), $data);
  515. }
  516. }
  517. $this->error(__('Operation failed'), $url);
  518. }
  519. /**
  520. * 重置密码
  521. *
  522. * @param string $mobile 手机号
  523. * @param string $newpassword 新密码
  524. * @param string $captcha 验证码
  525. */
  526. public function resetpwd()
  527. {
  528. $type = $this->request->request("type");
  529. $mobile = $this->request->request("mobile");
  530. $email = $this->request->request("email");
  531. $newpassword = $this->request->request("newpassword");
  532. $captcha = $this->request->request("captcha");
  533. if (!$newpassword || !$captcha) {
  534. $this->error(__('Invalid parameters'));
  535. }
  536. if ($type == 'mobile') {
  537. if (!Validate::regex($mobile, "^1\d{10}$")) {
  538. $this->error(__('Mobile is incorrect'));
  539. }
  540. $user = \app\common\model\User::getByMobile($mobile);
  541. if (!$user) {
  542. $this->error(__('User not found'));
  543. }
  544. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  545. if (!$ret) {
  546. $this->error(__('Captcha is incorrect'));
  547. }
  548. Sms::flush($mobile, 'resetpwd');
  549. } else {
  550. if (!Validate::is($email, "email")) {
  551. $this->error(__('Email is incorrect'));
  552. }
  553. $user = \app\common\model\User::getByEmail($email);
  554. if (!$user) {
  555. $this->error(__('User not found'));
  556. }
  557. $ret = Ems::check($email, $captcha, 'resetpwd');
  558. if (!$ret) {
  559. $this->error(__('Captcha is incorrect'));
  560. }
  561. Ems::flush($email, 'resetpwd');
  562. }
  563. //模拟一次登录
  564. $this->auth->direct($user->id);
  565. $ret = $this->auth->changepwd($newpassword, '', true);
  566. if ($ret) {
  567. $this->success(__('Reset password successful'));
  568. } else {
  569. $this->error($this->auth->getError());
  570. }
  571. }
  572. /*充值 */
  573. function torecharge()
  574. {
  575. $param = $this->request->post();
  576. if (empty($param['money'])) {
  577. $this->error("请输入充值金额");
  578. }
  579. if (empty($param['icon'])) {
  580. $this->error("请上传打款凭证");
  581. }
  582. if (empty($param['paytype'])) {
  583. $this->error("请选择支付类型");
  584. }
  585. $user = db('user')->where('id', $param['userid'])->find();
  586. $param['username'] = $user['username'];
  587. $param['ctime'] = time();
  588. $ids = db('recharge')->insertGetId($param);
  589. if ($ids) {
  590. $this->success("申请成功,请耐心等待审核");
  591. } else {
  592. $this->error("申请失败");
  593. }
  594. }
  595. /* 充值记录 */
  596. function getrechargedata()
  597. {
  598. $map['userid'] = $this->auth->id;
  599. $p = $this->request->post('p');
  600. $data_list = db('recharge')->where($map)->page($p, 10)->select();
  601. foreach ($data_list as $k => $v) {
  602. $data_list[$k]['status'] = get_recharge_status($v['status']);
  603. $data_list[$k]['times'] = date("Y-m-d H:i:s", $v['ctime']);
  604. $data_list[$k]['moneytype'] = get_money_name_byident($v['money_type']);
  605. }
  606. if ($data_list) {
  607. $return['data'] = $data_list;
  608. } else {
  609. $return['data'] = null;
  610. }
  611. $count = db('recharge')->where($map)->count();
  612. $return['total'] = ceil($count / 10);
  613. return $return;
  614. }
  615. function getnotice()
  616. {
  617. $map['status'] = 1;
  618. $map['type'] = $this->request->langset();
  619. $p = $this->request->post('p');
  620. $data_list = db('article')->where($map)->page($p, 10)->select();
  621. foreach ($data_list as $k => $v) {
  622. $data_list[$k]['times'] = date("Y-m-d", $v['ctime']);
  623. $data_list[$k]['url'] = "'" . url('index/user/newdetail', ['id' => $v['id']]) . "'";
  624. }
  625. if ($data_list) {
  626. $return['data'] = $data_list;
  627. } else {
  628. $return['data'] = null;
  629. }
  630. $count = db('article')->where($map)->count();
  631. $return['total'] = ceil($count / 10);
  632. return $return;
  633. }
  634. function getbonus2()
  635. {
  636. $map['userid'] = $this->auth->id;
  637. $p = $this->request->post('p');
  638. $data_list = db('user_bonus2')->where($map)->page($p, 10)->select();
  639. foreach ($data_list as $k => $v) {
  640. $data_list[$k]['times'] = date("Y.m.d H:i", $v['ctime']);
  641. if ($v['status'] == 1) {
  642. $data_list[$k]['status_dec'] = '锁仓中';
  643. $data_list[$k]['flag'] = 0;
  644. } else {
  645. $data_list[$k]['status_dec'] = '已解锁';
  646. $data_list[$k]['flag'] = 1;
  647. }
  648. }
  649. if ($data_list) {
  650. $return['data'] = $data_list;
  651. } else {
  652. $return['data'] = null;
  653. }
  654. $count = db('user_bonus2')->where($map)->count();
  655. $return['total'] = ceil($count / 10);
  656. return $return;
  657. }
  658. function getchat()
  659. {
  660. $user = $this->auth->getUserinfo();
  661. $map['from_uid|to_uid'] = $user['id'];
  662. $p = $this->request->post('p');
  663. $myset = config('site');
  664. $data_list = db('user_message')->where($map)->page($p, 10)->order("id asc")->select();
  665. foreach ($data_list as $k => $v) {
  666. if ($v['from_uid'] == $user['id']) {
  667. $data_list[$k]['flag'] = 0;
  668. $data_list[$k]['from_avatar'] = $user['avatar'];
  669. } else {
  670. $data_list[$k]['flag'] = 1;
  671. $data_list[$k]['from_avatar'] = $myset['web_site_logo'];
  672. }
  673. }
  674. $count = db('user_message')->where($map)->count();
  675. $total = ceil($count / 10);
  676. $return['total'] = $total;
  677. if ($data_list) {
  678. if ($p == $total) {
  679. $return['data'] = $data_list;
  680. } else {
  681. rsort($data_list);
  682. $return['data'] = $data_list;
  683. }
  684. } else {
  685. $return['data'] = null;
  686. }
  687. return $return;
  688. }
  689. /*发送留言 */
  690. function tosendmsg()
  691. {
  692. $param = $this->request->post();
  693. if (empty($param['content'])) {
  694. $this->error(__("请输入留言"));
  695. }
  696. $param['from_uid'] = $this->auth->id;
  697. $param['to_uid'] = 0;
  698. $param['ctime'] = time();
  699. $param['userid'] = $this->auth->id;
  700. $ids = db('user_message')->insertGetId($param);
  701. if ($ids) {
  702. $this->success(__("留言成功"));
  703. } else {
  704. $this->error(__("留言失败"));
  705. }
  706. }
  707. /* 修改密码 */
  708. function updatepwd()
  709. {
  710. $param = $this->request->post();
  711. if (empty($param['newPwd'])) {
  712. $this->error(__("请输入新密码"));
  713. }
  714. $user = get_user_data($this->auth->id);
  715. if ($param['type'] == 1) {
  716. $data['updatetime'] = time();
  717. $data['password'] = getEncryptPassword($param['newPwd'], $user['salt']);
  718. $res = db('user')->where('id', $user['id'])->update($data);
  719. if ($res) {
  720. $this->success(__("修改成功"));
  721. } else {
  722. $this->error(__("修改失败"));
  723. }
  724. } else {
  725. $data['updatetime'] = time();
  726. $data['password2'] = getEncryptPassword($param['newPwd'], $user['salt']);
  727. $res = db('user')->where('id', $user['id'])->update($data);
  728. if ($res) {
  729. $this->success(__("修改成功"));
  730. } else {
  731. $this->error(__("修改失败"));
  732. }
  733. }
  734. }
  735. function withdraw()
  736. {
  737. $param = $this->request->post();
  738. $psdtwo = $param['psdtwo'];
  739. if (empty($psdtwo)) {
  740. $this->error(__('请输入支付密码'));
  741. }
  742. if (!check_psdtwo($psdtwo, $this->auth->id)) {
  743. $this->error(__('支付密码验证失败!'));
  744. }
  745. //$config = db('bonus_config')->where('id', 6)->find();
  746. $tradeConfig = Config::getConfigByGroup('trade');
  747. $config['withdraw_min'] = isset($tradeConfig['withdraw_min'])? $tradeConfig['withdraw_min']['value'] : 0;
  748. $config['withdraw_cap'] = isset($tradeConfig['withdraw_cap'])? $tradeConfig['withdraw_cap']['value'] : 0;
  749. $config['withdraw_fee'] = isset($tradeConfig['withdraw_fee'])? $tradeConfig['withdraw_fee']['value'] : 0;
  750. if (empty($param['money'])) {
  751. $this->error(__('请输入提现金额!'));
  752. }
  753. if (!($param['money'] > 0)) {
  754. $this->error(__('提现金额有误'));
  755. }
  756. if (!is_numeric($param['money'])) {
  757. $this->error(__('提现金额有误'));
  758. }
  759. if ($param['money'] < $config['withdraw_min']) {
  760. $this->error(__('提现金额最低为'.$config['withdraw_min']));
  761. }
  762. if ($config['withdraw_cap'] && $param['money'] % $config['withdraw_cap'] != 0) {
  763. $this->error(__('提现金额应为'.$config['withdraw_cap'].'的倍数'));
  764. }
  765. if (empty($param['type'])) {
  766. $this->error(__('请选择提现方式'));
  767. }
  768. $user = get_user_data($this->auth->id);
  769. $JC = $param['money'] - $user['usdt'];
  770. if ($JC > 0) {
  771. $this->error("余额不足");
  772. }
  773. if($param['type'] == 1)
  774. {
  775. if(empty($user['alipayprc']))
  776. {
  777. $this->error('请完善支付宝收款信息');
  778. }
  779. $prc=$user['alipayprc'];
  780. $name='';
  781. $type="支付宝";
  782. }elseif($param['type'] == 2){
  783. if(empty($user['wxprc']))
  784. {
  785. $this->error('请完善微信收款信息');
  786. }
  787. $prc=$user['wxprc'];
  788. $name='';
  789. $type="微信";
  790. }else if($param['type'] == 3){
  791. if(!($user['bank'] && $user['bank_user_name'] && $user['bank_number']))
  792. {
  793. $this->error('请完善y银行卡收款信息');
  794. }
  795. $prc='';
  796. $name=$user['bank'].'-'.$user['bank_user_name'].'-'.$user['bank_number'];
  797. $type="银行卡";
  798. }else {
  799. if(empty($user['usdt_address']))
  800. {
  801. $this->error('请先完善USDT钱包地址信息');
  802. }
  803. $prc='';
  804. $name='';
  805. $type="USDT";
  806. }
  807. $studio=db('studio')->where(['title'=>$this->auth->login_studio])->find();
  808. $fee=$param['money']*$config['withdraw_fee']*0.01;
  809. db()->startTrans();
  810. $res = db('user')->where("id",$this->auth->id)->update(['usdt'=> $user['usdt']-$param['money'],'updatetime'=>time()]);
  811. // 流水明细
  812. $changedata=[
  813. 'userid'=>$this->auth->id,
  814. 'type'=> 6,
  815. 'money'=> -$param['money'],
  816. 'balance'=> $user['usdt'],
  817. 'relevant_userid'=>$this->auth->id,
  818. 'status'=>1,
  819. 'create_time'=>time(),
  820. 'remark'=>'提现扣除',
  821. 'user_name'=>$user['username']? $user['username'] : '系统',
  822. 'relevant_name'=>$user['username']? $user['username'] : '系统',
  823. ];
  824. $res1 = Db::name('detailed_usdt')->insertGetId($changedata);
  825. $data = [
  826. 'withdraw_date' => time(),
  827. 'amount' => $param['money'],
  828. 'usdt_num' => $param['money'],
  829. 'fack_receive' => $param['money']-$fee,
  830. 'fee' => $fee,
  831. 'userid' => $this->auth->id,
  832. 'username' => $user['username'],
  833. 'prc' => $prc,
  834. 'usdt_address' => isset($user['usdt_address']) && $param['type'] == 4? $user['usdt_address'] : '',
  835. 'name'=>$name,
  836. 'process_status' => 1,
  837. 'money_type' => 'usdt',
  838. 'type'=>$type,
  839. 'stuid'=>$studio['id'],
  840. ];
  841. $ids = db('withdrawals')->insertGetId($data);
  842. if ($res && $res1 && $ids) {
  843. db()->commit();
  844. $this->success(__("提现成功"));
  845. } else {
  846. db()->rollback();
  847. $this->error(__("提现失败"));
  848. }
  849. }
  850. /**
  851. * 佣金提现
  852. * @throws \think\db\exception\DataNotFoundException
  853. * @throws \think\db\exception\ModelNotFoundException
  854. * @throws \think\exception\DbException
  855. * @throws \think\exception\PDOException
  856. */
  857. function withdraw1()
  858. {
  859. $param = $this->request->post();
  860. $psdtwo = $param['psdtwo'];
  861. if (empty($psdtwo)) {
  862. $this->error(__('请输入支付密码'));
  863. }
  864. if (!check_psdtwo($psdtwo, $this->auth->id)) {
  865. $this->error(__('支付密码验证失败!'));
  866. }
  867. //$config = db('bonus_config')->where('id', 6)->find();
  868. $tradeConfig = Config::getConfigByGroup('trade');
  869. $config['withdraw_min'] = isset($tradeConfig['withdraw_min'])? $tradeConfig['withdraw_min']['value'] : 0;
  870. $config['withdraw_cap'] = isset($tradeConfig['withdraw_cap'])? $tradeConfig['withdraw_cap']['value'] : 0;
  871. $config['withdraw_fee'] = isset($tradeConfig['withdraw_bonus_fee'])? $tradeConfig['withdraw_bonus_fee']['value'] : 0;
  872. if (empty($param['money'])) {
  873. $this->error(__('请输入提现金额!'));
  874. }
  875. if (!($param['money'] > 0)) {
  876. $this->error(__('提现金额有误'));
  877. }
  878. if (!is_numeric($param['money'])) {
  879. $this->error(__('提现金额有误'));
  880. }
  881. if ($param['money'] < $config['withdraw_min']) {
  882. $this->error(__('提现金额最低为'.$config['withdraw_min']));
  883. }
  884. if ($config['withdraw_cap'] && $param['money'] % $config['withdraw_cap'] != 0) {
  885. $this->error(__('提现金额应为'.$config['withdraw_cap'].'的倍数'));
  886. }
  887. if (empty($param['type'])) {
  888. $this->error(__('请选择提现方式'));
  889. }
  890. $user = get_user_data($this->auth->id);
  891. $JC = $param['money'] - $user['bonus'];
  892. if ($JC > 0) {
  893. $this->error("佣金余额不足");
  894. }
  895. if($param['type'] == 1)
  896. {
  897. if(empty($user['alipayprc']))
  898. {
  899. $this->error('请完善支付宝收款信息');
  900. }
  901. $prc=$user['alipayprc'];
  902. $name= $user['alipay_name'].'-'.$user['alipayname'];
  903. $type="支付宝";
  904. }elseif($param['type'] == 2){
  905. if(empty($user['wxprc']))
  906. {
  907. $this->error('请完善微信收款信息');
  908. }
  909. $prc=$user['wxprc'];
  910. $name='';
  911. $type="微信";
  912. }else if($param['type'] == 3){
  913. if(!($user['bank'] && $user['bank_user_name'] && $user['bank_number']))
  914. {
  915. $this->error('请完善y银行卡收款信息');
  916. }
  917. $prc='';
  918. $name=$user['bank'].'-'.$user['bank_user_name'].'-'.$user['bank_number'];
  919. $type="银行卡";
  920. }
  921. $studio=db('studio')->where(['title'=>$this->auth->login_studio])->find();
  922. $fee=$param['money']*$config['withdraw_fee']*0.01;
  923. db()->startTrans();
  924. $changedata=[
  925. 'type'=>6,
  926. 'money'=>0-$param['money'],
  927. 'userid'=>$this->auth->id,
  928. 'relevant_userid'=>$this->auth->id,
  929. 'remark'=>'佣金提现扣除',
  930. ];
  931. $res=caiwu($changedata, 'bonus');
  932. $data = [
  933. 'withdraw_date' => time(),
  934. 'amount' => $param['money'],
  935. 'usdt_num' => $param['money'],
  936. 'fack_receive' => $param['money']-$fee,
  937. 'fee' => $fee,
  938. 'userid' => $this->auth->id,
  939. 'username' => $user['username'],
  940. 'prc' => $prc,
  941. 'name'=>$name,
  942. 'process_status' => 1,
  943. 'money_type' => 'bonus',
  944. 'type'=>$type,
  945. 'stuid'=>$studio['id'],
  946. ];
  947. $ids = db('withdrawals')->insertGetId($data);
  948. if ($res && $ids) {
  949. db()->commit();
  950. $this->success(__("提现成功"));
  951. } else {
  952. db()->rollback();
  953. $this->error(__("提现失败"));
  954. }
  955. }
  956. function toupdateuserinfo()
  957. {
  958. $param = $this->request->post();
  959. $userid = $this->auth->id;
  960. $res = db('user')->where("id", $userid)->update($param);
  961. if ($res) {
  962. $this->success(__("上传完成"));
  963. } else {
  964. $this->error(__("上传失败"));
  965. }
  966. }
  967. function getroselist1()
  968. {
  969. $map['pid'] = $this->auth->id;
  970. $p = $this->request->post('p');
  971. $type = $this->request->post('type');
  972. if($type)
  973. {
  974. $map['status']=$type;
  975. }
  976. $data_list = db('rose')->where($map)->page($p, 15)->select();
  977. foreach ($data_list as &$v) {
  978. $v['times'] = date("Y/m/d H:i:s", $v['ctime']);
  979. $v['phone']=substr($v['mobile'],0,3).'****'.substr($v['mobile'],-4);
  980. }
  981. if ($data_list) {
  982. $return['data'] = $data_list;
  983. } else {
  984. $return['data'] = null;
  985. }
  986. $count = db('rose')->where($map)->count();
  987. $return['total'] = ceil($count / 15);
  988. return $return;
  989. }
  990. function getroselist()
  991. {
  992. $map['pid'] = $this->auth->id;
  993. $p = $this->request->post('p');
  994. $type = $this->request->post('type');
  995. if($type)
  996. {
  997. $map['status']=$type;
  998. }
  999. $data_list = db('rose')->where($map)->page($p, 10)->select();
  1000. foreach ($data_list as &$v) {
  1001. $v['times'] = date("Y/m/d H:i:s", $v['ctime']);
  1002. $v['phone']=substr($v['mobile'],0,3).'****'.substr($v['mobile'],-4);
  1003. }
  1004. if ($data_list) {
  1005. $return['data'] = $data_list;
  1006. } else {
  1007. $return['data'] = null;
  1008. }
  1009. $count = db('rose')->where($map)->count();
  1010. $return['total'] = ceil($count / 10);
  1011. return $return;
  1012. }
  1013. function updatename()
  1014. {
  1015. $param=$this->request->post();
  1016. $userid = $this->auth->id;
  1017. $res=db('user')->where("id",$userid)->update(['nickname'=>$param['nickname']]);
  1018. if($res)
  1019. {
  1020. $this->success(__("修改完成"));
  1021. }else{
  1022. $this->error(__("修改失败"));
  1023. }
  1024. }
  1025. function profile()
  1026. {
  1027. $param = $this->request->post();
  1028. $check = (($param['bank'] && $param['bank_user_name'] && $param['bank_number']) || ($param['alipayprc'] && $param['alipay_name'] && $param['alipayname']) || ($param['wxprc']) || ($param['usdt_address']) || ($param['thb_bank_user_name'] && $param['thb_bank'] && ($param['thb_bank_number'] || $param['thb_qrcode'])) || ($param['idr_bank_user_name'] && $param['idr_bank'] && ($param['idr_bank_number'] || $param['idr_qrcode'])));
  1029. if(!$check)
  1030. {
  1031. $this->error('请至少完整填写一项收款信息');
  1032. }
  1033. $intime=get_user_data($this->auth->id,'intime');
  1034. $userid = $this->auth->id;
  1035. $param['isuser']=1;
  1036. $param['updatetime']=time();
  1037. if($intime>0)
  1038. {
  1039. $param['intime']=time();
  1040. }
  1041. $res=db('user')->where("id",$userid)->update($param);
  1042. if($res)
  1043. {
  1044. $this->success(__("修改完成"));
  1045. }else{
  1046. $this->error(__("修改失败"));
  1047. }
  1048. }
  1049. function toreal()
  1050. {
  1051. $param = $this->request->post();
  1052. $user=db('user')->where(['id'=> $this->auth->id])->find();
  1053. if($user['isreal']>0)
  1054. {
  1055. $this->error('您已实名或者实名审核中,不可重复操作');
  1056. }
  1057. if(!($param['idcard'] && $param['realname'] && $param['idprc1'] && $param['idprc2']))
  1058. {
  1059. $this->error('请完善实名资料');
  1060. }
  1061. $idcardinfo=db('user')->where(['idcard'=>$param['idcard'],'id'=>['neq',$this->auth->id]])->find();
  1062. if($idcardinfo)
  1063. {
  1064. $this->error('一个身份号只能绑定一个账号');
  1065. }
  1066. $param['isreal']=1;
  1067. $userid = $this->auth->id;
  1068. $res=db('user')->where("id",$userid)->update($param);
  1069. if($res)
  1070. {
  1071. $this->success(__("认证完成"));
  1072. }else{
  1073. $this->error(__("认证失败"));
  1074. }
  1075. }
  1076. function totrans()
  1077. {
  1078. $param=$this->request->post();
  1079. $from_moneytyp='cash';
  1080. $to_moneytype='bonus';
  1081. $psdtwo = $param['psdtwo'];
  1082. if(empty($psdtwo))
  1083. {
  1084. $this->error(__('请输入支付密码!'));
  1085. }
  1086. if(!check_psdtwo($psdtwo,$this->auth->id)){
  1087. $this->error(__('支付密码验证失败!'));
  1088. }
  1089. if(empty($param['money']))
  1090. {
  1091. $this->error(__('请输入提取金额'));
  1092. }
  1093. if(!($param['money']>0))
  1094. {
  1095. $this->error(__('提取金额有误'));
  1096. }
  1097. if(!is_numeric($param['money']))
  1098. {
  1099. $this->error(__('提取金额有误'));
  1100. }
  1101. $user=get_user_data($this->auth->id);
  1102. $jc=$param['money']-$user[$from_moneytyp];
  1103. if($jc>0)
  1104. {
  1105. $this->error(get_money_name_byident($from_moneytyp).'不足');
  1106. }
  1107. db()->startTrans();
  1108. $changedata=[
  1109. 'type'=>10,
  1110. 'money'=>0-$param['money'],
  1111. 'userid'=>$this->auth->id,
  1112. 'relevant_userid'=>$this->auth->id,
  1113. 'remark'=>'提取扣除'.$param['money'],
  1114. ];
  1115. $res=caiwu($changedata, $from_moneytyp);
  1116. $changedata=[
  1117. 'type'=>10,
  1118. 'money'=>$param['money'],
  1119. 'userid'=>$this->auth->id,
  1120. 'relevant_userid'=>$this->auth->id,
  1121. 'remark'=>'提取增加'.$param['money'],
  1122. ];
  1123. $res1=caiwu($changedata,$to_moneytype);
  1124. if($res && $res1)
  1125. {
  1126. db()->commit();
  1127. $this->success(__("提取成功"));
  1128. }else{
  1129. db()->rollback();
  1130. $this->error(__("提取失败"));
  1131. }
  1132. }
  1133. /* 转账 */
  1134. function transfer()
  1135. {
  1136. $param=$this->request->post();
  1137. $psdtwo = $param['psdtwo'];
  1138. if(empty($psdtwo))
  1139. {
  1140. $this->error(__('请输入安全密码!'));
  1141. }
  1142. if(!check_psdtwo($psdtwo,$this->auth->id)){
  1143. $this->error(__('安全密码验证失败!'));
  1144. }
  1145. if(empty($param['money']))
  1146. {
  1147. $this->error(__('请输入转账数量'));
  1148. }
  1149. if(!($param['money']>0))
  1150. {
  1151. $this->error(__('转账数量有误'));
  1152. }
  1153. if(!is_numeric($param['money']))
  1154. {
  1155. $this->error(__('转账数量有误'));
  1156. }
  1157. $user=get_user_data($this->auth->id);
  1158. $jc=$param['money']-$user['bonus'];
  1159. if($jc>0)
  1160. {
  1161. $this->error(__('平台币不足'));
  1162. }
  1163. $touser=db('user')->where(['username|mobile'=>$param['touser'],'status'=>1])->find();
  1164. if(empty($touser))
  1165. {
  1166. $this->error(__("接收会员不存在"));
  1167. }
  1168. if(!in_array($this->auth->id,explode(',',$touser['refereeids'])) && !in_array($touser['id'],explode(',',$user['refereeids'])) )
  1169. {
  1170. $this->error(__("与目标用户存在推荐关系方可转出"));
  1171. }
  1172. db()->startTrans();
  1173. $changedata=[
  1174. 'type'=>8,
  1175. 'money'=>0-$param['money'],
  1176. 'userid'=>$this->auth->id,
  1177. 'relevant_userid'=>$touser['id'],
  1178. 'remark'=>'转账给'.$touser['username'],
  1179. ];
  1180. $res=caiwu($changedata, 'bonus');
  1181. $changedata=[
  1182. 'type'=>7,
  1183. 'money'=>$param['money'],
  1184. 'userid'=>$touser['id'],
  1185. 'relevant_userid'=>$this->auth->id,
  1186. 'remark'=>'接收'.$user['username'].'转账',
  1187. ];
  1188. $res1=caiwu($changedata, 'bonus');
  1189. if($res && $res1)
  1190. {
  1191. db()->commit();
  1192. $this->success(__("转账成功"));
  1193. }else{
  1194. db()->rollback();
  1195. $this->error(__("转账失败"));
  1196. }
  1197. }
  1198. function gettranscode()
  1199. {
  1200. $group = $this->request->post('money_type');
  1201. $map['userid'] = $this->auth->id;
  1202. $map['type']=8;
  1203. $p = $this->request->post('p');
  1204. $data_list = db('detailed' . ucfirst($group))->where($map)->page($p, 15)->order("id desc")->select();
  1205. foreach ($data_list as $k => $v) {
  1206. $data_list[$k]['money'] = $v['money'] > 0 ? '+' . $v['money'] : $v['money'];
  1207. $data_list[$k]['times'] = date("Y-m-d H:i:s", $v['create_time']);
  1208. $data_list[$k]['type'] = get_detailed_type_text($v['type']);
  1209. }
  1210. if ($data_list) {
  1211. $return['data'] = $data_list;
  1212. } else {
  1213. $return['data'] = null;
  1214. }
  1215. $count = db('detailed' . ucfirst($group))->where($map)->count();
  1216. $return['total'] = ceil($count / 15);
  1217. return $return;
  1218. }
  1219. }