Account.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. <?php
  2. /**
  3. *------Create thems Controller------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2017-06-08 10:07:19------
  7. */
  8. namespace App\Api\Controller;
  9. use App\Api\Model\Lottery_money;
  10. use App\Api\Model\Lottery_money_log;
  11. use Biz\Account\AccountManager;
  12. use Biz\Common\Common;
  13. use Biz\Game\GameList;
  14. use System\Lang;
  15. use App\Api\Model\AccountDetail;
  16. use App\Api\Model\AccountNews;
  17. class Account extends BaseController
  18. {
  19. private $accountManager;
  20. public function init()
  21. {
  22. $this->accountManager = new AccountManager();
  23. }
  24. /**
  25. * 验证用户资金密码
  26. */
  27. public function checkPayPass()
  28. {
  29. $payPass = $_POST['payPass'];
  30. $token = $_GET['token'] ?? '';
  31. if (empty($token)) {
  32. Render('5555', '-4010', lang('errors')->get('-4010'));
  33. }
  34. $status = \App\Api\Model\Account::checkPayPwd($token, $payPass);
  35. $data = new \stdClass();
  36. Render($data, $status);
  37. }
  38. /**
  39. * 用户登录
  40. */
  41. public function Login()
  42. {
  43. $account = isset($_POST['account']) ? trim($_POST['account']) : '';
  44. $passwd = isset($_POST['password']) ? trim($_POST['password']) : '';
  45. $token = isset($_POST['wagenttoken']) ? trim($_POST['wagenttoken']) : '';
  46. $result = $this->accountManager->login($account, $passwd, $token);
  47. //$result = $this->accountManager->login('x0053', '123456');
  48. /*if ($result['status'] == 1) {
  49. $this->UserUpgrade();
  50. }*/
  51. Render($result['data'], $result['status'], $result['msg']);
  52. }
  53. /**
  54. * 用户修改密码
  55. */
  56. public function resetPassword()
  57. {
  58. $result = $this->accountManager->savePassword($_POST);
  59. Render($result['data'], $result['status'], $result['msg']);
  60. }
  61. /**
  62. * 用户修改支付密码
  63. */
  64. public function resetPayPassword()
  65. {
  66. $result = $this->accountManager->savePayPassword();
  67. Render($result['data'], $result['status'], $result['msg']);
  68. }
  69. /**
  70. * 用户注册
  71. */
  72. public function enroll()
  73. {
  74. $account_name = $_POST['account'];
  75. // if (stripos($_POST['account_name'],'guest') === false){
  76. //// var_dump($v['account_name']);
  77. // Render('',-4101);
  78. // }
  79. $result = $this->accountManager->register($_POST);
  80. if ($result['status'] == 1) {
  81. $settings = lm('settings', 'Commons')->first();
  82. $result['data']['0']['success_tip'] = $settings->success_tip;
  83. }
  84. Render($result['data'], $result['status'], $result['msg']);
  85. }
  86. /**
  87. * 直接开户
  88. */
  89. public function directAccount()
  90. {
  91. $result = $this->accountManager->directAccountOpening($_POST);
  92. Render($result['data'], $result['status'], $result['msg']);
  93. }
  94. /**
  95. * token获取用户详情
  96. */
  97. public function getAccount()
  98. {
  99. if ($_REQUEST['dbg'] == 1) dd($_SESSION);
  100. $checkToken = $this->accountManager->checkEffectiveTime();
  101. if ($checkToken['status'] != 1) {
  102. Render($checkToken['data'], $checkToken['status'], $checkToken['msg']);
  103. };
  104. $result = $this->accountManager->refreshToken();
  105. //删除不需要的字段
  106. unset($result['data']['token']);
  107. unset($result['data']['finance_cash']);
  108. unset($result['data']['parent_id']);
  109. unset($result['data']['parent_path']);
  110. unset($result['data']['hand_pass']);
  111. if (!empty($result)) {
  112. $find_name = lm('dc_user_grade', 'commons')->where('grade', $result['data']['grade'])->first();
  113. if (!empty($find_name)) {
  114. $res = $find_name->toArray();
  115. $result['data']['vname'] = $res['name'];
  116. }
  117. }
  118. $result['data']['qq'] = trim($result['data']['qq']);
  119. if (!$result['data']['img_url']) {
  120. $result['data']['img_url'] = $result['data']['img_id'] ? "/Public/themes/default/static/img/{$result['data']['img_url']}.png" : "/Public/themes/default/static/img/0.png";
  121. }
  122. Render($result['data'], $result['status'], $result['msg']);
  123. }
  124. /**
  125. * 用户退出登录
  126. */
  127. public function Logout()
  128. {
  129. $account = $this->accountManager->getCurrentUser();
  130. if ($account) {
  131. $result = $this->accountManager->logout($account->account_identity);
  132. Render($result['data'], $result['status'], $result['msg']);
  133. } else {
  134. Render('', -1);
  135. }
  136. }
  137. /**
  138. * 试玩用户注册
  139. */
  140. public function Playtest()
  141. {
  142. $ip = GETIP();
  143. $time = lm('Setinfo', 'commons')->select('infocontent')->where('status', 1)->where('infotype', '2000')->first();
  144. $time = $time->toArray();
  145. // $limit_time = date ('Y-m-d H:i:s', strtotime ('-3day'));
  146. $limit_time = date('Y-m-d H:i:s', strtotime('-' . $time['infocontent'] . 'hour'));
  147. $res = lm('account_detailed', 'commons')->join('account', 'account.identity', 'account_detailed.account_identity')->where('account.status', 4)->where('register_ip', $ip)->where('register_time', '>', $limit_time)->first();
  148. if ($res) {
  149. Render('', -4025);
  150. }
  151. $result = $this->accountManager->demoAccount();
  152. Render($result['data'], $result['status'], $result['msg']);
  153. }
  154. /**
  155. * 判断是否已绑定银行卡
  156. */
  157. public function Iscard()
  158. {
  159. $result = $this->accountManager->Iscard();
  160. Render($result['data'], $result['status'], $result['msg']);
  161. }
  162. /**
  163. * 申请代理用户
  164. */
  165. public function applyAgent()
  166. {
  167. $result = $this->accountManager->applyAgent($_POST);
  168. Render('', $result, lang('errors')->get($result));
  169. }
  170. /**
  171. * 代理用户登录
  172. */
  173. public function agentLogin()
  174. {
  175. $result = $this->accountManager->agentLogin($_POST);
  176. if ($result < 0) {
  177. Render('', $result);
  178. } else {
  179. Render($result, 1, lang('errors')->get(1));
  180. }
  181. }
  182. /**
  183. * 代理用户token是否过期
  184. */
  185. public function agentTokenOverdue()
  186. {
  187. $token = isset($_GET['token']) ? $_GET['token'] : '';
  188. $result = $this->accountManager->agentTokenOverdue($token);
  189. if ($result < 0) {
  190. Render('', $result, lang('errors')->get($result));
  191. } else {
  192. Render($result, 1, lang('errors')->get(1));
  193. }
  194. }
  195. /**
  196. *登录添加登录区域日志
  197. */
  198. public function areaLog()
  199. {
  200. $result = $this->accountManager->areaLog($_GET['ip'], $_GET['accountIdentity']);
  201. if ($result == 1) {
  202. Render('', $result, '成功');
  203. } else {
  204. Render('', $result, '添加登录日志区域错误');
  205. }
  206. }
  207. /**
  208. * 获取用户信息
  209. */
  210. function getAccountInfo()
  211. {
  212. $data = array();
  213. $data = $_SESSION['uinfo'];
  214. $bankInfo = lm('account_bank', 'commons')->where('account_identity', $_SESSION['uinfo']['account_identity'])->first();
  215. if (empty($bankInfo)) {
  216. Render('', -40451);
  217. }
  218. $bankInfo = $bankInfo->toArray();
  219. $data['bank_name'] = $bankInfo['bank_name'];
  220. $data['bank_address'] = $bankInfo['bank_address'];
  221. $data['bank_number'] = $bankInfo['bank_number'];
  222. Render($data, 1);
  223. }
  224. /**
  225. * token获取用户详情
  226. */
  227. public function getAgent()
  228. {
  229. $checkToken = $this->accountManager->checkEffectiveTime();
  230. if ($checkToken['status'] != 1) {
  231. Render($checkToken['data'], $checkToken['status'], lang('commons')->get('user does login'));
  232. };
  233. $result = $this->accountManager->refreshToken();
  234. Render($result['data'], $result['status'], $result['msg']);
  235. }
  236. /**
  237. * 等级升级申请
  238. * @return [type] [description]
  239. */
  240. public function UserUpgrade(int $total_flow = 0)
  241. {
  242. $uinfo = $this->accountManager->getCurrentUser();
  243. if (!$uinfo) {
  244. return '-50003';
  245. }
  246. $result['data'] = $uinfo->toArray();
  247. if ($result['data']['grade'] == 0 || $result['data']['grade'] == -1) {
  248. return '-50019';
  249. }
  250. $res = lm('UserGrade', 'Api')->upgrade($result['data'], $total_flow);
  251. if ($res == 1) {
  252. return 1;
  253. } else {
  254. return $res;
  255. }
  256. }
  257. /**
  258. * 活动升级彩金公用接口
  259. * @return [type] [description]
  260. */
  261. public function Promotiongold()
  262. {
  263. $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : "";
  264. if (empty($id)) {
  265. Render('', "-50009");
  266. }
  267. $wherel['id'] = $id;
  268. $Promotiong = lm('lottery_money', 'Api')->where($wherel)->first();
  269. if (empty($Promotiong)) {
  270. Render('', "-50010");
  271. }
  272. $Promotiong = $Promotiong->toArray();
  273. if ($Promotiong['type'] == 'upgrade') {
  274. $this->rank($id);
  275. } elseif ($Promotiong['type'] == 'first_save') {
  276. $utype = $_REQUEST['per_key'];
  277. if (!$utype) {
  278. Render('', -50025);
  279. }
  280. $this->firstRecharge($id, $utype);
  281. }
  282. }
  283. //晋级彩金
  284. public function rank($id)
  285. {
  286. $uinfo = $this->accountManager->getCurrentUser();
  287. if (!$uinfo) {
  288. return '-50003';
  289. }
  290. $result['data'] = $uinfo->toArray();
  291. if ($result['data']['grade'] == 0 || $result['data']['grade'] == '-1') {
  292. return Render('', '-50035');
  293. }
  294. $res = lm('UserGrade', 'Api')->gold($result['data'], $id);
  295. if ($res == 1) {
  296. return Render('', 1);
  297. } else {
  298. return Render('', $res);
  299. }
  300. }
  301. protected function firstRecharge($active_id, $utype = '')
  302. {
  303. $uinfo = $this->accountManager->getCurrentUser();
  304. if (!$uinfo) {
  305. Render('', -50011);
  306. }
  307. $userinfo = $uinfo->toArray();
  308. //$userinfo = lm ('AccountDetail', 'Api')->where ('account_identity', $uinfo['account_identity'])->first ();
  309. $account = $userinfo['account'];
  310. $account_identity = $userinfo['account_identity'];
  311. $lm = new Lottery_money();
  312. $type = 'first_save';
  313. $data = $lm->where('id', $active_id)->first()->toArray();
  314. if (!$data)
  315. Render('', -50016);
  316. $money = 0;
  317. //todo:首充检查并返回金额
  318. $content = json_decode($data['conent'], 1);
  319. $ftype = $content['fr_type'];
  320. $f = \App\Api\Model\Account::chkFirstRecharge($account_identity, $active_id, $ftype);
  321. $order_id = $f->order_id;
  322. $activeName = Lottery_money::where('id', $active_id)->first(['name'])->name ?? '';
  323. $Lottery_log = new Lottery_money_log();
  324. //查询申请记录
  325. $where = [
  326. ['account_identity', $account_identity],
  327. ['order_id', $order_id],
  328. ['status', '<>', 2]
  329. ];
  330. //需要逻辑:查询当前用户当前订单号是否有参与当前活动
  331. $active = $Lottery_log->where($where)->first();
  332. if ($active) {
  333. Render('', -50034);
  334. }
  335. $money = $f->money;
  336. $ranges = json_decode($data['conent'], 1)['ranges'];
  337. $sel = (function ($param, $num, $type) {
  338. foreach ($param as $k => $v) {
  339. if ($v[5] == $type && $num >= $v[0])
  340. return $v;
  341. }
  342. return [];
  343. })($ranges, $money, $utype);
  344. if (!$sel)
  345. Render('', -50016);//无活动数据
  346. $giftMoney = $money * ($sel[2] / 100);
  347. if ($giftMoney > (float)$sel[3])
  348. $giftMoney = $sel[3];
  349. $totalMoney = $giftMoney + $money;
  350. $rate = $sel[2];
  351. $frate = $sel[4];
  352. $needMoney = $totalMoney * $frate;
  353. $newremark = ['gift_money' => $giftMoney, 'money' => $money, 'needBettingMoney' => $needMoney, 'frate' => $sel[2] / 100, 'rate' => $sel[4]];
  354. $tpl = lang('money')->get('first');
  355. $grade = $sel[5];
  356. $newremark['selected'] = $grade;
  357. $detail = sprintf($tpl, $account, $activeName, $money, $rate, $giftMoney, $grade, $frate, $order_id);
  358. $newremark = json_encode($newremark);
  359. if (!$active) {
  360. {
  361. $data = [];
  362. $data['account_identity'] = $account_identity;
  363. $data['grade'] = $userinfo["grade"];
  364. $data['lottery_money_type'] = $type;
  365. $data['lottery_money_id'] = $active_id;
  366. $data['money'] = $giftMoney;
  367. $data['create_time'] = date('Y-m-d H:i:s');
  368. $data['status'] = 0;
  369. $data['detail'] = $detail ?? '无';
  370. $data['account_name'] = $account;
  371. $data['lottery_money_name'] = $activeName;
  372. $data['flow_record'] = $newremark ?? '';
  373. $data['order_id'] = $order_id;
  374. $res = lm('lottery_money_log', 'Api')->insert($data);
  375. }
  376. if ($res) Render('', 1);
  377. }
  378. Render('', -30018);
  379. }
  380. public function analysis($str = '', $arr = array())
  381. {
  382. if (empty($str)) {
  383. return -51055;
  384. }
  385. if (empty($arr)) {
  386. return -51055;
  387. }
  388. foreach ($arr as $key => $value) {
  389. $str = str_replace("#" . $key . "#", $value, $str);
  390. }
  391. return $str;
  392. }
  393. //申请vip
  394. public function ApplyVip()
  395. {
  396. $result = $this->accountManager->refreshToken();
  397. if ($result['status'] < 0) {
  398. Render('', "-50011");
  399. }
  400. if ($result['data']['grade'] > 0) {
  401. Render('', "-50028");
  402. }
  403. if ($result['data']['grade'] != 0) {
  404. Render('', "-50028");
  405. }
  406. //试玩账号 --2019/1/15 17/14 blues
  407. if (isset($result['data']['status']) && $result['data']['status'] == 4) {
  408. Render('', -4026);
  409. }
  410. $num = lm('User_vip', 'Api')->where('account_identity', $result['data']['account_identity'])->count();
  411. if ($num == 0) {
  412. $data['account_name'] = $result['data']['account'];
  413. $data['account_identity'] = $result['data']['account_identity'];
  414. $data['addtime'] = date('Y-m-d H:i:s');
  415. $data['status'] = 1;
  416. $res = lm('User_vip', 'Api')->insert($data);
  417. if ($res) {
  418. lm('AccountDetail', 'Api')->where('account_identity', $result['data']['account_identity'])->update(['grade' => -1]);
  419. Render('', '1');
  420. } else {
  421. Render('', "-50026");
  422. }
  423. } else {
  424. if ($result['data']['grade'] == 0) {
  425. lm('User_vip', 'Api')->where('account_identity', $result['data']['account_identity'])->update(['status' => 1]);
  426. lm('AccountDetail', 'Api')->where('account_identity', $result['data']['account_identity'])->update(['grade' => -1]);
  427. Render('', '1');
  428. } else {
  429. Render('', "-50036");
  430. }
  431. }
  432. }
  433. //开新用户
  434. public function households()
  435. {
  436. if (empty($_POST['account'])) {
  437. Render('', "-50060", '缺少用户名称');
  438. }
  439. if (empty($_POST['name'])) {
  440. Render('', "-50061", '缺少真实用户名称');
  441. }
  442. if (empty($_POST['password'])) {
  443. Render('', "-50062", '缺少密码');
  444. }
  445. if (empty($_POST['again_password'])) {
  446. Render('', "-50063", '缺少确定密码');
  447. }
  448. if ($_POST['password'] != $_POST['again_password']) {
  449. Render('', "-50064", '确定密码不一致');
  450. }
  451. if (empty($_POST['phone'])) {
  452. Render('', "-50065", '缺少手机号码');
  453. }
  454. $this->checkLogin();
  455. $uinfo = $this->accountManager->getCurrentUser();
  456. if (empty($uinfo->account_identity)) {
  457. Render('', "-50066", '用户未登录');
  458. }
  459. $_POST['parent_identity'] = $uinfo->account_identity;
  460. $result = $this->accountManager->newhouseholds($_POST);
  461. Render($result['data'], $result['status'], $result['msg']);
  462. }
  463. protected function checkLogin()
  464. {
  465. $checkToken = $this->accountManager->checkEffectiveTime();
  466. if ($checkToken['status'] != 1) {
  467. Render($checkToken['data'], $checkToken['status'], $checkToken['msg']);
  468. };
  469. $this->accountManager->refreshToken();
  470. }
  471. public function checkHandPass()
  472. {
  473. $hand_pass = $_REQUEST['hand_pass'];
  474. $this->checkLogin();
  475. $uinfo = $this->accountManager->getCurrentUser();
  476. $uuid = $uinfo->account_identity;
  477. if ($uuid) {
  478. $ret = lm('UserSetting', 'api')->getUserSetting($uuid);
  479. //dd($ret);
  480. if ($ret && isset($ret['hand_pass']) && $ret['hand_pass']) {
  481. if (!$ret['hand_lock'])
  482. Render('' - 60002);//未开启手势密码
  483. if ($ret['hand_pass'] === md5($hand_pass))
  484. Render('', 1);
  485. Render('', -60000);//手势密码不匹配
  486. } else
  487. Render('', -60001);//未设置手势密码
  488. }
  489. Render('', -51017);//用户不存在
  490. }
  491. public function getUserSetting()
  492. {
  493. $this->checkLogin();
  494. $uinfo = $this->accountManager->getCurrentUser();
  495. $uuid = $uinfo->account_identity;
  496. $ret = lm('UserSetting', 'api')->getUserSetting($uuid);
  497. if ($_REQUEST['devicetype'] === 'android' || $_REQUEST['devicetype'] === 'ios') {
  498. $ret['fav_info'] = json_decode($ret['fav_info'], 1) ?? [];
  499. $ret['cart_info'] = json_decode($ret['cart_info'], 1) ?? [];
  500. }
  501. Render($ret, 1);
  502. }
  503. public function setUserSetting()
  504. {
  505. $this->checkLogin();
  506. $uinfo = $this->accountManager->getCurrentUser();
  507. //if ($uinfo && $uinfo->account_identity)
  508. $uuid = $uinfo->account_identity;
  509. if (isset($_POST['hand_pass']) && $_POST['hand_pass'] != '') $data ['hand_pass'] = md5($_POST['hand_pass']);
  510. if (isset($_POST['hand_lock']) && $_POST['hand_lock'] != '') $data ['hand_lock'] = $_POST['hand_lock'];
  511. if (isset($_POST['sound']) && $_POST['sound'] != '') $data ['sound'] = $_POST['sound'];
  512. if (isset($_POST['shake_rand']) && $_POST['shake_rand'] != '') $data ['shake_rand'] = $_POST['shake_rand'];
  513. if (isset($_POST['prize_ani']) && $_POST['prize_ani'] != '') $data ['prize_ani'] = $_POST['prize_ani'];
  514. if (isset($_POST['prize_all']) && $_POST['prize_all'] != '') $data ['prize_all'] = $_POST['prize_all'];
  515. if (isset($_POST['win_games']) && $_POST['win_games'] != '') $data ['win_games'] = $_POST['win_games'];
  516. if (isset($_POST['prize_games']) && $_POST['prize_games'] != '') $data ['prize_games'] = $_POST['prize_games'];
  517. if (isset($_POST['fav_info']) && $_POST['fav_info'] != '') $data ['fav_info'] = ($_POST['fav_info']);
  518. if (isset($_POST['cart_info']) && $_POST['cart_info'] != '') $data ['cart_info'] = ($_POST['cart_info']);
  519. if (isset($_POST['device_state']) && $_POST['device_state'] != '') $data ['device_state'] = ($_POST['device_state']);
  520. if (isset($_POST['device_number']) && $_POST['device_number'] != '') $data ['device_number'] = ($_POST['device_number']);
  521. if ($data['prize_games'] == -1) $data['prize_games'] = '';
  522. $lm = lm('UserSetting', 'api');
  523. $favs = json_decode($data['fav_info'], 1);
  524. $favs = array_unique($favs);
  525. $data['fav_info'] = json_encode($favs);
  526. $ret = $lm->setUserSettings($uuid, $data);
  527. Render('', 1);
  528. }
  529. public function setUserSet()
  530. {
  531. $this->checkLogin();
  532. $uinfo = $this->accountManager->getCurrentUser();
  533. //if ($uinfo && $uinfo->account_identity)
  534. $uuid = $uinfo->account_identity;
  535. // $data ['hand_pass'] = md5 ($_POST['hand_pass']);
  536. // $data ['win_games'] = $_POST['win_games'];
  537. $data = array(
  538. 'prize_all' => isset($_POST['prize_all']) ? 1 : 0,
  539. 'win_games' => isset($_POST['win_games']) ? 1 : 0,
  540. );
  541. if (empty($data)) {
  542. return -909090;
  543. }
  544. $ret = lm('UserSetting', 'api')->where('account_identity', $uuid)->update($data);
  545. if ($ret == 1) {
  546. return Render('', 1);
  547. } else {
  548. return Render('', 0);
  549. }
  550. }
  551. public function setHeadImg()
  552. {
  553. //$imgUrl = $_REQUEST['imgUrl'];
  554. $imgId = $_REQUEST['imgId'] ?? 0;
  555. $accountMan = new AccountManager();
  556. // if ($_POST['dd'] == 1)
  557. // dd ($imgUrl);
  558. // if (!$imgUrl) {
  559. // $arr = json_decode (file_get_contents ('php://input'), 1);
  560. // if (isset($arr['imgUrl']) && $arr['imgUrl']) {
  561. // $imgUrl = $arr['imgUrl'];
  562. // }
  563. // }
  564. $ret = null;
  565. $imgUrl = "/Public/themes/default/static/img/{$imgId}.png";
  566. if ($imgUrl) $ret = $accountMan->chHeadImg($imgUrl, $imgId);
  567. if ($ret < 1) {
  568. Render('', $ret);
  569. }
  570. Render($ret, 1);
  571. }
  572. public function setDetail()
  573. {
  574. $phone = $_POST['phone'] ? strip_tags(trim($_POST['phone'])) : '';
  575. $qq = $_POST['qq'] ? strip_tags(trim($_POST['qq'])) : '';
  576. $email = $_POST['email'] ? strip_tags(trim($_POST['email'])) : '';
  577. $wechat = $_POST['wechat'] ? strip_tags(trim($_POST['wechat'])) : '';
  578. if (!$phone && !$qq && !$email && !$wechat) {
  579. Render('', -40256);//数据不能全为空
  580. }
  581. $data = [];
  582. if ($phone) {
  583. $data['phone'] = $phone;
  584. }
  585. if ($qq) {
  586. $data['qq'] = $qq;
  587. }
  588. if ($email) {
  589. $data['email'] = $email;
  590. }
  591. if ($wechat) {
  592. $data['wechat'] = $wechat;
  593. }
  594. $accountMan = new AccountManager();
  595. $uinfo = $accountMan->getCurrentUser();
  596. $uuid = $uinfo->account_identity ?? null;
  597. if (!$uuid) {
  598. Render('', -4001);//用户未找到
  599. }
  600. $ret = lm('AccountDetail', 'Api')->where('account_identity', $uuid)->update($data);
  601. if ($ret) {
  602. Render('', 1);
  603. } else {
  604. Render('', -40254);
  605. }
  606. }
  607. //获取当前用户安全等级
  608. public function safetygrade()
  609. {
  610. //if($_REQUEST['dbg']==1)dd($_SESSION);
  611. $checkToken = $this->accountManager->checkEffectiveTime();
  612. if ($checkToken['status'] != 1) {
  613. Render($checkToken['data'], $checkToken['status'], $checkToken['msg']);
  614. };
  615. $result = $this->accountManager->refreshToken();
  616. if (!empty($result)) {
  617. $bankstate = lm('account_bank', 'commons')->where('account_identity', $result['data']['account_identity'])->count();
  618. $paypasswordstate = lm('pay_password', 'commons')->where('account_identity', $result['data']['account_identity'])->count();
  619. if ($bankstate != 0 && $paypasswordstate != 0 && $result['data']['email'] != '' && $result['data']['qq'] != '') {
  620. $safetystate = '高';
  621. } elseif ($bankstate != 0 && $paypasswordstate != 0) {
  622. $safetystate = '中';
  623. } else {
  624. $safetystate = '低';
  625. }
  626. Render($safetystate, 1);
  627. } else {
  628. Render('', $result['status'], $result['msg']);
  629. }
  630. }
  631. //检查用户是否已注册
  632. public function isRegistered()
  633. {
  634. $an = $_REQUEST['account_name'];
  635. $ret = (new \App\Api\Model\Account())->where('account', $an)->exists();
  636. Render(null, $ret ? -40040 : 1);
  637. }
  638. /**
  639. *错误码列表接口
  640. */
  641. public function getErrLangs()
  642. {
  643. $lang = Lang('Errors', 'Api');
  644. $langs = $lang->getAll();
  645. $newLangs = [];
  646. foreach ($langs as $k => $v) {
  647. $k = trim($k, 'error');
  648. $newLangs["$k"] = $v;
  649. }
  650. Render($newLangs, 1);
  651. }
  652. /**
  653. * 玩法语言包总列表接口
  654. */
  655. public function getGameLangs()
  656. {
  657. if (C()->get('cache')->has('totalGameLangs')) {
  658. $data = C()->get('cache')->get('totalGameLangs');
  659. // C()->get('cache')->delete('totalGameLangs');
  660. } else {
  661. $cls = new Common();
  662. $data = $cls->getGameLangs();
  663. C()->get('cache')->set('totalGameLangs', $data, 86400 * 7);
  664. }
  665. Render($data, 1);
  666. }
  667. /**
  668. * 修改用户基本信息
  669. *
  670. * @access public
  671. * @return array JsonString
  672. */
  673. public function updateUserInfo()
  674. {
  675. $code = 0;
  676. $msg = lang('Common', 'Api')->get('error');
  677. try {
  678. $accountDetailClass = new AccountDetail();
  679. // 修改用户基本信息
  680. $result = $accountDetailClass->updateUserInfo();
  681. if ($result) {
  682. $code = 1;
  683. $msg = lang('Index', 'Api')->get('success');
  684. Render($result, $code, $msg);
  685. } else {
  686. Render([], $code, $msg);
  687. }
  688. } catch (Exception $e) {
  689. Render([], $code, $msg);
  690. }
  691. }
  692. /**
  693. * 用户消息
  694. *
  695. * @access public
  696. * @return array JsonString
  697. */
  698. public function userNews()
  699. {
  700. $code = 0;
  701. $msg = lang('Common', 'Api')->get('error');
  702. try {
  703. $accountDetailClass = new AccountNews();
  704. // 获取用户消息
  705. $result = $accountDetailClass->userNews();
  706. $code = 1;
  707. $msg = lang('Index', 'Api')->get('success');
  708. Render($result, $code, $msg);
  709. } catch (Exception $e) {
  710. Render([], $code, $msg);
  711. }
  712. }
  713. /**
  714. * 上传用户头像
  715. *
  716. * @access public
  717. * @return array JsonString
  718. */
  719. public function updateHeader()
  720. {
  721. $code = 0;
  722. $msg = lang('Common', 'Api')->get('error');
  723. try {
  724. $accountDetailClass = new AccountDetail();
  725. // 修改用户基本信息
  726. $result = $accountDetailClass->updateHeader();
  727. $code = 1;
  728. $msg = lang('Index', 'Api')->get('success');
  729. Render($result, $code, $msg);
  730. } catch (Exception $e) {
  731. Render([], $code, $msg);
  732. }
  733. }
  734. }