User.php 38 KB

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