User.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  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_address' => isset($user['usdt_address']) && $param['type'] == 4? $user['usdt_address'] : '',
  808. 'name'=>$name,
  809. 'process_status' => 1,
  810. 'money_type' => 'bonus',
  811. 'type'=>$type,
  812. 'stuid'=>$studio['id'],
  813. ];
  814. $ids = db('withdrawals')->insertGetId($data);
  815. if ($res && $ids) {
  816. db()->commit();
  817. $this->success(__("提现成功"));
  818. } else {
  819. db()->rollback();
  820. $this->error(__("提现失败"));
  821. }
  822. }
  823. function toupdateuserinfo()
  824. {
  825. $param = $this->request->post();
  826. $userid = $this->auth->id;
  827. $res = db('user')->where("id", $userid)->update($param);
  828. if ($res) {
  829. $this->success(__("上传完成"));
  830. } else {
  831. $this->error(__("上传失败"));
  832. }
  833. }
  834. function getroselist1()
  835. {
  836. $map['pid'] = $this->auth->id;
  837. $p = $this->request->post('p');
  838. $type = $this->request->post('type');
  839. if($type)
  840. {
  841. $map['status']=$type;
  842. }
  843. $data_list = db('rose')->where($map)->page($p, 15)->select();
  844. foreach ($data_list as &$v) {
  845. $v['times'] = date("Y/m/d H:i:s", $v['ctime']);
  846. $v['phone']=substr($v['mobile'],0,3).'****'.substr($v['mobile'],-4);
  847. }
  848. if ($data_list) {
  849. $return['data'] = $data_list;
  850. } else {
  851. $return['data'] = null;
  852. }
  853. $count = db('rose')->where($map)->count();
  854. $return['total'] = ceil($count / 15);
  855. return $return;
  856. }
  857. function getroselist()
  858. {
  859. $map['pid'] = $this->auth->id;
  860. $p = $this->request->post('p');
  861. $type = $this->request->post('type');
  862. if($type)
  863. {
  864. $map['status']=$type;
  865. }
  866. $data_list = db('rose')->where($map)->page($p, 10)->select();
  867. foreach ($data_list as &$v) {
  868. $v['times'] = date("Y/m/d H:i:s", $v['ctime']);
  869. $v['phone']=substr($v['mobile'],0,3).'****'.substr($v['mobile'],-4);
  870. }
  871. if ($data_list) {
  872. $return['data'] = $data_list;
  873. } else {
  874. $return['data'] = null;
  875. }
  876. $count = db('rose')->where($map)->count();
  877. $return['total'] = ceil($count / 10);
  878. return $return;
  879. }
  880. function updatename()
  881. {
  882. $param=$this->request->post();
  883. $userid = $this->auth->id;
  884. $res=db('user')->where("id",$userid)->update(['nickname'=>$param['nickname']]);
  885. if($res)
  886. {
  887. $this->success(__("修改完成"));
  888. }else{
  889. $this->error(__("修改失败"));
  890. }
  891. }
  892. function profile()
  893. {
  894. $param = $this->request->post();
  895. $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'])));
  896. if(!$check)
  897. {
  898. $this->error('请至少完整填写一项收款信息');
  899. }
  900. $intime=get_user_data($this->auth->id,'intime');
  901. $userid = $this->auth->id;
  902. $param['isuser']=1;
  903. $param['updatetime']=time();
  904. if($intime>0)
  905. {
  906. $param['intime']=time();
  907. }
  908. $res=db('user')->where("id",$userid)->update($param);
  909. if($res)
  910. {
  911. $this->success(__("修改完成"));
  912. }else{
  913. $this->error(__("修改失败"));
  914. }
  915. }
  916. function toreal()
  917. {
  918. $param = $this->request->post();
  919. $user=db('user')->where(['id'=> $this->auth->id])->find();
  920. if($user['isreal']>0)
  921. {
  922. $this->error('您已实名或者实名审核中,不可重复操作');
  923. }
  924. if(!($param['idcard'] && $param['realname'] && $param['idprc1'] && $param['idprc2']))
  925. {
  926. $this->error('请完善实名资料');
  927. }
  928. $idcardinfo=db('user')->where(['idcard'=>$param['idcard'],'id'=>['neq',$this->auth->id]])->find();
  929. if($idcardinfo)
  930. {
  931. $this->error('一个身份号只能绑定一个账号');
  932. }
  933. $param['isreal']=1;
  934. $userid = $this->auth->id;
  935. $res=db('user')->where("id",$userid)->update($param);
  936. if($res)
  937. {
  938. $this->success(__("认证完成"));
  939. }else{
  940. $this->error(__("认证失败"));
  941. }
  942. }
  943. function totrans()
  944. {
  945. $param=$this->request->post();
  946. $from_moneytyp='cash';
  947. $to_moneytype='bonus';
  948. $psdtwo = $param['psdtwo'];
  949. if(empty($psdtwo))
  950. {
  951. $this->error(__('请输入支付密码!'));
  952. }
  953. if(!check_psdtwo($psdtwo,$this->auth->id)){
  954. $this->error(__('支付密码验证失败!'));
  955. }
  956. if(empty($param['money']))
  957. {
  958. $this->error(__('请输入提取金额'));
  959. }
  960. if(!($param['money']>0))
  961. {
  962. $this->error(__('提取金额有误'));
  963. }
  964. if(!is_numeric($param['money']))
  965. {
  966. $this->error(__('提取金额有误'));
  967. }
  968. $user=get_user_data($this->auth->id);
  969. $jc=$param['money']-$user[$from_moneytyp];
  970. if($jc>0)
  971. {
  972. $this->error(get_money_name_byident($from_moneytyp).'不足');
  973. }
  974. db()->startTrans();
  975. $changedata=[
  976. 'type'=>10,
  977. 'money'=>0-$param['money'],
  978. 'userid'=>$this->auth->id,
  979. 'relevant_userid'=>$this->auth->id,
  980. 'remark'=>'提取扣除'.$param['money'],
  981. ];
  982. $res=caiwu($changedata, $from_moneytyp);
  983. $changedata=[
  984. 'type'=>10,
  985. 'money'=>$param['money'],
  986. 'userid'=>$this->auth->id,
  987. 'relevant_userid'=>$this->auth->id,
  988. 'remark'=>'提取增加'.$param['money'],
  989. ];
  990. $res1=caiwu($changedata,$to_moneytype);
  991. if($res && $res1)
  992. {
  993. db()->commit();
  994. $this->success(__("提取成功"));
  995. }else{
  996. db()->rollback();
  997. $this->error(__("提取失败"));
  998. }
  999. }
  1000. /* 转账 */
  1001. function transfer()
  1002. {
  1003. $param=$this->request->post();
  1004. $psdtwo = $param['psdtwo'];
  1005. if(empty($psdtwo))
  1006. {
  1007. $this->error(__('请输入安全密码!'));
  1008. }
  1009. if(!check_psdtwo($psdtwo,$this->auth->id)){
  1010. $this->error(__('安全密码验证失败!'));
  1011. }
  1012. if(empty($param['money']))
  1013. {
  1014. $this->error(__('请输入转账数量'));
  1015. }
  1016. if(!($param['money']>0))
  1017. {
  1018. $this->error(__('转账数量有误'));
  1019. }
  1020. if(!is_numeric($param['money']))
  1021. {
  1022. $this->error(__('转账数量有误'));
  1023. }
  1024. $user=get_user_data($this->auth->id);
  1025. $jc=$param['money']-$user['bonus'];
  1026. if($jc>0)
  1027. {
  1028. $this->error(__('平台币不足'));
  1029. }
  1030. $touser=db('user')->where(['username|mobile'=>$param['touser'],'status'=>1])->find();
  1031. if(empty($touser))
  1032. {
  1033. $this->error(__("接收会员不存在"));
  1034. }
  1035. if(!in_array($this->auth->id,explode(',',$touser['refereeids'])) && !in_array($touser['id'],explode(',',$user['refereeids'])) )
  1036. {
  1037. $this->error(__("与目标用户存在推荐关系方可转出"));
  1038. }
  1039. db()->startTrans();
  1040. $changedata=[
  1041. 'type'=>8,
  1042. 'money'=>0-$param['money'],
  1043. 'userid'=>$this->auth->id,
  1044. 'relevant_userid'=>$touser['id'],
  1045. 'remark'=>'转账给'.$touser['username'],
  1046. ];
  1047. $res=caiwu($changedata, 'bonus');
  1048. $changedata=[
  1049. 'type'=>7,
  1050. 'money'=>$param['money'],
  1051. 'userid'=>$touser['id'],
  1052. 'relevant_userid'=>$this->auth->id,
  1053. 'remark'=>'接收'.$user['username'].'转账',
  1054. ];
  1055. $res1=caiwu($changedata, 'bonus');
  1056. if($res && $res1)
  1057. {
  1058. db()->commit();
  1059. $this->success(__("转账成功"));
  1060. }else{
  1061. db()->rollback();
  1062. $this->error(__("转账失败"));
  1063. }
  1064. }
  1065. function gettranscode()
  1066. {
  1067. $group = $this->request->post('money_type');
  1068. $map['userid'] = $this->auth->id;
  1069. $map['type']=8;
  1070. $p = $this->request->post('p');
  1071. $data_list = db('detailed' . ucfirst($group))->where($map)->page($p, 15)->order("id desc")->select();
  1072. foreach ($data_list as $k => $v) {
  1073. $data_list[$k]['money'] = $v['money'] > 0 ? '+' . $v['money'] : $v['money'];
  1074. $data_list[$k]['times'] = date("Y-m-d H:i:s", $v['create_time']);
  1075. $data_list[$k]['type'] = get_detailed_type_text($v['type']);
  1076. }
  1077. if ($data_list) {
  1078. $return['data'] = $data_list;
  1079. } else {
  1080. $return['data'] = null;
  1081. }
  1082. $count = db('detailed' . ucfirst($group))->where($map)->count();
  1083. $return['total'] = ceil($count / 15);
  1084. return $return;
  1085. }
  1086. }