UserCenter.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use think\Db;
  7. /**
  8. * @title 会员个人中心
  9. * @controller UserCenter
  10. * @group base
  11. */
  12. class UserCenter extends Base
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. parent::check_login();
  18. }
  19. /**
  20. * @title 获取个人信息
  21. * @desc 个人信息
  22. * @author Gavin
  23. * @url /api/User_center/getUserInfo
  24. * @method POST
  25. * @tag 个人信息
  26. * @header name:Authorization require:1 desc:Token
  27. * @return name:phone type:int default:-- desc:手机号
  28. * @return name:name type:string default:-- desc:昵称
  29. * @return name:headimg type:string default:-- desc:头像地址
  30. * @return name:integral type:int default:-- desc:积分
  31. * @return name:snap_card type:int default:-- desc:抢购卡
  32. * @return name:wallet_address type:int default:-- desc:钱包地址
  33. * @return name:true_name type:string default:-- desc:真实姓名
  34. * @return name:id_card type:string default:-- desc:身份证号
  35. * @return name:is_auth type:int default:-- desc:是否认证(0否1是)
  36. * @return name:auth_at type:string default:-- desc:认证时间
  37. * @return name:vip_name type:int default:-- desc:身份
  38. * @return name:is_order_no_paid type:string default:-- desc:是否有未支付订单true:有false:没有
  39. * @return name:is_sign type:string default:-- desc:今日是否已经签到true:已签到false:未签到
  40. */
  41. public function getUserInfo()
  42. {
  43. $uid = $this->uid;
  44. $user_info = Db::name('store_member')
  45. ->field('password,second_password',true)
  46. ->where('id',$uid)
  47. ->find();
  48. if(empty($user_info)) $this->error('用户信息不正确');
  49. $user_info['vip_name'] = $user_info['vip']==1 ? "藏友" : "创世勋章";
  50. //是否有待支付订单
  51. $order = Db::name('store_order')->where('status',0)->where('is_deleted',0)->where('mid',$uid)->count();
  52. $user_info['is_order_no_paid'] = $order ? true : false;
  53. //今日是否签到
  54. $date = date('Y-m-d');
  55. $sign = Db::name('store_member_sign')->where('mid',$uid)->where('date',$date)->count();
  56. $user_info['is_sign'] = $sign ? true : false;
  57. $this->success('获取成功',$user_info);
  58. }
  59. /**
  60. * @title 编辑个人信息
  61. * @desc 编辑个人信息
  62. * @author Gavin
  63. * @url /api/User_center/updateUserInfo
  64. * @method POST
  65. * @tag 编辑信息
  66. * @header name:Authorization require:1 desc:Token
  67. *
  68. * @param name:name type:string require:0 default:-- desc:姓名
  69. * @param name:headimg type:string require:0 default:-- desc:头像地址
  70. */
  71. public function updateUserInfo()
  72. {
  73. $headimg = input('post.headimg');
  74. $name = trim(input('post.name',''));
  75. if(!$headimg && !$name) $this->error('参数错误');
  76. $update_data= [];
  77. if($name) $update_data['name'] = $name;
  78. if ($headimg) $update_data['headimg'] = $headimg;
  79. if($name){
  80. $check_member = Db::name('store_member')
  81. ->where('name',$name)
  82. ->where('id','<>',$this->uid)
  83. ->count();
  84. if($check_member) $this->error('该用户名已被占用');
  85. }
  86. $update_data['update_at'] = date('Y-m-d H:i:s');
  87. if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){
  88. setMemberInfoHash($this->uid);
  89. $this->success('编辑成功');
  90. }
  91. $this->error('编辑失败');
  92. }
  93. /**
  94. * @title 实名认证
  95. * @desc 实名认证
  96. * @author Gavin
  97. * @method POST
  98. * @tag 编辑信息
  99. * @url /api/User_center/userCertification
  100. * @header name:Authorization require:1 desc:Token
  101. * @param name:true_name type:string require:1 default:-- desc:真实姓名
  102. * @param name:id_card type:string require:1 default:-- desc:身份证号
  103. */
  104. public function userCertification()
  105. {
  106. $true_name = input('post.true_name');
  107. $id_card = input('post.id_card');
  108. if (!$true_name || !$id_card) $this->error('参数错误');
  109. $check_id_card = isCreditNo($id_card);
  110. if (!$check_id_card) $this->error('身份证号格式错误');
  111. $is_auth = Db::table('store_member')->where('id',$this->uid)->value('is_auth');
  112. if($is_auth) $this->error('已认证');
  113. $check = Db::name('store_member')->where('id_card',$id_card)->count();
  114. if ($check) $this->error('身份证号已经认证过');
  115. if (Db::table('store_member')->where('id',$this->uid)->update(['is_auth'=>1,'true_name'=>$true_name,'id_card'=>$id_card,'auth_at'=>date('Y-m-d H:i:s')])){
  116. setMemberInfoHash($this->uid);
  117. $this->success('认证成功');
  118. }
  119. $this->error('认证失败');
  120. }
  121. /**
  122. * @title 修改密码
  123. * @desc 修改密码
  124. * @author Gavin
  125. * @method POST
  126. * @tag 编辑信息
  127. * @url /api/User_center/updatePass
  128. * @header name:Authorization require:1 desc:Token
  129. * @param name:old_password type:string require:1 default:-- desc:旧密码
  130. * @param name:new_password type:string require:1 default:-- desc:新密码
  131. * @param name:confirm_password type:string require:1 default:-- desc:确认密码
  132. */
  133. public function updatePass()
  134. {
  135. $old_password = input('post.old_password');
  136. $new_password = input('post.new_password');
  137. $confirm_password = input('post.confirm_password');
  138. if (!$old_password || !$new_password || !$confirm_password) $this->error('参数错误');
  139. if ($new_password!=$confirm_password) $this->error('密码与确认密码不一致');
  140. if (!preg_match('/^[0-9a-z]{6,12}$/i',$new_password)) $this->error('密码格式错误,请输入6-12位数字+字母');
  141. $member = Db::name('store_member')->where('id',$this->uid)->find();
  142. if ($member['password']!=md5($old_password)) $this->error('旧密码错误');
  143. $data['password'] = md5($new_password);
  144. $data['update_at'] = date('Y-m-d H:i:s');
  145. if (Db::name('store_member')->where('id',$this->uid)->update($data)){
  146. setMemberInfoHash($this->uid);
  147. $this->success('修改成功');
  148. }
  149. $this->error('修改失败');
  150. }
  151. /**
  152. * @title 修改二级密码
  153. * @desc 修改二级密码
  154. * @author Gavin
  155. * @method POST
  156. * @tag 编辑信息
  157. * @url /api/User_center/updateSecondPass
  158. * @header name:Authorization require:1 desc:Token
  159. * @param name:second_password type:string require:1 default:-- desc:二级密码
  160. * @param name:confirm_second_password type:string require:1 default:-- desc:确认密码
  161. */
  162. public function updateSecondPass()
  163. {
  164. $second_password = input('post.second_password');
  165. $confirm_second_password = input('post.confirm_second_password');
  166. if (!$second_password || !$confirm_second_password) $this->error('参数错误');
  167. if ($second_password!=$confirm_second_password) $this->error('密码与确认密码不一致');
  168. if (!preg_match('/^[0-9]{6}$/i',$second_password)) $this->error('二级密码格式错误,请输入6位纯数字');
  169. $data['second_password'] = md5($second_password);
  170. $data['update_at'] = date('Y-m-d H:i:s');
  171. if (Db::name('store_member')->where('id',$this->uid)->update($data)){
  172. setMemberInfoHash($this->uid);
  173. $this->success('修改成功');
  174. }
  175. $this->error('修改失败');
  176. }
  177. /**
  178. * @title 我的藏品
  179. * @desc 我的藏品
  180. * @author Gavin
  181. * @method POST
  182. * @tag 编辑信息
  183. * @url /api/User_center/myCollection
  184. * @header name:Authorization require:1 desc:Token
  185. *
  186. * @return name:id type:int require:0 default:0 desc:藏品ID
  187. * @return name:tag type:string require:0 default:0 desc:唯一标签
  188. * @return name:name type:string require:0 default:0 desc:藏品名称
  189. * @return name:cover type:string require:0 default:0 desc:藏品图片
  190. * @return name:auth_img type:string require:0 default:0 desc:作者头像
  191. * @return name:auth_name type:string require:0 default:0 desc:作者名称
  192. */
  193. public function myCollection(){
  194. $list = Db::name('store_order_info')
  195. ->where('mid',$this->uid)
  196. ->whereIn('status','1,3')
  197. ->field('id,tag,pro_info')
  198. ->order('id desc')
  199. ->select();
  200. foreach ($list as &$v){
  201. $pro_info = json_decode($v['pro_info'],true);
  202. $v['name'] = $pro_info['name'];
  203. $v['cover'] = $pro_info['cover'];
  204. $v['auth_img'] = $pro_info['auth_img'];
  205. $v['auth_name'] = $pro_info['auth_name'];
  206. unset($v['pro_info']);
  207. }
  208. $this->success('成功',$list);
  209. }
  210. /**
  211. * @title 藏品详情
  212. * @desc 藏品详情
  213. * @author Gavin
  214. * @method POST
  215. * @tag 编辑信息
  216. * @url /api/User_center/myCollectionDetail
  217. * @header name:Authorization require:1 desc:Token
  218. * @param name:id type:int require:1 default:-- desc:藏品ID
  219. *
  220. * @return name:id type:int require:0 default:0 desc:藏品ID
  221. * @return name:tag type:string require:0 default:0 desc:唯一标签
  222. * @return name:collectors_name type:string require:0 default:0 desc:收藏者
  223. * @return name:collectors_hash type:string require:0 default:0 desc:收藏者hash
  224. * @return name:create_at type:string require:0 default:0 desc:收藏时间
  225. * @return name:company type:string require:0 default:0 desc:流转公司
  226. * @return name:company_hash type:string require:0 default:0 desc:流转公司hash
  227. * @return name:examples_illustrate type:string require:0 default:0 desc:转赠说明
  228. * @return name:pro_info@name type:string require:0 default:0 desc:藏品名称
  229. * @return name:pro_info@price type:string require:0 default:0 desc:藏品价格
  230. * @return name:pro_info@label type:string require:0 default:0 desc:藏品标签
  231. * @return name:pro_info@cover type:string require:0 default:0 desc:藏品图片
  232. * @return name:pro_info@auth_img type:string require:0 default:0 desc:作者头像
  233. * @return name:pro_info@auth_name type:string require:0 default:0 desc:作者姓名
  234. * @return name:pro_info@warm_prompt type:string require:0 default:0 desc:温馨提示
  235. * @return name:pro_info@share_img type:string require:0 default:0 desc:分享二维码
  236. */
  237. public function myCollectionDetail(){
  238. $id = input('id');
  239. if (!$id) $this->error('参数错误');
  240. $info = Db::name('store_order_info')->where('id',$id)->find();
  241. if (!$info) $this->error('藏品不存在');
  242. $info['pro_info'] = json_decode($info['pro_info'],true);
  243. if (!isset($info['pro_info']['share_img'])){
  244. $info['pro_info']['share_img'] = Db::name('store_collection')->where('id',$info['pro_info']['id'])->value('share_img');
  245. }
  246. $info['collectors_name'] = Db::name('store_member')->where('id',$this->uid)->value('name');
  247. $info['collectors_hash'] = $info['collectors_hash']=='' ? "发放中" : $info['collectors_hash'];
  248. $info['collectors_hash_time'] = $info['collectors_hash_time']=='' ? "发放中" : $info['collectors_hash_time'];
  249. $info['examples_illustrate'] = Db::table('system_config')->where('name','examples_illustrate')->value('value');
  250. $this->success('成功',$info);
  251. }
  252. /**
  253. * @title 转赠
  254. * @desc 转赠
  255. * @author Gavin
  256. * @method POST
  257. * @tag 编辑信息
  258. * @url /api/User_center/examples
  259. * @header name:Authorization require:1 desc:Token
  260. * @param name:id type:int require:1 default:-- desc:藏品ID
  261. * @param name:phone type:string require:1 default:-- desc:手机号
  262. * @param name:wallet_address type:int require:1 default:-- desc:钱包地址
  263. * @param name:second_password type:int require:1 default:-- desc:二级密码
  264. *
  265. */
  266. public function examples(){
  267. $id = input('id');
  268. $phone = input('phone');
  269. $wallet_address = input('wallet_address');
  270. $second_password = input('second_password');
  271. if (!$id || !$phone || !$wallet_address) $this->error('参数错误');
  272. $info = Db::name('store_order_info')->where('id',$id)->find();
  273. if (!$info) $this->error('藏品不存在');
  274. if ($info['status']==2) $this->error('藏品已转赠');
  275. $member = Db::name('store_member')->where('phone',$phone)->where('wallet_address',$wallet_address)->find();
  276. if (!$member) $this->error('转赠用户不存在');
  277. $examples_number = Db::name('store_member')->where('id',$this->uid)->value('examples_number');
  278. $date = date('Y-m');
  279. $number = Db::name('store_collect_examples_log')
  280. ->where('mid',$this->uid)
  281. ->where('date',$date)
  282. ->count();
  283. //if ($number>=$examples_number) $this->error('转赠次数不足,无法转赠');
  284. if (!$info['collectors_hash']) $this->error('发放中,无法转赠');
  285. $mem = getMemberInfoHash($this->uid);
  286. if ($mem['second_password']!=md5($second_password)) $this->error('密码错误');
  287. $pro_info = json_decode($info['pro_info'],true);
  288. $log = Db::name('store_collect_examples_log')
  289. ->where('order_info_id',$id)
  290. ->count();
  291. if (!$log){
  292. if ($pro_info['one_given_day']!=0){
  293. $exam_time = strtotime($info['create_at'])+($pro_info['one_given_day']*24*60*60);
  294. if ($exam_time>time()) $this->error('持有时间限制,无法转赠');
  295. }
  296. }else{
  297. if ($pro_info['other_given_day']!=0){
  298. $exam_time = strtotime($info['create_at'])+($pro_info['other_given_day']*24*60*60);
  299. if ($exam_time>time()) $this->error('持有时间限制,无法转赠');
  300. }
  301. }
  302. if ($info['is_business']==0 || $info['is_gas']==0) $this->error('能量值/业务费不足,不能转赠');
  303. $com = true;
  304. Db::startTrans();
  305. try {
  306. Db::name('store_order_info')
  307. ->where('id',$id)
  308. ->update(['status'=>2,'over_time'=>date('Y-m-d H:i:s'),'to_mid'=>$member['id']]);
  309. $to_date = [
  310. 'order_id'=>$info['order_id'],
  311. 'order_no'=>get_order_sn(),
  312. 'tag'=>$info['tag'],
  313. 'mid'=>$member['id'],
  314. 'pro_info'=>$info['pro_info'],
  315. 'status'=>3,
  316. 'to_mid'=>$this->uid,
  317. 'over_time'=>date('Y-m-d H:i:s'),
  318. 'company'=>'象寻数字科技(上海)有限公司',
  319. 'company_hash'=>$info['company_hash'],
  320. 'company_hash_time'=>$info['company_hash_time'],
  321. 'ddcid'=>$info['ddcid'],
  322. 'collectors_hash'=>'',
  323. 'collectors_hash_time'=>date('Y-m-d H:i:s')
  324. ];
  325. Db::name('store_order_info')->insert($to_date);
  326. $log_date = [
  327. 'order_info_id'=>$id,
  328. 'mid'=>$this->uid,
  329. 'to_mid'=>$member['id'],
  330. 'date'=>date('Y-m')
  331. ];
  332. Db::name('store_collect_examples_log')->insert($log_date);
  333. Db::commit();
  334. }catch (\Exception $e){
  335. $com = false;
  336. Db::rollback();
  337. }
  338. if ($com){
  339. $this->success('转赠成功');
  340. }
  341. $this->error('转赠失败');
  342. }
  343. /**
  344. * @title 消息列表
  345. * @desc 消息列表
  346. * @author Gavin
  347. * @method POST
  348. * @tag 编辑信息
  349. * @url /api/User_center/messageList
  350. * @header name:Authorization require:1 desc:Token
  351. *
  352. * @param name:page type:int : default:1 desc:页数
  353. * @param name:page_num type:int : default:20 desc:每页数
  354. *
  355. * @return name:id type:int require:0 default:0 desc:消息ID
  356. * @return name:title type:string require:0 default:0 desc:标题
  357. * @return name:content type:string require:0 default:0 desc:内容
  358. * @return name:create_at type:string require:0 default:0 desc:发布时间
  359. * @return name:is_read type:string require:0 default:0 desc:是否查看true:已查看false:未查看
  360. */
  361. public function messageList(){
  362. $count = Db::name('store_message')->where('is_deleted',0)->count();
  363. $list = Db::name('store_message')
  364. ->field('is_deleted,update_at',true)
  365. ->where('is_deleted',0)
  366. ->order('id desc')
  367. ->limit($this->off_set,$this->page_num)
  368. ->select();
  369. // echo Db::name('store_message')->getLastSql();die;
  370. foreach ($list as &$v){
  371. $is_read = Db::name('store_message_read_log')->where('mid',$this->uid)->where('message_id',$v['id'])->count();
  372. $v['is_read'] = $is_read ? true : false;
  373. }
  374. $this->success('成功',compact('count','list'));
  375. }
  376. /**
  377. * @title 点击消息
  378. * @desc 点击消息,查看消息
  379. * @author Gavin
  380. * @method POST
  381. * @tag 编辑信息
  382. * @url /api/User_center/readMessage
  383. * @header name:Authorization require:1 desc:Token
  384. *
  385. * @param name:id type:int : default:1 desc:消息ID
  386. *
  387. */
  388. public function readMessage(){
  389. $id = input('id');
  390. if (!$id) $this->error('参数错误');
  391. $log = Db::name('store_message_read_log')->where('message_id',$id)->where('mid',$this->uid)->count();
  392. if (!$log){
  393. $data = [
  394. 'mid'=>$this->uid,
  395. 'message_id'=>$id
  396. ];
  397. Db::name('store_message_read_log')->insert($data);
  398. }
  399. $this->success('成功');
  400. }
  401. /**
  402. * @title 人脸认证sign
  403. * @desc 人脸认证sign
  404. * @author Gavin
  405. * @method POST
  406. * @tag 编辑信息
  407. * @url /api/User_center/getFaceSign
  408. * @header name:Authorization require:1 desc:Token
  409. *
  410. *
  411. * @param name:name type:string default:1 desc:姓名
  412. * @param name:idNo type:string default:1 desc:身份证号
  413. *
  414. * @return name:sign type:string require: default:-- desc:签名
  415. *
  416. */
  417. public function getFaceSign(){
  418. $name = input('name');
  419. $idNo = input('idNo');
  420. if (!$name || !$idNo) $this->error('参数错误');
  421. $userId = $this->uid;
  422. //$userId = get32Str();
  423. $data = getfaceid($name,$idNo,$userId);
  424. $this->success('成功',$data);
  425. }
  426. /**
  427. * @title 邀请记录
  428. * @desc 邀请记录
  429. * @author Gavin
  430. * @method POST
  431. * @tag 编辑信息
  432. * @url /api/User_center/invitedRecord
  433. * @header name:Authorization require:1 desc:Token
  434. *
  435. * @param name:page type:int : default:1 desc:页数
  436. * @param name:page_num type:int : default:20 desc:每页数
  437. *
  438. * @return name:id type:int require:0 default:0 desc:用户ID
  439. * @return name:headimg type:string require:0 default:0 desc:头像
  440. * @return name:name type:string require:0 default:0 desc:名称
  441. * @return name:create_at type:string require:0 default:0 desc:时间
  442. */
  443. public function invitedRecord(){
  444. $count = Db::name('store_member')->where('pid',$this->uid)->count();
  445. $list = Db::name('store_member')
  446. ->field('id,headimg,name,create_at')
  447. ->where('pid',$this->uid)
  448. ->order('id desc')
  449. ->limit($this->off_set,$this->page_num)
  450. ->select();
  451. $this->success('成功',compact('count','list'));
  452. }
  453. /**
  454. * @title 签到
  455. * @desc 签到
  456. * @author Gavin
  457. * @method POST
  458. * @tag 编辑信息
  459. * @url /api/User_center/sign
  460. * @header name:Authorization require:1 desc:Token
  461. *
  462. */
  463. public function sign(){
  464. $date = date('Y-m-d');
  465. $log = Db::name('store_member_sign')->where('mid',$this->uid)->where('date',$date)->count();
  466. if ($log) $this->error('今日已签到');
  467. $data = [
  468. 'mid'=>$this->uid,
  469. 'date'=>$date
  470. ];
  471. $com = true;
  472. Db::startTrans();
  473. try {
  474. $id = Db::name('store_member_sign')->insertGetId($data);
  475. $sign_integral = getConfigValue('sign_integral');
  476. if ($sign_integral>0){
  477. //memberMoneyChange($sign_integral,1,$this->uid,'签到',1,$id);
  478. }
  479. Db::commit();
  480. }catch (\Exception $e){
  481. $com=false;
  482. Db::rollback();
  483. }
  484. if ($com){
  485. $this->success('签到成功');
  486. }
  487. $this->error('签到失败');
  488. }
  489. /**
  490. * @title 积分记录
  491. * @desc 积分记录
  492. * @author Gavin
  493. * @method POST
  494. * @tag 编辑信息
  495. * @url /api/User_center/integralLog
  496. * @header name:Authorization require:1 desc:Token
  497. *
  498. * @param name:page type:int : default:1 desc:页数
  499. * @param name:page_num type:int : default:20 desc:每页数
  500. *
  501. * @return name:id type:int require:0 default:0 desc:id
  502. * @return name:change type:string require:0 default:0 desc:变动数值
  503. * @return name:title type:string require:0 default:0 desc:标题
  504. * @return name:create_at type:string require:0 default:0 desc:时间
  505. */
  506. public function integralLog(){
  507. $where = [
  508. 'm_id'=>$this->uid,
  509. 'type'=>1
  510. ];
  511. $count = Db::name('store_member_log')->where($where)->count();
  512. $list = Db::name('store_member_log')
  513. ->field('id,pm,change,title,create_at')
  514. ->where($where)
  515. ->order('id desc')
  516. ->limit($this->off_set,$this->page_num)
  517. ->select();
  518. foreach ($list as &$v){
  519. if ($v['pm']==1){
  520. $v['change'] = '+'.$v['change'];
  521. }else{
  522. $v['change'] = '-'.$v['change'];
  523. }
  524. }
  525. $this->success('成功',compact('count','list'));
  526. }
  527. }