User.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  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_type'=> 2,
  798. 'money'=> -$param['money'],
  799. 'balance'=> $user['usdt'],
  800. 'relevant_userid'=>$this->auth->id,
  801. 'status'=>1,
  802. 'create_time'=>time(),
  803. 'remark'=>'提现扣除',
  804. 'user_name'=>$user['username']? $user['username'] : '系统',
  805. 'relevant_name'=>$user['username']? $user['username'] : '系统',
  806. ];
  807. $res1 = Db::name('detailed_bonus')->insertGetId($changedata);
  808. $data = [
  809. 'withdraw_date' => time(),
  810. 'amount' => $param['money'],
  811. 'usdt_num' => $param['money'],
  812. 'fack_receive' => $param['money']-$fee,
  813. 'fee' => $fee,
  814. 'userid' => $this->auth->id,
  815. 'username' => $user['username'],
  816. 'prc' => $prc,
  817. 'usdt_address' => isset($user['usdt_address']) && $param['type'] == 4? $user['usdt_address'] : '',
  818. 'name'=>$name,
  819. 'process_status' => 1,
  820. 'money_type' => 'usdt',
  821. 'type'=>$type,
  822. 'stuid'=>$studio['id'],
  823. ];
  824. $ids = db('withdrawals')->insertGetId($data);
  825. if ($res && $res1 && $ids) {
  826. db()->commit();
  827. $this->success(__("提现成功"));
  828. } else {
  829. db()->rollback();
  830. $this->error(__("提现失败"));
  831. }
  832. }
  833. /**
  834. * 佣金提现
  835. * @throws \think\db\exception\DataNotFoundException
  836. * @throws \think\db\exception\ModelNotFoundException
  837. * @throws \think\exception\DbException
  838. * @throws \think\exception\PDOException
  839. */
  840. function withdraw1()
  841. {
  842. $param = $this->request->post();
  843. $psdtwo = $param['psdtwo'];
  844. if (empty($psdtwo)) {
  845. $this->error(__('请输入支付密码'));
  846. }
  847. if (!check_psdtwo($psdtwo, $this->auth->id)) {
  848. $this->error(__('支付密码验证失败!'));
  849. }
  850. //$config = db('bonus_config')->where('id', 6)->find();
  851. $tradeConfig = Config::getConfigByGroup('trade');
  852. $config['withdraw_min'] = isset($tradeConfig['withdraw_min'])? $tradeConfig['withdraw_min']['value'] : 0;
  853. $config['withdraw_cap'] = isset($tradeConfig['withdraw_cap'])? $tradeConfig['withdraw_cap']['value'] : 0;
  854. $config['withdraw_fee'] = isset($tradeConfig['withdraw_fee'])? $tradeConfig['withdraw_fee']['value'] : 0;
  855. if (empty($param['money'])) {
  856. $this->error(__('请输入提现金额!'));
  857. }
  858. if (!($param['money'] > 0)) {
  859. $this->error(__('提现金额有误'));
  860. }
  861. if (!is_numeric($param['money'])) {
  862. $this->error(__('提现金额有误'));
  863. }
  864. if ($param['money'] < $config['withdraw_min']) {
  865. $this->error(__('提现金额最低为'.$config['withdraw_min']));
  866. }
  867. if ($config['withdraw_cap'] && $param['money'] % $config['withdraw_cap'] != 0) {
  868. $this->error(__('提现金额应为'.$config['withdraw_cap'].'的倍数'));
  869. }
  870. if (empty($param['type'])) {
  871. $this->error(__('请选择提现方式'));
  872. }
  873. $user = get_user_data($this->auth->id);
  874. $JC = $param['money'] - $user['bonus'];
  875. if ($JC > 0) {
  876. $this->error("佣金余额不足");
  877. }
  878. if($param['type'] == 1)
  879. {
  880. if(empty($user['alipayprc']))
  881. {
  882. $this->error('请完善支付宝收款信息');
  883. }
  884. $prc=$user['alipayprc'];
  885. $name= $user['alipay_name'].'-'.$user['alipayname'];
  886. $type="支付宝";
  887. }elseif($param['type'] == 2){
  888. if(empty($user['wxprc']))
  889. {
  890. $this->error('请完善微信收款信息');
  891. }
  892. $prc=$user['wxprc'];
  893. $name='';
  894. $type="微信";
  895. }else if($param['type'] == 3){
  896. if(!($user['bank'] && $user['bank_user_name'] && $user['bank_number']))
  897. {
  898. $this->error('请完善y银行卡收款信息');
  899. }
  900. $prc='';
  901. $name=$user['bank'].'-'.$user['bank_user_name'].'-'.$user['bank_number'];
  902. $type="银行卡";
  903. }
  904. $studio=db('studio')->where(['title'=>$this->auth->login_studio])->find();
  905. $fee=$param['money']*$config['withdraw_fee']*0.01;
  906. db()->startTrans();
  907. $changedata=[
  908. 'type'=>6,
  909. 'money'=>$param['money'],
  910. 'userid'=>$this->auth->id,
  911. 'relevant_userid'=>$this->auth->id,
  912. 'remark'=>'佣金提现扣除',
  913. ];
  914. $res=caiwu($changedata, 'bonus');
  915. $data = [
  916. 'withdraw_date' => time(),
  917. 'amount' => $param['money'],
  918. 'usdt_num' => $param['money'],
  919. 'fack_receive' => $param['money']-$fee,
  920. 'fee' => $fee,
  921. 'userid' => $this->auth->id,
  922. 'username' => $user['username'],
  923. 'prc' => $prc,
  924. 'name'=>$name,
  925. 'process_status' => 1,
  926. 'money_type' => 'bonus',
  927. 'type'=>$type,
  928. 'stuid'=>$studio['id'],
  929. ];
  930. $ids = db('withdrawals')->insertGetId($data);
  931. if ($res && $ids) {
  932. db()->commit();
  933. $this->success(__("提现成功"));
  934. } else {
  935. db()->rollback();
  936. $this->error(__("提现失败"));
  937. }
  938. }
  939. function toupdateuserinfo()
  940. {
  941. $param = $this->request->post();
  942. $userid = $this->auth->id;
  943. $res = db('user')->where("id", $userid)->update($param);
  944. if ($res) {
  945. $this->success(__("上传完成"));
  946. } else {
  947. $this->error(__("上传失败"));
  948. }
  949. }
  950. function getroselist1()
  951. {
  952. $map['pid'] = $this->auth->id;
  953. $p = $this->request->post('p');
  954. $type = $this->request->post('type');
  955. if($type)
  956. {
  957. $map['status']=$type;
  958. }
  959. $data_list = db('rose')->where($map)->page($p, 15)->select();
  960. foreach ($data_list as &$v) {
  961. $v['times'] = date("Y/m/d H:i:s", $v['ctime']);
  962. $v['phone']=substr($v['mobile'],0,3).'****'.substr($v['mobile'],-4);
  963. }
  964. if ($data_list) {
  965. $return['data'] = $data_list;
  966. } else {
  967. $return['data'] = null;
  968. }
  969. $count = db('rose')->where($map)->count();
  970. $return['total'] = ceil($count / 15);
  971. return $return;
  972. }
  973. function getroselist()
  974. {
  975. $map['pid'] = $this->auth->id;
  976. $p = $this->request->post('p');
  977. $type = $this->request->post('type');
  978. if($type)
  979. {
  980. $map['status']=$type;
  981. }
  982. $data_list = db('rose')->where($map)->page($p, 10)->select();
  983. foreach ($data_list as &$v) {
  984. $v['times'] = date("Y/m/d H:i:s", $v['ctime']);
  985. $v['phone']=substr($v['mobile'],0,3).'****'.substr($v['mobile'],-4);
  986. }
  987. if ($data_list) {
  988. $return['data'] = $data_list;
  989. } else {
  990. $return['data'] = null;
  991. }
  992. $count = db('rose')->where($map)->count();
  993. $return['total'] = ceil($count / 10);
  994. return $return;
  995. }
  996. function updatename()
  997. {
  998. $param=$this->request->post();
  999. $userid = $this->auth->id;
  1000. $res=db('user')->where("id",$userid)->update(['nickname'=>$param['nickname']]);
  1001. if($res)
  1002. {
  1003. $this->success(__("修改完成"));
  1004. }else{
  1005. $this->error(__("修改失败"));
  1006. }
  1007. }
  1008. function profile()
  1009. {
  1010. $param = $this->request->post();
  1011. $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'])));
  1012. if(!$check)
  1013. {
  1014. $this->error('请至少完整填写一项收款信息');
  1015. }
  1016. $intime=get_user_data($this->auth->id,'intime');
  1017. $userid = $this->auth->id;
  1018. $param['isuser']=1;
  1019. $param['updatetime']=time();
  1020. if($intime>0)
  1021. {
  1022. $param['intime']=time();
  1023. }
  1024. $res=db('user')->where("id",$userid)->update($param);
  1025. if($res)
  1026. {
  1027. $this->success(__("修改完成"));
  1028. }else{
  1029. $this->error(__("修改失败"));
  1030. }
  1031. }
  1032. function toreal()
  1033. {
  1034. $param = $this->request->post();
  1035. $user=db('user')->where(['id'=> $this->auth->id])->find();
  1036. if($user['isreal']>0)
  1037. {
  1038. $this->error('您已实名或者实名审核中,不可重复操作');
  1039. }
  1040. if(!($param['idcard'] && $param['realname'] && $param['idprc1'] && $param['idprc2']))
  1041. {
  1042. $this->error('请完善实名资料');
  1043. }
  1044. $idcardinfo=db('user')->where(['idcard'=>$param['idcard'],'id'=>['neq',$this->auth->id]])->find();
  1045. if($idcardinfo)
  1046. {
  1047. $this->error('一个身份号只能绑定一个账号');
  1048. }
  1049. $param['isreal']=1;
  1050. $userid = $this->auth->id;
  1051. $res=db('user')->where("id",$userid)->update($param);
  1052. if($res)
  1053. {
  1054. $this->success(__("认证完成"));
  1055. }else{
  1056. $this->error(__("认证失败"));
  1057. }
  1058. }
  1059. function totrans()
  1060. {
  1061. $param=$this->request->post();
  1062. $from_moneytyp='cash';
  1063. $to_moneytype='bonus';
  1064. $psdtwo = $param['psdtwo'];
  1065. if(empty($psdtwo))
  1066. {
  1067. $this->error(__('请输入支付密码!'));
  1068. }
  1069. if(!check_psdtwo($psdtwo,$this->auth->id)){
  1070. $this->error(__('支付密码验证失败!'));
  1071. }
  1072. if(empty($param['money']))
  1073. {
  1074. $this->error(__('请输入提取金额'));
  1075. }
  1076. if(!($param['money']>0))
  1077. {
  1078. $this->error(__('提取金额有误'));
  1079. }
  1080. if(!is_numeric($param['money']))
  1081. {
  1082. $this->error(__('提取金额有误'));
  1083. }
  1084. $user=get_user_data($this->auth->id);
  1085. $jc=$param['money']-$user[$from_moneytyp];
  1086. if($jc>0)
  1087. {
  1088. $this->error(get_money_name_byident($from_moneytyp).'不足');
  1089. }
  1090. db()->startTrans();
  1091. $changedata=[
  1092. 'type'=>10,
  1093. 'money'=>0-$param['money'],
  1094. 'userid'=>$this->auth->id,
  1095. 'relevant_userid'=>$this->auth->id,
  1096. 'remark'=>'提取扣除'.$param['money'],
  1097. ];
  1098. $res=caiwu($changedata, $from_moneytyp);
  1099. $changedata=[
  1100. 'type'=>10,
  1101. 'money'=>$param['money'],
  1102. 'userid'=>$this->auth->id,
  1103. 'relevant_userid'=>$this->auth->id,
  1104. 'remark'=>'提取增加'.$param['money'],
  1105. ];
  1106. $res1=caiwu($changedata,$to_moneytype);
  1107. if($res && $res1)
  1108. {
  1109. db()->commit();
  1110. $this->success(__("提取成功"));
  1111. }else{
  1112. db()->rollback();
  1113. $this->error(__("提取失败"));
  1114. }
  1115. }
  1116. /* 转账 */
  1117. function transfer()
  1118. {
  1119. $param=$this->request->post();
  1120. $psdtwo = $param['psdtwo'];
  1121. if(empty($psdtwo))
  1122. {
  1123. $this->error(__('请输入安全密码!'));
  1124. }
  1125. if(!check_psdtwo($psdtwo,$this->auth->id)){
  1126. $this->error(__('安全密码验证失败!'));
  1127. }
  1128. if(empty($param['money']))
  1129. {
  1130. $this->error(__('请输入转账数量'));
  1131. }
  1132. if(!($param['money']>0))
  1133. {
  1134. $this->error(__('转账数量有误'));
  1135. }
  1136. if(!is_numeric($param['money']))
  1137. {
  1138. $this->error(__('转账数量有误'));
  1139. }
  1140. $user=get_user_data($this->auth->id);
  1141. $jc=$param['money']-$user['bonus'];
  1142. if($jc>0)
  1143. {
  1144. $this->error(__('平台币不足'));
  1145. }
  1146. $touser=db('user')->where(['username|mobile'=>$param['touser'],'status'=>1])->find();
  1147. if(empty($touser))
  1148. {
  1149. $this->error(__("接收会员不存在"));
  1150. }
  1151. if(!in_array($this->auth->id,explode(',',$touser['refereeids'])) && !in_array($touser['id'],explode(',',$user['refereeids'])) )
  1152. {
  1153. $this->error(__("与目标用户存在推荐关系方可转出"));
  1154. }
  1155. db()->startTrans();
  1156. $changedata=[
  1157. 'type'=>8,
  1158. 'money'=>0-$param['money'],
  1159. 'userid'=>$this->auth->id,
  1160. 'relevant_userid'=>$touser['id'],
  1161. 'remark'=>'转账给'.$touser['username'],
  1162. ];
  1163. $res=caiwu($changedata, 'bonus');
  1164. $changedata=[
  1165. 'type'=>7,
  1166. 'money'=>$param['money'],
  1167. 'userid'=>$touser['id'],
  1168. 'relevant_userid'=>$this->auth->id,
  1169. 'remark'=>'接收'.$user['username'].'转账',
  1170. ];
  1171. $res1=caiwu($changedata, 'bonus');
  1172. if($res && $res1)
  1173. {
  1174. db()->commit();
  1175. $this->success(__("转账成功"));
  1176. }else{
  1177. db()->rollback();
  1178. $this->error(__("转账失败"));
  1179. }
  1180. }
  1181. function gettranscode()
  1182. {
  1183. $group = $this->request->post('money_type');
  1184. $map['userid'] = $this->auth->id;
  1185. $map['type']=8;
  1186. $p = $this->request->post('p');
  1187. $data_list = db('detailed' . ucfirst($group))->where($map)->page($p, 15)->order("id desc")->select();
  1188. foreach ($data_list as $k => $v) {
  1189. $data_list[$k]['money'] = $v['money'] > 0 ? '+' . $v['money'] : $v['money'];
  1190. $data_list[$k]['times'] = date("Y-m-d H:i:s", $v['create_time']);
  1191. $data_list[$k]['type'] = get_detailed_type_text($v['type']);
  1192. }
  1193. if ($data_list) {
  1194. $return['data'] = $data_list;
  1195. } else {
  1196. $return['data'] = null;
  1197. }
  1198. $count = db('detailed' . ucfirst($group))->where($map)->count();
  1199. $return['total'] = ceil($count / 15);
  1200. return $return;
  1201. }
  1202. }