User.php 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Ems;
  5. use app\common\library\Sms;
  6. use fast\Random;
  7. use think\Config;
  8. use think\Validate;
  9. use app\common\library\Token;
  10. use think\Db;
  11. use app\common\model\UserDeviceInfo;
  12. use onlogin\onlogin;
  13. use addons\epay\library\Service;
  14. use addons\epay\library\Wechat;
  15. use TencentCloud\Common\Credential;
  16. use TencentCloud\Common\Profile\ClientProfile;
  17. use TencentCloud\Common\Profile\HttpProfile;
  18. use TencentCloud\Common\Exception\TencentCloudSDKException;
  19. use TencentCloud\Faceid\V20180301\FaceidClient;
  20. use TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
  21. use TencentCloud\Iai\V20200303\IaiClient;
  22. use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
  23. /**
  24. * 会员接口,登录,注册,修改资料等
  25. */
  26. class User extends Api
  27. {
  28. protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'onlogin','getUserOpenid_gzh','jssdkBuildConfig', 'mobileregister', 'mobilecheck', 'wechatregiter', 'onregister', 'ioslogin', 'iosregiter'];
  29. protected $noNeedRight = '*';
  30. public function _initialize()
  31. {
  32. parent::_initialize();
  33. if (!Config::get('fastadmin.usercenter')) {
  34. $this->error(__('User center already closed'));
  35. }
  36. }
  37. /**
  38. * 会员中心
  39. */
  40. public function index()
  41. {
  42. $this->success('', ['welcome' => $this->auth->nickname]);
  43. }
  44. /**
  45. * 获取美颜授权
  46. *
  47. */
  48. public function getmeiyan()
  49. {
  50. $code = Db::name('Config')->where(['name'=>'meiyan'])->value('value');
  51. $rs['code'] = $code;
  52. $this->success('请求成功',$code);
  53. }
  54. /**
  55. * 会员登录
  56. *
  57. * @ApiMethod (POST)
  58. * @param string $account 账号
  59. * @param string $password 密码
  60. */
  61. public function login()
  62. {
  63. $account = input('account');
  64. $password = input('password');
  65. if (!$account || !$password) {
  66. $this->error(__('Invalid parameters'));
  67. }
  68. $ret = $this->auth->login($account, $password);
  69. if ($ret) {
  70. $data = $this->userInfo('return');
  71. $this->success(__('Logged in successful'), $data);
  72. } else {
  73. $this->error($this->auth->getError());
  74. }
  75. }
  76. /**
  77. * 手机验证码登录
  78. *
  79. * @ApiMethod (POST)
  80. * @param string $mobile 手机号
  81. * @param string $captcha 验证码
  82. */
  83. public function mobilelogin()
  84. {
  85. $mobile = input('mobile');
  86. $captcha = input('captcha');
  87. if (!$mobile || !$captcha) {
  88. $this->error(__('Invalid parameters'));
  89. }
  90. if (!Validate::regex($mobile, "^1\d{10}$")) {
  91. $this->error(__('Mobile is incorrect'));
  92. }
  93. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  94. $this->error(__('Captcha is incorrect'));
  95. }
  96. $user = \app\common\model\User::getByMobile($mobile);
  97. if ($user) {
  98. if ($user->status == -1) {
  99. $this->error('账户已注销');
  100. }
  101. if (!in_array($user->status,[1,2])) {
  102. $this->error(__('Account is locked'));
  103. }
  104. if ($user->frozentime > time()) {
  105. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  106. }
  107. //如果已经有账号则直接登录
  108. $ret = $this->auth->direct($user->id);
  109. //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
  110. /*if($user->gender == 1 && $user->gh_id == 0){
  111. $this->firstopen_send($user->id);
  112. }*/
  113. } else {
  114. // $this->success('选择性别', ['code' => 5]);
  115. $extend = [
  116. 'register_from' => input('register_from',''),
  117. 'gender' => -1
  118. ];
  119. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  120. //亿米
  121. /*if(input('register_from','') == 'xiaomi'){
  122. $this->yimi_advert();
  123. }*/
  124. }
  125. if ($ret) {
  126. Sms::flush($mobile, 'mobilelogin');
  127. $data = $this->userInfo('return');
  128. $this->success(__('Logged in successful'), $data);
  129. } else {
  130. $this->error($this->auth->getError());
  131. }
  132. }
  133. /**
  134. * 手机验证码验证
  135. *
  136. * @ApiMethod (POST)
  137. * @param string $mobile 手机号
  138. * @param string $captcha 验证码
  139. */
  140. public function mobilecheck()
  141. {
  142. $mobile = input('mobile');
  143. $captcha = input('captcha');
  144. if (!$mobile || !$captcha) {
  145. $this->error(__('Invalid parameters'));
  146. }
  147. if (!Validate::regex($mobile, "^1\d{10}$")) {
  148. $this->error(__('Mobile is incorrect'));
  149. }
  150. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  151. $this->error(__('Captcha is incorrect'));
  152. }
  153. $this->success('验证通过');
  154. }
  155. /**
  156. * 手机验证码注册
  157. *
  158. * @ApiMethod (POST)
  159. * @param string $mobile 手机号
  160. * @param string $captcha 验证码
  161. * @param string $gender 性别:1=男,0=女
  162. */
  163. public function mobileregister()
  164. {
  165. $mobile = input('mobile');
  166. $captcha = input('captcha');
  167. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  168. if (!$mobile || !$captcha) {
  169. $this->error(__('Invalid parameters'));
  170. }
  171. if (!Validate::regex($mobile, "^1\d{10}$")) {
  172. $this->error(__('Mobile is incorrect'));
  173. }
  174. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  175. $this->error(__('Captcha is incorrect'));
  176. }
  177. if (!in_array($gender, [1, 0])) {
  178. $this->error('性别错误');
  179. }
  180. $user = \app\common\model\User::getByMobile($mobile);
  181. if ($user) {
  182. $this->error('账号已经存在,请直接登录');
  183. if ($user->status == -1) {
  184. $this->error('账户已注销');
  185. }
  186. if (!in_array($user->status,[1,2])) {
  187. $this->error(__('Account is locked'));
  188. }
  189. //如果已经有账号则直接登录
  190. $ret = $this->auth->direct($user->id);
  191. //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
  192. /*if($user->gender == 1 && $user->gh_id == 0){
  193. $this->firstopen_send($user->id);
  194. }*/
  195. } else {
  196. $extend = [
  197. 'register_from' => input('register_from',''),
  198. 'gender' => $gender
  199. ];
  200. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  201. //亿米
  202. /*if(input('register_from','') == 'xiaomi'){
  203. $this->yimi_advert();
  204. }*/
  205. }
  206. if ($ret) {
  207. Sms::flush($mobile, 'mobilelogin');
  208. $data = $this->userInfo('return');
  209. $this->success(__('Logged in successful'), $data);
  210. } else {
  211. $this->error($this->auth->getError());
  212. }
  213. }
  214. /**
  215. * 运营商一键登录
  216. */
  217. public function onLogin()
  218. {
  219. $accessToken = input('accessToken');// 运营商预取号获取到的token
  220. $token = input('tokenT');// 易盾返回的token
  221. if (!$accessToken || !$token) {
  222. $this->error("参数获取失败!");
  223. }
  224. $params = array(
  225. // 运营商预取号获取到的token
  226. "accessToken" => $accessToken,
  227. // 易盾返回的token
  228. "token" => $token
  229. );
  230. // 获取密钥配置
  231. $configInfo = config("onLogin");
  232. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  233. $onret = $onlogin->check($params);
  234. // $ret = [];
  235. // $ret["code"] = 200;
  236. // $ret["msg"] = "ok";
  237. // $ret["data"] = [
  238. // "phone" => "17574504021",
  239. // "resultCode" => 0
  240. // ];
  241. if ($onret["code"] == 200) {
  242. $mobile = $onret["data"]["phone"];
  243. if (empty($mobile)) {
  244. // 取号失败,建议进行二次验证,例如短信验证码
  245. $this->error("取号登录失败,请用验证码方式登录!");
  246. } else {
  247. // 取号成功, 执行登录等流程
  248. // 用户登录逻辑 === 开始
  249. $user = \app\common\model\User::getByMobile($mobile);
  250. if ($user) {
  251. if (!in_array($user->status,[1,2])) {
  252. $this->error(__('Account is locked'));
  253. }
  254. if ($user->frozentime > time()) {
  255. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  256. }
  257. //如果已经有账号则直接登录
  258. $ret = $this->auth->direct($user->id);
  259. $is_register = 0;
  260. //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
  261. /*if($user->gender == 1 && $user->gh_id == 0){
  262. $this->firstopen_send($user->id);
  263. }*/
  264. } else {
  265. // $this->success('选择性别', ['code' => 5]);
  266. $extend = [
  267. 'register_from' => input('register_from',''),
  268. 'gender' => -1
  269. ];
  270. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  271. $is_register = 1;
  272. //亿米
  273. // if(input('register_from','') == 'xiaomi'){
  274. // $this->yimi_advert();
  275. // }
  276. }
  277. //结果
  278. /*$rs['userinfo'] = $this->auth->getUserinfo();
  279. $rs['is_register'] = $is_register;*/
  280. if ($ret) {
  281. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  282. } else {
  283. $this->error($this->auth->getError());
  284. }
  285. // 用户登录逻辑 === 结束
  286. }
  287. } else {
  288. $this->error("登录失败,请用验证码方式登录!");
  289. }
  290. }
  291. /**
  292. * 运营商一键登录注册
  293. */
  294. public function onregister()
  295. {
  296. $accessToken = input('accessToken');// 运营商预取号获取到的token
  297. $token = input('tokenT');// 易盾返回的token
  298. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  299. if (!$accessToken || !$token) {
  300. $this->error("参数获取失败!");
  301. }
  302. if (!in_array($gender, [1, 0])) {
  303. $this->error('性别错误');
  304. }
  305. $params = array(
  306. // 运营商预取号获取到的token
  307. "accessToken" => $accessToken,
  308. // 易盾返回的token
  309. "token" => $token
  310. );
  311. // 获取密钥配置
  312. $configInfo = config("onLogin");
  313. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  314. $onret = $onlogin->check($params);
  315. // $ret = [];
  316. // $ret["code"] = 200;
  317. // $ret["msg"] = "ok";
  318. // $ret["data"] = [
  319. // "phone" => "17574504021",
  320. // "resultCode" => 0
  321. // ];
  322. if ($onret["code"] == 200) {
  323. $mobile = $onret["data"]["phone"];
  324. if (empty($mobile)) {
  325. // 取号失败,建议进行二次验证,例如短信验证码
  326. $this->error("取号登录失败,请用验证码方式登录!");
  327. } else {
  328. // 取号成功, 执行登录等流程
  329. // 用户登录逻辑 === 开始
  330. $user = \app\common\model\User::getByMobile($mobile);
  331. if ($user) {
  332. $this->error('账号已经存在,请直接登录');
  333. if (!in_array($user->status,[1,2])) {
  334. $this->error(__('Account is locked'));
  335. }
  336. //如果已经有账号则直接登录
  337. $ret = $this->auth->direct($user->id);
  338. $is_register = 0;
  339. //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
  340. /*if($user->gender == 1 && $user->gh_id == 0){
  341. $this->firstopen_send($user->id);
  342. }*/
  343. } else {
  344. $extend = [
  345. 'register_from' => input('register_from',''),
  346. 'gender' => $gender
  347. ];
  348. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  349. $is_register = 1;
  350. //亿米
  351. // if(input('register_from','') == 'xiaomi'){
  352. // $this->yimi_advert();
  353. // }
  354. }
  355. //结果
  356. /*$rs['userinfo'] = $this->auth->getUserinfo();
  357. $rs['is_register'] = $is_register;*/
  358. if ($ret) {
  359. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  360. } else {
  361. $this->error($this->auth->getError());
  362. }
  363. // 用户登录逻辑 === 结束
  364. }
  365. } else {
  366. $this->error("登录失败,请用验证码方式登录!");
  367. }
  368. }
  369. //用户详细资料
  370. public function userInfo($type = 1){
  371. $info = $this->auth->getUserinfo();
  372. if($type == 'return'){
  373. return $info;
  374. }
  375. $this->success(__('success'),$info);
  376. }
  377. public function testhaibao(){
  378. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode]);
  379. // dump($haibao);
  380. $this->success('success', $haibao);
  381. }
  382. //海报
  383. public function haibao($player_id,$data){
  384. //下载页二维码,没必要保留
  385. $params = [
  386. 'text' => config('site.domain_name').'?code=' . $data['introcode'],
  387. 'size' => 90,
  388. 'logo' => false,
  389. 'label' => false,
  390. 'padding' => 0,
  391. ];
  392. $qrCode = \addons\qrcode\library\Service::qrcode($params);
  393. $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
  394. mk_dir($qrcode_path);
  395. $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
  396. $qrCode->writeFile($download_qrcode);
  397. //海报
  398. $haibao = $this->createhaibao($download_qrcode,$player_id,$data);
  399. return $haibao;
  400. }
  401. /*public function createhaibao($download_qrcode,$player_id,$sub_data){
  402. //背景图
  403. $background = $sub_data['background'] ? $sub_data['background'] : config('site.domain_name').'/assets/img/haibao.png';
  404. //海报图片路径
  405. $new_path = 'uploads/hbplayer/'.date("Ymd").'/';
  406. mk_dir($new_path);
  407. $wap_file_name = $new_path .'wap_player_'. $player_id . '.png';
  408. //二维码
  409. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  410. //合成wap图片
  411. $image = new \addons\poster\library\Image2();
  412. $imgurl = $image->createPosterImage($background,$download_qrcode,$sub_data['introcode'],$wap_file_name);
  413. return '/'.$wap_file_name;
  414. }*/
  415. public function createhaibao($download_qrcode,$player_id,$sub_data){
  416. //二维码
  417. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  418. $data = [
  419. [
  420. "left" => "15px",
  421. "top" => "296px",
  422. "type" => "img",
  423. "width" => "58px",
  424. "height" => "58px",
  425. "src" => one_domain_image($this->auth->avatar)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  426. ],
  427. [
  428. "left" => "81px",
  429. "top" => "300px",
  430. "type" => "nickname",
  431. "width" => "80px",
  432. "height" => "24px",
  433. "size" => "12px",
  434. "color" => "#000",
  435. "content" => $this->auth->nickname
  436. ],
  437. [
  438. "left" => "81px",
  439. "top" => "327px",
  440. "type" => "nickname",
  441. "width" => "80px",
  442. "height" => "24px",
  443. "size" => "12px",
  444. "color" => "#000",
  445. "content" => $this->auth->introcode
  446. ],
  447. [
  448. "left" => "227px",
  449. "top" => "283px",
  450. "type" => "img",
  451. "width" => "80px",
  452. "height" => "80px",
  453. // "src" => httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  454. "src" => $download_qrcode//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  455. ]
  456. ];
  457. $data = json_encode($data, 320);
  458. $poster = [
  459. 'id' => 1,
  460. 'title' => '测试2',
  461. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  462. 'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
  463. 'data' => $data,
  464. 'status' => 'normal',
  465. 'weigh' => 0,
  466. 'createtime' => 1653993709,
  467. 'updatetime' => 1653994259,
  468. ];
  469. $image = new \addons\poster\library\Image();
  470. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  471. if (!$imgurl) {
  472. $this->error('生成海报出错');
  473. }
  474. // $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  475. return '/' . $imgurl;
  476. }
  477. //实名认证信息
  478. public function idcard_confirm_info(){
  479. $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
  480. if (!$check) {
  481. $check = (object)[];
  482. }
  483. $this->success('success',$check);
  484. }
  485. /**
  486. * 退出登录
  487. * @ApiMethod (POST)
  488. */
  489. public function logout()
  490. {
  491. if (!$this->request->isPost()) {
  492. $this->error(__('Invalid parameters'));
  493. }
  494. //退出im
  495. $tenIm = new Tenim();
  496. $tenIm->loginoutim($this->auth->id);
  497. //修改用户活跃0
  498. Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
  499. $this->auth->logout();
  500. $this->success(__('Logout successful'));
  501. }
  502. /**
  503. * 修改会员个人信息
  504. *
  505. * @ApiMethod (POST)
  506. * @param string $avatar 头像地址
  507. * @param string $username 用户名
  508. * @param string $nickname 昵称
  509. * @param string $bio 个人简介
  510. */
  511. public function profile()
  512. {
  513. $field_array = ['nickname','introcode',/*'gender',*/'birthday','height','weight','bio','audio_bio','avatar','photo_images','education_id','hobby_ids','job_id','marital_id','tag_ids','wages_id','hometown_cityid','hide_is_finishinfo','wechat_account','character_id','constellation_id','stature_id','is_appointment', 'greet_voice', 'greet_chat', 'is_cohabit', 'live_id', 'is_house', 'car_id', 'chest_id', 'waist'];
  514. $data = [];
  515. foreach($field_array as $key => $field){
  516. if(!input('?'.$field)){
  517. continue;
  518. }
  519. $newone = input($field);
  520. if($field == 'avatar'){
  521. // if ($this->auth->real_status == 1) {
  522. //$this->error('您已经真人认证不能修改头像~');
  523. // die;
  524. // }
  525. $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  526. }
  527. if($field == 'photo_images'){
  528. $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
  529. }
  530. $data[$field] = $newone;
  531. }
  532. if(isset($data['birthday'])){
  533. $data['birthday'] = strtotime($data['birthday']);
  534. }
  535. if(isset($data['avatar'])){
  536. //$data['real_status'] = -1; //或许应该改成0。性别不能改所以不需要
  537. }
  538. if(isset($data['hobby_ids'])){
  539. $data['hobby_ids'] = implode(',',explode(',',$data['hobby_ids']));
  540. }
  541. if(isset($data['tag_ids'])){
  542. $data['tag_ids'] = implode(',',explode(',',$data['tag_ids']));
  543. }
  544. if(isset($data['introcode'])){
  545. if ($this->auth->intro_uid != 0) {
  546. $this->error('邀请人不可修改~');
  547. }
  548. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $data['introcode'])->find();
  549. if(!$intro_user){
  550. $this->error('不存在的邀请人');
  551. }
  552. if ($intro_user['id'] == $this->auth->id) {
  553. $this->error('不能填写自己邀请码');
  554. }
  555. if ($intro_user['intro_uid'] == $this->auth->id) {
  556. $this->error('不能填写下级邀请码');
  557. }
  558. unset($data['introcode']);//别人的邀请码,不能改了自己的
  559. $data['intro_uid'] = $intro_user['id'];
  560. $data['invite_time'] = time();
  561. }
  562. //dump($data);
  563. if(empty($data)){
  564. $this->error('没有任何改变');
  565. }
  566. Db::startTrans();
  567. $userData = Db::name('user')->field('avatar,gender,status')->where('id',$this->auth->id)->find();
  568. if (isset($data['avatar']) && !empty($data['avatar']) && $userData['status'] == 2) {//隐藏
  569. $boyAvatar = config('avatar_boy');
  570. $girlAvatar = config('avatar_girl');
  571. if ($userData['gender'] == 1 && $data['avatar'] != $boyAvatar) {
  572. $data['status'] = 1;//更新为正常
  573. } elseif ($userData['gender'] == 0 && $data['avatar'] != $girlAvatar) {
  574. $data['status'] = 1;//更新为正常
  575. }
  576. }
  577. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  578. if($update_rs === false){
  579. Db::rollback();
  580. $this->error('修改资料失败');
  581. }
  582. //tag任务赠送金币
  583. //上传头像加5金币
  584. if(isset($data['avatar'])){
  585. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  586. if($task_rs === false){
  587. Db::rollback();
  588. $this->error('完成任务赠送奖励失败');
  589. }
  590. }
  591. //上传生日 +5金币
  592. if (isset($data['birthday'])) {
  593. //完成设置生日 +5金币
  594. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  595. if($task_rs === false){
  596. Db::rollback();
  597. $this->error('完成任务赠送奖励失败');
  598. }
  599. }
  600. //上传个性签名 5金币
  601. if(isset($data['audio_bio'])){
  602. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
  603. if($task_rs === false){
  604. Db::rollback();
  605. $this->error('完成任务赠送奖励失败');
  606. }
  607. }
  608. //上传本人语音介绍 10金币
  609. if(isset($data['audio_bio'])){
  610. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,21);
  611. if($task_rs === false){
  612. Db::rollback();
  613. $this->error('完成任务赠送奖励失败');
  614. }
  615. }
  616. //上传本人五张照片 10金币
  617. if(isset($data['photo_images'])){
  618. $photo_images_num = count(explode(',',$data['photo_images'])) + count(explode(',',$this->auth->photo_images));
  619. if ($photo_images_num >= 5) {
  620. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id, 5);
  621. if ($task_rs === false) {
  622. Db::rollback();
  623. $this->error('完成任务赠送奖励失败');
  624. }
  625. }
  626. }
  627. Db::commit();
  628. $this->success();
  629. }
  630. /*
  631. * 修改用户的坐标
  632. * */
  633. public function change_longlat(){
  634. $longitude = input_post('longitude');
  635. $latitude = input_post('latitude');
  636. $cityname = input_post('cityname');
  637. if(empty($longitude) || empty($latitude) || empty($cityname)){
  638. $this->error();
  639. }
  640. $data = [
  641. 'longitude' => $longitude,
  642. 'latitude' => $latitude,
  643. 'cityname' => $cityname,
  644. ];
  645. Db::name('user')->where('id',$this->auth->id)->update($data);
  646. $this->success();
  647. }
  648. /**
  649. * 修改手机号
  650. *
  651. * @ApiMethod (POST)
  652. * @param string $mobile 手机号
  653. * @param string $captcha 验证码
  654. */
  655. public function changemobile()
  656. {
  657. $user = $this->auth->getUser();
  658. $oldcaptcha = $this->request->request('oldcaptcha');
  659. $mobile = $this->request->request('mobile');
  660. $captcha = $this->request->request('captcha');
  661. if (!$oldcaptcha || !$mobile || !$captcha) {
  662. $this->error(__('Invalid parameters'));
  663. }
  664. if (!Validate::regex($mobile, "^1\d{10}$")) {
  665. $this->error(__('Mobile is incorrect'));
  666. }
  667. if($user->mobile == $mobile){
  668. $this->error('新手机号不能与旧手机号相同');
  669. }
  670. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  671. $this->error(__('Mobile already exist'));
  672. }
  673. $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
  674. if (!$result) {
  675. $this->error(__('Captcha is incorrect'));
  676. }
  677. $result = Sms::check($mobile, $captcha, 'changemobile');
  678. if (!$result) {
  679. $this->error(__('Captcha is incorrect'));
  680. }
  681. $verification = $user->verification;
  682. $verification->mobile = 1;
  683. $user->verification = $verification;
  684. $user->mobile = $mobile;
  685. $user->save();
  686. Sms::flush($user->mobile, 'changemobile');
  687. Sms::flush($mobile, 'changemobile');
  688. $this->success();
  689. }
  690. /**
  691. * 微信注册来的,绑定手机号
  692. *
  693. * @ApiMethod (POST)
  694. * @param string $mobile 手机号
  695. * @param string $captcha 验证码
  696. */
  697. public function bindmobile()
  698. {
  699. $user = $this->auth->getUser();
  700. $mobile = $this->request->request('mobile');
  701. $captcha = $this->request->request('captcha');
  702. if(!empty($this->auth->mobile)){
  703. $this->error('已经绑定了手机号');
  704. }
  705. if (!$mobile || !$captcha) {
  706. $this->error(__('Invalid parameters'));
  707. }
  708. if (!Validate::regex($mobile, "^1\d{10}$")) {
  709. $this->error(__('Mobile is incorrect'));
  710. }
  711. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  712. $this->error('该手机号已被其他用户绑定');
  713. }
  714. $result = Sms::check($mobile, $captcha, 'changemobile');
  715. if (!$result) {
  716. $this->error(__('Captcha is incorrect'));
  717. }
  718. $verification = $user->verification;
  719. $verification->mobile = 1;
  720. $user->verification = $verification;
  721. $user->mobile = $mobile;
  722. $user->save();
  723. Sms::flush($mobile, 'changemobile');
  724. //手机号奖励
  725. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,18);
  726. if($task_rs === false){
  727. Db::rollback();
  728. return false;
  729. }
  730. $this->success('success',$this->userInfo('return'));
  731. }
  732. /**
  733. * 手机号注册来的,绑定微信
  734. *
  735. * @ApiMethod (POST)
  736. * @param string wechat_openid 微信openid
  737. */
  738. public function bindopenid()
  739. {
  740. $user = $this->auth->getUser();
  741. $wechat_openid = $this->request->request('wechat_openid');
  742. if(!empty($this->auth->wechat_openid)){
  743. $this->error('已经绑定了微信号');
  744. }
  745. if (!$wechat_openid) {
  746. $this->error(__('Invalid parameters'));
  747. }
  748. if (\app\common\model\User::where('wechat_openid', $wechat_openid)->find()) {
  749. $this->error('该微信号已被其他用户绑定');
  750. }
  751. $user->wechat_openid = $wechat_openid;
  752. $user->save();
  753. $this->success('success',$this->userInfo('return'));
  754. }
  755. /**
  756. * 重置密码
  757. *
  758. * @ApiMethod (POST)
  759. * @param string $mobile 手机号
  760. * @param string $newpassword 新密码
  761. * @param string $captcha 验证码
  762. */
  763. public function resetpwd()
  764. {
  765. //$type = input("type");
  766. $type = 'mobile';
  767. $mobile = input("mobile");
  768. $email = input("email");
  769. $newpassword = input("newpassword");
  770. $captcha = input("captcha");
  771. if (!$newpassword || !$captcha) {
  772. $this->error(__('Invalid parameters'));
  773. }
  774. if ($type == 'mobile') {
  775. if (!Validate::regex($mobile, "^1\d{10}$")) {
  776. $this->error(__('Mobile is incorrect'));
  777. }
  778. $user = \app\common\model\User::getByMobile($mobile);
  779. if (!$user) {
  780. $this->error(__('User not found'));
  781. }
  782. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  783. if (!$ret) {
  784. $this->error(__('Captcha is incorrect'));
  785. }
  786. Sms::flush($mobile, 'resetpwd');
  787. } else {
  788. if (!Validate::is($email, "email")) {
  789. $this->error(__('Email is incorrect'));
  790. }
  791. $user = \app\common\model\User::getByEmail($email);
  792. if (!$user) {
  793. $this->error(__('User not found'));
  794. }
  795. $ret = Ems::check($email, $captcha, 'resetpwd');
  796. if (!$ret) {
  797. $this->error(__('Captcha is incorrect'));
  798. }
  799. Ems::flush($email, 'resetpwd');
  800. }
  801. //模拟一次登录
  802. $this->auth->direct($user->id);
  803. $ret = $this->auth->changepwd($newpassword, '', true);
  804. if ($ret) {
  805. $this->success(__('Reset password successful'));
  806. } else {
  807. $this->error($this->auth->getError());
  808. }
  809. }
  810. /**
  811. * 修改密码
  812. *
  813. * @ApiMethod (POST)
  814. * @param string $newpassword 新密码
  815. * @param string $oldpassword 旧密码
  816. */
  817. public function changepwd(){
  818. $newpassword = input('newpassword');
  819. $oldpassword = input('oldpassword','');
  820. if (!$newpassword) {
  821. $this->error(__('Invalid parameters'));
  822. }
  823. if($this->auth->password && empty($oldpassword)){
  824. $this->error('原密码必填');
  825. }
  826. if(empty($this->auth->password)){
  827. $ret = $this->auth->changepwd($newpassword, '', true);
  828. }else{
  829. $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
  830. }
  831. if ($ret) {
  832. $this->success(__('Reset password successful'));
  833. } else {
  834. $this->error($this->auth->getError());
  835. }
  836. }
  837. /**
  838. * 记录当前登陆的设备ID,设备信息,IP等
  839. */
  840. public function changeDeviceIp()
  841. {
  842. // 接口防并发
  843. if (!$this->apiLimit(1, 5)) {
  844. return ;
  845. }
  846. $user = $this->auth->getUser();
  847. $ip = request()->ip();
  848. $deviceId = $this->request->request('device_id','');
  849. $phoneModel = $this->request->request('phone_model','');
  850. $brand = $this->request->request('brand','');
  851. $apiVersion = $this->request->request('api_version','');
  852. $deviceOs = $this->request->request('device_os','');
  853. if ($ip !== $user->loginip){
  854. $update = [];
  855. $update['id'] = $user->id;
  856. $update['loginip'] = $ip;
  857. \app\common\model\User::update($update);
  858. }
  859. $userDeviceInfo = UserDeviceInfo::get(['user_id'=>$user->u_id]);
  860. if (empty($userDeviceInfo)){
  861. $userDeviceInfo = new UserDeviceInfo();
  862. $userDeviceInfo->user_id = $user->u_id;
  863. }
  864. $userDeviceInfo->device_os = $deviceOs;
  865. $userDeviceInfo->device_id = $deviceId;
  866. $userDeviceInfo->phone_model = $phoneModel;
  867. $userDeviceInfo->brand = $brand;
  868. $userDeviceInfo->api_version = $apiVersion;
  869. $userDeviceInfo->save();
  870. //首页接口调用,这里不反回信息
  871. // $this->success("更新成功!");
  872. }
  873. //假注销
  874. public function cancleUser(){
  875. if (!$this->request->isPost()) {
  876. $this->error(__('Invalid parameters'));
  877. }
  878. //退出im
  879. $tenIm = new Tenim();
  880. $tenIm->loginoutim($this->auth->id);
  881. Db::name('user')->where('id',$this->auth->id)->update(['status'=>-1]);
  882. $this->auth->logout();
  883. $this->success('注销成功');
  884. }
  885. //修改用户活跃1
  886. public function useractive(){
  887. $this->success('success');
  888. }
  889. //公众号获取openid
  890. public function getUserOpenid_gzh(){
  891. $configValue = Service::getConfig('wechat');
  892. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  893. $rs = $wechat->getOpenid();
  894. $this->success('success',$rs);
  895. }
  896. /**
  897. * 微信内H5-JSAPI支付
  898. */
  899. public function jssdkBuildConfig() {
  900. $url = $this->request->request("url");
  901. $configValue = Service::getConfig('wechat');
  902. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  903. $sign = $wechat->getSignPackage(urldecode($url));
  904. $this->success("获取成功!",$sign);
  905. }
  906. //苹果账号登录
  907. public function ioslogin(){
  908. $ios_openid = input('ios_openid','');
  909. if (!$ios_openid) {
  910. $this->error(__('Invalid parameters'));
  911. }
  912. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  913. /*if (!$user) {
  914. $this->success('选择性别', ['code' => 5]);
  915. }*/
  916. if ($user) {
  917. if (!in_array($user->status,[1,2])) {
  918. $this->error(__('Account is locked'));
  919. }
  920. if ($user->frozentime > time()) {
  921. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  922. }
  923. //如果已经有账号则直接登录
  924. $ret = $this->auth->direct($user->id);
  925. } else {
  926. $reg_data = [
  927. 'register_from' => input('register_from',''),
  928. 'gender' => -1
  929. ];
  930. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  931. }
  932. if ($ret) {
  933. $data = $this->userInfo('return');
  934. $this->success(__('Logged in successful'), $data);
  935. } else {
  936. $this->error($this->auth->getError());
  937. }
  938. }
  939. //苹果账号注册
  940. public function iosregiter(){
  941. $ios_openid = input('ios_openid', '', 'trim');
  942. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  943. if (!$ios_openid) {
  944. $this->error(__('Invalid parameters'));
  945. }
  946. if (!in_array($gender, [1, 0])) {
  947. $this->error('性别错误');
  948. }
  949. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  950. if ($user) {
  951. $this->error('账号已经存在,请直接登录');
  952. }
  953. $reg_data = [
  954. 'register_from' => input('register_from',''),
  955. 'gender' => $gender
  956. ];
  957. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  958. if ($ret) {
  959. $data = $this->userInfo('return');
  960. $this->success(__('Logged in successful'), $data);
  961. } else {
  962. $this->error($this->auth->getError());
  963. }
  964. }
  965. //注册完善资料
  966. public function perfect_info() {
  967. $avatar = input('avatar', '', 'trim'); //头像
  968. $nickname = input('nickname', '', 'trim'); //昵称
  969. $birthday = input('birthday', '', 'strtotime'); //生日
  970. $hometown_cityid = input('hometown_cityid', '', 'trim'); //城市id
  971. $job_id = input('job_id', '', 'trim'); //职业id
  972. $character_id = input('character_id', '', 'trim'); //性格id
  973. $introcode = input('introcode', '', 'trim'); //邀请码
  974. $data = [];
  975. if ($avatar) {
  976. $data['avatar'] = $avatar;
  977. }
  978. if ($nickname !== '') {
  979. if (iconv_strlen($nickname, 'utf-8') > 10) {
  980. $this->error('昵称最多10个字~');
  981. }
  982. $data['nickname'] = $nickname;
  983. }
  984. if ($birthday) {
  985. $data['birthday'] = $birthday;
  986. }
  987. if ($hometown_cityid) {
  988. $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
  989. if (!$count) {
  990. $this->error('城市不存在');
  991. }
  992. $data['hometown_cityid'] = $hometown_cityid;
  993. }
  994. if ($job_id) {
  995. $count = Db::name('enum_job')->where('id', $job_id)->count('id');
  996. if (!$count) {
  997. $this->error('职业不存在');
  998. }
  999. $data['job_id'] = $job_id;
  1000. }
  1001. if ($character_id) {
  1002. $count = Db::name('enum_character')->where('id', $character_id)->count('id');
  1003. if (!$count) {
  1004. $this->error('性格不存在');
  1005. }
  1006. $data['character_id'] = $character_id;
  1007. }
  1008. if ($introcode && !$this->auth->intro_uid) {
  1009. /*if ($this->auth->intro_uid) {
  1010. $this->error('您已经填写过邀请人啦');
  1011. }
  1012. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
  1013. if(!$intro_user){
  1014. $this->error('不存在的邀请人');
  1015. }
  1016. if ($intro_user['id'] == $this->auth->id) {
  1017. $this->error('不能填写自己邀请码');
  1018. }
  1019. if ($intro_user['intro_uid'] == $this->auth->id) {
  1020. $this->error('不能填写下级邀请码');
  1021. }
  1022. $data['intro_uid'] = $intro_user['id'];
  1023. $data['invite_time'] = time();*/
  1024. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
  1025. if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
  1026. $data['intro_uid'] = $intro_user['id'];
  1027. $data['invite_time'] = time();
  1028. }
  1029. }
  1030. // if (!$data) {
  1031. // $this->error('请输入要修改的信息');
  1032. // }
  1033. //开启事务
  1034. Db::startTrans();
  1035. $update_rs = Db::name('user')->where('id',$this->auth->id)->setField($data);
  1036. if($update_rs === false){
  1037. Db::rollback();
  1038. $this->error('修改失败');
  1039. }
  1040. //上传头像加5金币
  1041. if(isset($data['avatar'])){
  1042. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  1043. if($task_rs === false){
  1044. Db::rollback();
  1045. $this->error('完成任务赠送奖励失败');
  1046. }
  1047. }
  1048. if (isset($data['birthday'])) {
  1049. //完成设置生日 +5金币
  1050. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  1051. if($task_rs === false){
  1052. Db::rollback();
  1053. $this->error('完成任务赠送奖励失败');
  1054. }
  1055. }
  1056. Db::commit();
  1057. $this->success('修改成功');
  1058. }
  1059. //实名认证
  1060. public function idcard_auth() {
  1061. $info = Db::name('user_idconfirm')->where(['user_id' => $this->auth->id])->find();
  1062. // if ($info && $info['status'] == 0) {
  1063. // $this->error('您已经提交信息了,请进行人脸认证!');
  1064. // }
  1065. if ($info && $info['status'] == 1) {
  1066. $this->error('您已通过审核!');
  1067. }
  1068. $nickname = input('nickname', '', 'trim'); // 姓名
  1069. $idcard = input('idcard', '', 'trim'); // 身份证号
  1070. if ($nickname === '') {
  1071. $this->error('请输入姓名');
  1072. }
  1073. if (iconv_strlen($nickname, 'utf-8') > 50) {
  1074. $this->error('请输入正确姓名');
  1075. }
  1076. if ($idcard === '') {
  1077. $this->error('请输入身份证号');
  1078. }
  1079. if (iconv_strlen($idcard, 'utf-8') != 18) {
  1080. $this->error('请输入正确身份证号');
  1081. }
  1082. $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
  1083. if ($count) {
  1084. $this->error('身份证号已存在');
  1085. }
  1086. $data = [];
  1087. $data['truename'] = $nickname;
  1088. $data['idcard'] = $idcard;
  1089. //腾讯云身份证二要素认证
  1090. $auth_restult = $this->userauth_tencent($idcard, $nickname);
  1091. if ($auth_restult) {
  1092. $data['status'] = 1; //通过
  1093. $msg = '认证通过';
  1094. } else {
  1095. $data['status'] = 2; //不通过
  1096. $msg = '认证不通过';
  1097. }
  1098. //开启事务
  1099. Db::startTrans();
  1100. if (!$info) { //未认证
  1101. $data["user_id"] = $this->auth->id;
  1102. $data["createtime"] = time();
  1103. $res = Db::name('user_idconfirm')->insertGetId($data);
  1104. } else { //认证被拒绝过
  1105. $data['updatetime'] = time();
  1106. $res = Db::name('user_idconfirm')->where(['id' => $info['id'], 'user_id' => $this->auth->id])->setField($data);
  1107. }
  1108. if (!$res) {
  1109. Db::rollback();
  1110. $this->error('认证失败');
  1111. }
  1112. $rt = Db::name('user')->where(['id' => $this->auth->id, 'idcard_status' => $this->auth->idcard_status])->setField('idcard_status', $data['status']);
  1113. if ($rt === false) {
  1114. Db::rollback();
  1115. $this->error('认证失败');
  1116. }
  1117. if ($data['status'] == 1) {
  1118. //完成实名认证 +20金币
  1119. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,4);
  1120. if($task_rs === false){
  1121. Db::rollback();
  1122. $this->error('完成任务赠送奖励失败');
  1123. }
  1124. //系统消息
  1125. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证已经审核通过');
  1126. } else {
  1127. //系统消息
  1128. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证审核不通过');
  1129. }
  1130. Db::commit();
  1131. $this->success($msg);
  1132. }
  1133. //腾讯云身份证二要素认证
  1134. public function userauth_tencent($idcard = '', $nickname = '') {
  1135. // require_once 'vendor/autoload.php';
  1136. try {
  1137. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1138. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1139. $config = config('tencent_im');
  1140. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1141. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1142. $httpProfile = new HttpProfile();
  1143. $httpProfile->setEndpoint("faceid.tencentcloudapi.com");
  1144. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1145. $clientProfile = new ClientProfile();
  1146. $clientProfile->setHttpProfile($httpProfile);
  1147. // 实例化要请求产品的client对象,clientProfile是可选的
  1148. $client = new FaceidClient($cred, "", $clientProfile);
  1149. // 实例化一个请求对象,每个接口都会对应一个request对象
  1150. $req = new IdCardVerificationRequest();
  1151. $params = array(
  1152. "IdCard" => $idcard,
  1153. "Name" => $nickname
  1154. );
  1155. $req->fromJsonString(json_encode($params));
  1156. // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应
  1157. $resp = $client->IdCardVerification($req);
  1158. // 输出json格式的字符串回包
  1159. // print_r($resp->toJsonString());
  1160. $result = json_decode($resp->toJsonString(), true);
  1161. if (isset($result['Result']) && $result['Result'] == 0) {
  1162. return 1; //通过
  1163. } else {
  1164. return 0;
  1165. }
  1166. }
  1167. catch(TencentCloudSDKException $e) {
  1168. // echo $e;
  1169. return 0;
  1170. }
  1171. }
  1172. //绑定支付宝
  1173. public function addalipayaccount() {
  1174. $id = input('id', 0, 'intval'); //账号id
  1175. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1176. // $type = 1;
  1177. $realname = input('realname', '', 'trim'); //账户真实姓名
  1178. $banknumber = input('banknumber', '', 'trim'); //卡号或账号
  1179. $bankname = input('bankname', '', 'trim'); //银行名称
  1180. // if ($id) {
  1181. // $this->error('您已经拥有该类型账号,请联系后台解绑');
  1182. // }
  1183. if (!in_array($type, [1, 2])) {
  1184. $this->error('参数错误');
  1185. }
  1186. /*if ($type == 1) {
  1187. $this->error('暂不支持绑定支付宝');
  1188. }*/
  1189. if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
  1190. $this->error('账号姓名1-30位');
  1191. }
  1192. if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
  1193. $this->error('账号1-50位');
  1194. }
  1195. if ($type == 1) {
  1196. if (iconv_strlen($bankname, 'utf-8') != 18) {
  1197. $this->error('请输入正确身份证号');
  1198. }
  1199. }
  1200. if ($type == 2) {
  1201. if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
  1202. $this->error('开户行名称1-50位');
  1203. }
  1204. }
  1205. $user_bank = Db::name('user_bank');
  1206. if ($id) {
  1207. //编辑
  1208. //查询账号是否存在
  1209. $info = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1210. if (!$info) {
  1211. $this->error('账号不存在');
  1212. }
  1213. if ($info['type'] != $type) {
  1214. $this->error('账号类型错误');
  1215. }
  1216. //查询是否未通过提现记录
  1217. $count = Db::name('take_cash')->where(['user_id' => $this->auth->id, 'alipay_account' => $info['banknumber'], 'status' => 0])->count('id');
  1218. if ($count) {
  1219. $this->error('该账户有未审核的提现记录,暂不可修改');
  1220. }
  1221. $data['realname'] = $realname;
  1222. $data['banknumber'] = $banknumber;
  1223. $data['updatetime'] = time();
  1224. // if ($type == 2) {
  1225. $data['bankname'] = $bankname;
  1226. // }
  1227. $rs = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->setField($data);
  1228. if ($rs === false) {
  1229. $this->error('修改失败');
  1230. }
  1231. $this->success('修改成功');
  1232. } else {
  1233. //添加
  1234. //查询是否已经拥有该类型账号
  1235. $count = $user_bank->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  1236. if ($count) {
  1237. $this->error('您已经拥有该类型账号,请联系后台解绑');
  1238. }
  1239. $data['user_id'] = $this->auth->id;
  1240. $data['type'] = $type;
  1241. $data['realname'] = $realname;
  1242. $data['banknumber'] = $banknumber;
  1243. // if ($type == 2) {
  1244. $data['bankname'] = $bankname;
  1245. // }
  1246. $data['createtime'] = time();
  1247. $rs = $user_bank->insertGetId($data);
  1248. if (!$rs) {
  1249. $this->error('添加失败');
  1250. }
  1251. $this->success('添加成功');
  1252. }
  1253. }
  1254. //查询支付宝/银行卡信息
  1255. public function alipayinfo() {
  1256. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1257. $info = Db::name('user_bank')->field('id, realname, banknumber, bankname')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
  1258. if (!$info) {
  1259. $info = (object)[];
  1260. }
  1261. $this->success('success', $info);
  1262. }
  1263. //申请真人认证
  1264. public function realauth() {
  1265. if ($this->auth->real_status == 1) {
  1266. $this->error('您已经真人认证过了~');
  1267. }
  1268. if ($this->auth->avatar == config('avatar_boy') || $this->auth->avatar == config('avatar_girl')) {
  1269. $this->error('请先上传真人头像~');
  1270. }
  1271. //获取token
  1272. $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
  1273. $token_result = file_get_contents($token_url);
  1274. if (!$token_result) {
  1275. $this->error('您的网络开小差啦1~');
  1276. }
  1277. $token_result = json_decode($token_result, true);
  1278. if ($token_result['code'] != 0) {
  1279. $this->error('您的网络开小差啦2~');
  1280. }
  1281. $token = $token_result['access_token'];
  1282. //获取签名鉴权参数ticket
  1283. $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
  1284. $ticket_result = file_get_contents($ticket_url);
  1285. if (!$ticket_result) {
  1286. $this->error('您的网络开小差啦3~');
  1287. }
  1288. $ticket_result = json_decode($ticket_result, true);
  1289. if ($ticket_result['code'] != 0) {
  1290. $this->error('您的网络开小差啦4~');
  1291. }
  1292. $ticket = $ticket_result['tickets'][0]['value'];
  1293. //获取签名
  1294. $sign_data = [
  1295. 'wbappid' => config('tencent_yun')['secret_id'],
  1296. 'userId' => (string)$this->auth->id,
  1297. 'version' => '1.0.0',
  1298. 'ticket' => $ticket,
  1299. 'nonce' => Random::alnum(32)
  1300. ];//p($sign_data);
  1301. asort($sign_data); //p($sign_data);//排序
  1302. $sign_string = join('', $sign_data);//p($sign_string);
  1303. $sign = sha1($sign_string);//p($sign);
  1304. //上传身份信息
  1305. $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000); //商户请求的唯一标识
  1306. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo=' . $orderNo;
  1307. $avatar = one_domain_image($this->auth->avatar);
  1308. $avatar = str_replace('https', 'http', $avatar);
  1309. $img = file_get_contents($avatar);
  1310. $img = str_replace('data:image/jpg;base64', '', $img);
  1311. $img = str_replace('\n', '', $img);
  1312. $sourcePhotoStr = base64_encode($img);
  1313. $data = [
  1314. 'webankAppId' => config('tencent_yun')['secret_id'],
  1315. 'orderNo' => $orderNo,
  1316. 'userId' => (string)$this->auth->id,
  1317. 'sourcePhotoStr' => $sourcePhotoStr,
  1318. 'sourcePhotoType' => 2,
  1319. 'version' => '1.0.0',
  1320. 'sign' => $sign,
  1321. 'nonce' => $sign_data['nonce']
  1322. ];
  1323. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1324. if (!$rs) {
  1325. $this->error('您的网络开小差啦5~');
  1326. }
  1327. $rs = json_decode($rs, true);
  1328. if (!$rs || $rs['code'] != 0) {
  1329. $this->error('您的网络开小差啦6~');
  1330. }
  1331. $user_auth = [
  1332. 'user_id' => $this->auth->id,
  1333. 'certify_id' => $rs['result']['faceId'],
  1334. 'out_trade_no' => $data['orderNo'],
  1335. 'status' => 0,
  1336. 'createtime' => time(),
  1337. 'updatetime' => time()
  1338. ];
  1339. //开启事务
  1340. Db::startTrans();
  1341. //查询是否认证过
  1342. $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1343. if ($info) {
  1344. $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
  1345. } else {
  1346. $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
  1347. }
  1348. if (!$auth_rs) {
  1349. Db::rollback();
  1350. $this->error('您的网络开小差啦7~');
  1351. }
  1352. //修改用户表认证状态
  1353. $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
  1354. if ($user_rs === false) {
  1355. Db::rollback();
  1356. $this->error('您的网络开小差啦8~');
  1357. }
  1358. Db::commit();
  1359. $return_data = [
  1360. 'face_id' => $user_auth['certify_id'],
  1361. 'order_no' => $user_auth['out_trade_no'],
  1362. 'user_id' => (string)$this->auth->id,
  1363. 'nonce' => $sign_data['nonce'],
  1364. 'sign' => $sign
  1365. ];
  1366. $this->success('success', $return_data);
  1367. }
  1368. //查询真人认证结果
  1369. public function getrealauthresult() {
  1370. $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1371. if (!$user_auth) {
  1372. $this->success('尚未认证');
  1373. }
  1374. if ($user_auth['status'] == 1) {
  1375. $this->success('真人认证通过');
  1376. }
  1377. if (!$user_auth['certify_id']) {
  1378. $this->success('请先进行真人认证');
  1379. }
  1380. //获取token
  1381. $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
  1382. $token_result = file_get_contents($token_url);
  1383. if (!$token_result) {
  1384. $this->error('您的网络开小差啦1~');
  1385. }
  1386. $token_result = json_decode($token_result, true);
  1387. if ($token_result['code'] != 0) {
  1388. $this->error('您的网络开小差啦2~');
  1389. }
  1390. $token = $token_result['access_token'];
  1391. //获取签名鉴权参数ticket
  1392. $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
  1393. $ticket_result = file_get_contents($ticket_url);
  1394. if (!$ticket_result) {
  1395. $this->error('您的网络开小差啦3~');
  1396. }
  1397. $ticket_result = json_decode($ticket_result, true);
  1398. if ($ticket_result['code'] != 0) {
  1399. $this->error('您的网络开小差啦4~');
  1400. }
  1401. $ticket = $ticket_result['tickets'][0]['value'];
  1402. //获取签名
  1403. $sign_data = [
  1404. 'wbappid' => config('tencent_yun')['secret_id'],
  1405. 'orderNo' => $user_auth['out_trade_no'],
  1406. 'version' => '1.0.0',
  1407. 'ticket' => $ticket,
  1408. 'nonce' => Random::alnum(32)
  1409. ];//p($sign_data);
  1410. asort($sign_data); //p($sign_data);//排序
  1411. $sign_string = join('', $sign_data);//p($sign_string);
  1412. $sign = sha1($sign_string);//p($sign);
  1413. //人脸核身结果查询
  1414. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
  1415. $data = [
  1416. 'appId' => config('tencent_yun')['secret_id'],
  1417. 'version' => '1.0.0',
  1418. 'nonce' => $sign_data['nonce'],
  1419. 'orderNo' => $user_auth['out_trade_no'],
  1420. 'sign' => $sign
  1421. ];
  1422. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1423. if (!$rs) {
  1424. $this->error('您的网络开小差啦5~');
  1425. }
  1426. $rs = json_decode($rs, true);
  1427. if (!$rs || $rs['code'] != 0) {
  1428. $this->error($rs['msg']);
  1429. }
  1430. if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
  1431. $edit_data['status'] = 1;
  1432. $msg = '真人认证成功';
  1433. } else {
  1434. $edit_data['status'] = 2;
  1435. $edit_data['certify_id'] = '';
  1436. $edit_data['out_trade_no'] = '';
  1437. $msg = '真人认证失败';
  1438. }
  1439. $edit_data['updatetime'] = time();
  1440. //开启事务
  1441. Db::startTrans();
  1442. //修改认证信息
  1443. $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
  1444. if (!$result) {
  1445. Db::rollback();
  1446. $this->error('查询认证结果失败2');
  1447. }
  1448. //修改用户信息
  1449. $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
  1450. if (!$rs) {
  1451. Db::rollback();
  1452. $this->error('查询认证结果失败3');
  1453. }
  1454. if ($edit_data['status'] == 1) { //通过
  1455. //tag任务赠送金币
  1456. //真人认证奖励
  1457. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
  1458. if($task_rs === false){
  1459. Db::rollback();
  1460. $this->error('完成任务赠送奖励失败');
  1461. }
  1462. //系统消息
  1463. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  1464. } else {
  1465. //系统消息
  1466. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
  1467. }
  1468. Db::commit();
  1469. $this->success($msg);
  1470. }
  1471. //客服
  1472. public function kefu() {
  1473. $type = input('type', 0, 'intval'); //客服位置: 0客服中心 1充值客服
  1474. if (!in_array($type, [0, 1])) {
  1475. $this->error('您的网络开小差啦~');
  1476. }
  1477. if ($type == 0) {
  1478. $user_id = config('site.customer_service_id') ? : 0; //指定客服id
  1479. } else {
  1480. $user_id = config('site.pay_customer_service_id') ? : 0; //指定客服id
  1481. }
  1482. $list = Db::name('user')->field('id')->where(['status' => 1, 'is_kefu' => 1, 'id' => $user_id])->select();
  1483. if (!$list) {
  1484. $this->success('success', $list);
  1485. }
  1486. foreach ($list as $k => &$v) {
  1487. $v['nickname'] = '客服' . ($k + 1);
  1488. $v['avatar'] = config('avatar_girl');
  1489. }
  1490. $this->success('success', $list);
  1491. }
  1492. //海报背景图
  1493. public function posterlist() {
  1494. $list = config('site.intro_images');
  1495. if (!$list) {
  1496. $this->success('success', (object)[]);
  1497. }
  1498. foreach ($list as &$v) {
  1499. $v = config('img_url') . $this->createposter(config('site.domain_cdnurl') . $v);
  1500. }
  1501. $this->success('success', $list);
  1502. }
  1503. //生成海报
  1504. public function createposter($image = '') {
  1505. // $image = input('image', '', 'trim');
  1506. // if (!$image) {
  1507. // $this->error('您的网络开小差啦~');
  1508. // }
  1509. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode, 'background' => $image]);
  1510. return $haibao;
  1511. // $this->success('success', $haibao);
  1512. }
  1513. //注册设置性别
  1514. public function setgender() {
  1515. $user_id = $this->auth->id;
  1516. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  1517. if (!in_array($gender, [1, 0])) {
  1518. $this->error('性别错误');
  1519. }
  1520. $edit_data['gender'] = $gender;
  1521. $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl'); //头像
  1522. $rs = Db::name('user')->where(['id' => $user_id, 'gender' => $this->auth->gender])->setField($edit_data);
  1523. if (!$rs) {
  1524. $this->error('您的网络开小差啦~');
  1525. }
  1526. $data = $this->userInfo('return');
  1527. $data['gender'] = $edit_data['gender'];
  1528. $data['avatar'] = $edit_data['avatar'];
  1529. $this->success('success', $data);
  1530. }
  1531. //真人认证后修改头像前比对
  1532. public function realavatar_auit() {
  1533. if ($this->auth->real_status != 1) {
  1534. $this->error('尚未通过真人认证');
  1535. }
  1536. $avatar = input('avatar', '', 'trim'); //头像地址
  1537. if ($avatar === '') {
  1538. $this->error('参数缺失');
  1539. }
  1540. $avatar = one_domain_image($avatar);
  1541. $now_avatar = one_domain_image($this->auth->avatar);
  1542. if ($avatar == $now_avatar) {
  1543. $this->error('头像未改变');
  1544. }
  1545. //腾讯云人脸识别
  1546. $result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  1547. $this->success('结果', $result);
  1548. }
  1549. //真人认证后修改头像
  1550. public function editrealavatar() {
  1551. if ($this->auth->real_status != 1) {
  1552. $this->error('尚未通过真人认证');
  1553. }
  1554. $avatar = input('avatar', '', 'trim'); //头像地址
  1555. if ($avatar === '') {
  1556. $this->error('参数缺失');
  1557. }
  1558. $avatar = one_domain_image($avatar);
  1559. $now_avatar = one_domain_image($this->auth->avatar);
  1560. if ($avatar == $now_avatar) {
  1561. $this->error('头像未改变');
  1562. }
  1563. //腾讯云人脸识别
  1564. $auit_result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  1565. if ($auit_result != 1) {
  1566. $this->success('提示', ['code' => 2]);
  1567. }
  1568. $data['avatar'] = $avatar;
  1569. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  1570. if (!$user_result) {
  1571. $this->error('修改失败');
  1572. }
  1573. $this->success('修改成功');
  1574. }
  1575. //真人认证后修改头像并取消真人认证
  1576. public function editrealavatarcancelauit() {
  1577. if ($this->auth->real_status != 1) {
  1578. $this->error('尚未通过真人认证');
  1579. }
  1580. $avatar = input('avatar', '', 'trim'); //头像地址
  1581. if ($avatar === '') {
  1582. $this->error('参数缺失');
  1583. }
  1584. $avatar = one_domain_image($avatar);
  1585. $now_avatar = one_domain_image($this->auth->avatar);
  1586. if ($avatar == $now_avatar) {
  1587. $this->error('头像未改变');
  1588. }
  1589. $data['avatar'] = $avatar;
  1590. $data['real_status'] = -1;
  1591. //开启事务
  1592. Db::startTrans();
  1593. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  1594. if (!$user_result) {
  1595. Db::rollback();
  1596. $this->error('修改失败');
  1597. }
  1598. $user_auth_result = Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
  1599. if (!$user_auth_result) {
  1600. Db::rollback();
  1601. $this->error('修改失败');
  1602. }
  1603. Db::commit();
  1604. $this->success('修改成功');
  1605. }
  1606. //腾讯云人脸识别
  1607. public function face_tencent($urla = '', $urlb = '') {
  1608. // require_once 'vendor/autoload.php';
  1609. try {
  1610. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1611. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1612. $config = config('tencent_im');
  1613. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1614. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1615. $httpProfile = new HttpProfile();
  1616. $httpProfile->setEndpoint("iai.tencentcloudapi.com");
  1617. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1618. $clientProfile = new ClientProfile();
  1619. $clientProfile->setHttpProfile($httpProfile);
  1620. // 实例化要请求产品的client对象,clientProfile是可选的
  1621. $client = new IaiClient($cred, "ap-beijing", $clientProfile);
  1622. // 实例化一个请求对象,每个接口都会对应一个request对象
  1623. $req = new CompareFaceRequest();
  1624. $params = array(
  1625. "UrlA" => $urla,
  1626. "UrlB" => $urlb,
  1627. "FaceModelVersion" => "3.0"
  1628. );
  1629. $req->fromJsonString(json_encode($params));
  1630. // 返回的resp是一个CompareFaceResponse的实例,与请求对象对应
  1631. $resp = $client->CompareFace($req);
  1632. // 输出json格式的字符串回包
  1633. // print_r($resp->toJsonString());
  1634. $result = json_decode($resp->toJsonString(), true);
  1635. //3.0版本误识率千分之一对应分数为40分,误识率万分之一对应分数为50分,误识率十万分之一对应分数为60分。 一般超过50分则可认定为同一人。
  1636. if (isset($result['Score']) && $result['Score'] >= 60) {
  1637. return 1; //通过
  1638. } else {
  1639. return 0;
  1640. }
  1641. }
  1642. catch(TencentCloudSDKException $e) {
  1643. // echo $e;
  1644. return 0;
  1645. }
  1646. }
  1647. //修改城市
  1648. public function editcity() {
  1649. $name = input('name', '', 'trim'); //城市名
  1650. if ($name === '') {
  1651. $this->error('参数缺失');
  1652. }
  1653. $hometown_cityid = Db::name('area')->where(['name' => $name])->value('id');
  1654. if (!$hometown_cityid) {
  1655. $this->success('修改成功');
  1656. }
  1657. Db::name('user')->where(['id' => $this->auth->id])->setField('hometown_cityid', $hometown_cityid);
  1658. $this->success('修改成功');
  1659. }
  1660. //搜索用户
  1661. public function searchuser() {
  1662. $keyword = input('keyword', '', 'trim'); //昵称或ID
  1663. if ($keyword === '') {
  1664. $this->error('请输入关键字');
  1665. }
  1666. $id = Db::name('user')->where(['nickname|username' => $keyword])->value('id');
  1667. $id = $id ? : 0;
  1668. $this->success('用户', $id);
  1669. }
  1670. //绑定支付宝账号信息
  1671. public function bindalipayaccount() {
  1672. $mt_user_bank = Db::name('user_bank');
  1673. $count = $mt_user_bank->where(['user_id' => $this->auth->id, 'type' => 1])->count();
  1674. if ($count) {
  1675. $this->error('您已绑定支付宝啦');
  1676. }
  1677. $auth_code = input('auth_code', '', 'trim');
  1678. if (!$auth_code) {
  1679. $this->error('授权码缺失');
  1680. }
  1681. //获取支付宝用户信息
  1682. $rs = getAlipayInfo($auth_code);
  1683. if ($rs['status'] == 0) {
  1684. $this->error($rs['info']);
  1685. }
  1686. $rs = $rs['data'];
  1687. /*
  1688. * Array(
  1689. [alipay_user_info_share_response] => Array
  1690. (
  1691. [code] => 10000
  1692. [msg] => Success
  1693. [avatar] => https://tfs.alipayobjects.com/images/partner/T1BQJsXhhbXXXXXXXX 头像
  1694. [city] => 临沂市 市名称。
  1695. [gender] => m 【注意】只有is_certified为T的时候才有意义,否则不保证准确性. 性别(F:女性;M:男性)。
  1696. [is_certified] => T 是否通过实名认证。T是通过 F是没有实名认证。
  1697. [is_student_certified] => F 是否是学生 T是 F否
  1698. [nick_name] => 风的追求 用户昵称
  1699. [province] => 山东省 省份名称
  1700. [user_id] => 2088902918001020 支付宝用户的userId
  1701. [user_status] => T 用户状态(Q/T/B/W)。 Q代表快速注册用户 T代表已认证用户 B代表被冻结账户 W代表已注册,未激活的账户
  1702. [user_type] => 2 用户类型(1/2) 1代表公司账户2代表个人账户
  1703. )
  1704. )
  1705. */
  1706. $data['banknumber'] = $rs['user_id']; //支付宝用户id
  1707. if (!$data['banknumber']) {
  1708. $this->error('获取用户信息失败');
  1709. }
  1710. $bank_number_count = $mt_user_bank->where(['banknumber' => $data['banknumber'], 'type' => 1])->count();
  1711. if ($bank_number_count) {
  1712. $this->error('该支付宝账号已经绑定用户, 请先解除绑定');
  1713. }
  1714. if (isset($rs['nick_name'])) {
  1715. $data['realname'] = $rs['nick_name']; //支付宝用户昵称
  1716. }
  1717. $data['user_id'] = $this->auth->id;
  1718. $data['createtime'] = time();
  1719. $data['type'] = 1;
  1720. $rt = $mt_user_bank->insertGetId($data);
  1721. if (!$rt) {
  1722. $this->error('绑定失败');
  1723. }
  1724. $this->success('绑定成功');
  1725. }
  1726. //添加打招呼内容,女性使用
  1727. public function addgreetcontent() {
  1728. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册
  1729. $title = input('title', '', 'trim'); //标题(type=1必传)
  1730. $content = input('content', '', 'trim'); //内容
  1731. $duration = input('duration', 0, 'intval'); //时长(type=1必传)
  1732. if (!in_array($type, [0, 1, 2])) {
  1733. $this->error('您的网络开小差了');
  1734. }
  1735. if ($content === '') {
  1736. $this->error('请设置打招呼内容');
  1737. }
  1738. if (iconv_strlen($content, 'utf-8') > 255) {
  1739. $this->error('打招呼内容最多255位');
  1740. }
  1741. if ($type == 1) {
  1742. if ($title === '') {
  1743. $this->error('请输入语音名称');
  1744. }
  1745. if (iconv_strlen($title, 'utf-8') > 50) {
  1746. $this->error('语音名称最多50字');
  1747. }
  1748. if (!$duration) {
  1749. $this->error('参数缺失');
  1750. }
  1751. }
  1752. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  1753. if ($count > 10) {
  1754. $this->error('同一类型打招呼最多设置10条');
  1755. }
  1756. $data['user_id'] = $this->auth->id;
  1757. $data['type'] = $type;
  1758. $data['content'] = $content;
  1759. if ($type == 1) {
  1760. $data['title'] = $title;
  1761. $data['duration'] = $duration;
  1762. }
  1763. $data['createtime'] = time();
  1764. //查询是否有默认打招呼内容
  1765. $default_greet_count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'is_default' => 1])->count('id');
  1766. if (!$default_greet_count) {
  1767. $data['is_default'] = 1;
  1768. }
  1769. $rs = Db::name('user_greet_content')->insertGetId($data);
  1770. if (!$rs) {
  1771. $this->error('您的网络开小差了');
  1772. }
  1773. $this->success('设置成功');
  1774. }
  1775. //查询打招呼内容,女性使用
  1776. public function getgreetcontent() {
  1777. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册,3=所有招呼
  1778. if (!in_array($type, [0, 1, 2, 3])) {
  1779. $this->error('您的网络开小差了');
  1780. }
  1781. if ($type == 3) {
  1782. $list = Db::name('user_greet_content')->where(function ($query) {
  1783. $query->where('user_id', $this->auth->id)->where('type', 'neq', 1);
  1784. })->whereOr(function ($query) {
  1785. $query->where('user_id', $this->auth->id)->where('type', 1)->where('is_default', 1);
  1786. })->select();
  1787. } else {
  1788. $where['user_id'] = $this->auth->id;
  1789. $where['type'] = $type;
  1790. $list = Db::name('user_greet_content')->where($where)->select();
  1791. }
  1792. if ($list) {
  1793. foreach ($list as &$v) {
  1794. if ($v['type'] != 0) {
  1795. $v['content'] = one_domain_image($v['content']);
  1796. }
  1797. }
  1798. }
  1799. $this->success('打招呼内容', $list);
  1800. }
  1801. //设置默认打招呼内容,女性使用
  1802. public function setdefaultgreet() {
  1803. $id = input('id', 0, 'intval'); //打招呼id
  1804. if (!$id) {
  1805. $this->error('您的网络开小差了');
  1806. }
  1807. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->count('id');
  1808. if (!$count) {
  1809. $this->error('您的网络开小差了');
  1810. }
  1811. //开启事务
  1812. Db::startTrans();
  1813. //清除之前默认
  1814. $rs = Db::name('user_greet_content')->where(['user_id' => $this->auth->id])->setField('is_default', 0);
  1815. if ($rs === false) {
  1816. Db::rollback();
  1817. $this->error('您的网络开小差了');
  1818. }
  1819. //设置
  1820. $rt = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->setField('is_default', 1);
  1821. if ($rt === false) {
  1822. Db::rollback();
  1823. $this->error('您的网络开小差了');
  1824. }
  1825. Db::commit();
  1826. $this->success('设置成功');
  1827. }
  1828. //删除打招呼内容,女性使用
  1829. public function deldefaultgreet() {
  1830. $id = input('id', 0, 'intval'); //打招呼id
  1831. if (!$id) {
  1832. $this->error('您的网络开小差了');
  1833. }
  1834. $mt_user_greet_content = Db::name('user_greet_content');
  1835. $info = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->find();
  1836. if (!$info) {
  1837. $this->error('您的网络开小差了');
  1838. }
  1839. //开启事务
  1840. Db::startTrans();
  1841. //删除
  1842. $rs = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->delete();
  1843. if ($rs === false) {
  1844. Db::rollback();
  1845. $this->error('您的网络开小差了');
  1846. }
  1847. //若为默认打招呼内容则重新设置一条
  1848. if ($info['is_default'] == 1) {
  1849. $first_greet = $mt_user_greet_content->where(['user_id' => $this->auth->id])->find();
  1850. if ($first_greet) {
  1851. $rt = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $first_greet['id']])->setField('is_default', 1);
  1852. if ($rt === false) {
  1853. Db::rollback();
  1854. $this->error('您的网络开小差了');
  1855. }
  1856. }
  1857. }
  1858. Db::commit();
  1859. $this->success('删除成功');
  1860. }
  1861. }