User.php 38 KB

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