UserCenter.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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 app\common\library\AliPay;
  7. use EasyWeChat\Factory;
  8. use think\Db;
  9. /**
  10. * @title 会员个人中心
  11. * @controller UserCenter
  12. * @group base
  13. */
  14. class UserCenter extends Base
  15. {
  16. public function initialize()
  17. {
  18. parent::initialize();
  19. parent::check_login();
  20. }
  21. /**
  22. * @title 获取个人信息
  23. * @desc 个人信息
  24. * @author Gavin
  25. * @url /api/User_center/getUserInfo
  26. * @method POST
  27. * @tag 个人信息
  28. * @header name:Authorization require:1 desc:Token
  29. * @return name:id type:int default:-- desc:ID(邀请ID)
  30. * @return name:phone type:string default:-- desc:手机号
  31. * @return name:name type:string default:-- desc:昵称
  32. * @return name:headimg type:string default:-- desc:头像地址
  33. * @return name:integral type:int default:-- desc:积分
  34. * @return name:snap_card type:int default:-- desc:抢购卡
  35. * @return name:wallet_address type:int default:-- desc:钱包地址
  36. * @return name:true_name type:string default:-- desc:真实姓名
  37. * @return name:id_card type:string default:-- desc:身份证号
  38. * @return name:is_auth type:int default:-- desc:是否认证(0否1是)
  39. * @return name:auth_at type:string default:-- desc:认证时间
  40. * @return name:vip_name type:int default:-- desc:身份
  41. * @return name:is_order_no_paid type:string default:-- desc:是否有未支付订单true:有false:没有
  42. * @return name:is_sign type:string default:-- desc:今日是否已经签到true:已签到false:未签到
  43. * @return name:invite_img type:string default:-- desc:邀请二维码
  44. * @return name:invite_address type:string default:-- desc:邀请地址
  45. */
  46. public function getUserInfo()
  47. {
  48. $uid = $this->uid;
  49. $user_info = Db::name('store_member')
  50. ->field('password,second_password',true)
  51. ->where('id',$uid)
  52. ->find();
  53. if(empty($user_info)) $this->error('用户信息不正确');
  54. $user_info['vip_name'] = $user_info['vip']==1 ? "藏友" : "创世勋章";
  55. //是否有待支付订单
  56. $order = Db::name('store_order')->where('status',0)->where('is_deleted',0)->where('mid',$uid)->count();
  57. $user_info['is_order_no_paid'] = $order ? true : false;
  58. //今日是否签到
  59. $date = date('Y-m-d');
  60. $sign = Db::name('store_member_sign')->where('mid',$uid)->where('date',$date)->count();
  61. $user_info['is_sign'] = $sign ? true : false;
  62. $this->success('获取成功',$user_info);
  63. }
  64. /**
  65. * @title 编辑个人信息
  66. * @desc 编辑个人信息
  67. * @author Gavin
  68. * @url /api/User_center/updateUserInfo
  69. * @method POST
  70. * @tag 编辑信息
  71. * @header name:Authorization require:1 desc:Token
  72. *
  73. * @param name:name type:string require:0 default:-- desc:姓名
  74. * @param name:headimg type:string require:0 default:-- desc:头像地址
  75. */
  76. public function updateUserInfo()
  77. {
  78. $headimg = input('post.headimg');
  79. $name = trim(input('post.name',''));
  80. if(!$headimg && !$name) $this->error('参数错误');
  81. $update_data= [];
  82. if($name) $update_data['name'] = $name;
  83. if ($headimg) $update_data['headimg'] = $headimg;
  84. if($name){
  85. $check_member = Db::name('store_member')
  86. ->where('name',$name)
  87. ->where('id','<>',$this->uid)
  88. ->count();
  89. if($check_member) $this->error('该用户名已被占用');
  90. }
  91. $update_data['update_at'] = date('Y-m-d H:i:s');
  92. if (Db::name('store_member')->where('id',$this->uid)->update($update_data)){
  93. setMemberInfoHash($this->uid);
  94. $this->success('编辑成功');
  95. }
  96. $this->error('编辑失败');
  97. }
  98. /**
  99. * @title 实名认证
  100. * @desc 实名认证
  101. * @author Gavin
  102. * @method POST
  103. * @tag 编辑信息
  104. * @url /api/User_center/userCertification
  105. * @header name:Authorization require:1 desc:Token
  106. * @param name:true_name type:string require:1 default:-- desc:真实姓名
  107. * @param name:id_card type:string require:1 default:-- desc:身份证号
  108. */
  109. public function userCertification()
  110. {
  111. $true_name = input('post.true_name');
  112. $id_card = input('post.id_card');
  113. if (!$true_name || !$id_card) $this->error('参数错误');
  114. $check_id_card = isCreditNo($id_card);
  115. if (!$check_id_card) $this->error('身份证号格式错误');
  116. $is_auth = Db::table('store_member')->where('id',$this->uid)->value('is_auth');
  117. if($is_auth) $this->error('已认证');
  118. $check = Db::name('store_member')->where('id_card',$id_card)->count();
  119. if ($check) $this->error('身份证号已经认证过');
  120. 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')])){
  121. setMemberInfoHash($this->uid);
  122. $this->success('认证成功');
  123. }
  124. $this->error('认证失败');
  125. }
  126. /**
  127. * @title 修改密码
  128. * @desc 修改密码
  129. * @author Gavin
  130. * @method POST
  131. * @tag 编辑信息
  132. * @url /api/User_center/updatePass
  133. * @header name:Authorization require:1 desc:Token
  134. * @param name:old_password type:string require:1 default:-- desc:旧密码
  135. * @param name:new_password type:string require:1 default:-- desc:新密码
  136. * @param name:confirm_password type:string require:1 default:-- desc:确认密码
  137. */
  138. public function updatePass()
  139. {
  140. $old_password = input('post.old_password');
  141. $new_password = input('post.new_password');
  142. $confirm_password = input('post.confirm_password');
  143. if (!$old_password || !$new_password || !$confirm_password) $this->error('参数错误');
  144. if ($new_password!=$confirm_password) $this->error('密码与确认密码不一致');
  145. if (!preg_match('/^[0-9a-z]{6,12}$/i',$new_password)) $this->error('密码格式错误,请输入6-12位数字+字母');
  146. $member = Db::name('store_member')->where('id',$this->uid)->find();
  147. if ($member['password']!=md5($old_password)) $this->error('旧密码错误');
  148. $data['password'] = md5($new_password);
  149. $data['update_at'] = date('Y-m-d H:i:s');
  150. if (Db::name('store_member')->where('id',$this->uid)->update($data)){
  151. setMemberInfoHash($this->uid);
  152. $this->success('修改成功');
  153. }
  154. $this->error('修改失败');
  155. }
  156. /**
  157. * @title 修改二级密码
  158. * @desc 修改二级密码
  159. * @author Gavin
  160. * @method POST
  161. * @tag 编辑信息
  162. * @url /api/User_center/updateSecondPass
  163. * @header name:Authorization require:1 desc:Token
  164. * @param name:second_password type:string require:1 default:-- desc:二级密码
  165. * @param name:confirm_second_password type:string require:1 default:-- desc:确认密码
  166. */
  167. public function updateSecondPass()
  168. {
  169. $second_password = input('post.second_password');
  170. $confirm_second_password = input('post.confirm_second_password');
  171. if (!$second_password || !$confirm_second_password) $this->error('参数错误');
  172. if ($second_password!=$confirm_second_password) $this->error('密码与确认密码不一致');
  173. if (!preg_match('/^[0-9]{6}$/i',$second_password)) $this->error('二级密码格式错误,请输入6位纯数字');
  174. $data['second_password'] = md5($second_password);
  175. $data['update_at'] = date('Y-m-d H:i:s');
  176. if (Db::name('store_member')->where('id',$this->uid)->update($data)){
  177. setMemberInfoHash($this->uid);
  178. $this->success('修改成功');
  179. }
  180. $this->error('修改失败');
  181. }
  182. /**
  183. * @title 我的藏品
  184. * @desc 我的藏品
  185. * @author Gavin
  186. * @method POST
  187. * @tag 编辑信息
  188. * @url /api/User_center/myCollection
  189. * @header name:Authorization require:1 desc:Token
  190. *
  191. * @return name:id type:int require:0 default:0 desc:藏品ID
  192. * @return name:tag type:string require:0 default:0 desc:唯一标签
  193. * @return name:name type:string require:0 default:0 desc:藏品名称
  194. * @return name:cover type:string require:0 default:0 desc:藏品图片
  195. * @return name:auth_img type:string require:0 default:0 desc:作者头像
  196. * @return name:auth_name type:string require:0 default:0 desc:作者名称
  197. */
  198. public function myCollection(){
  199. $list = Db::name('store_order_info')
  200. ->where('mid',$this->uid)
  201. ->whereIn('status','1,3')
  202. ->field('id,tag,pro_info')
  203. ->order('id desc')
  204. ->select();
  205. foreach ($list as &$v){
  206. $pro_info = json_decode($v['pro_info'],true);
  207. $v['name'] = $pro_info['name'];
  208. $v['cover'] = $pro_info['cover'];
  209. $v['auth_img'] = $pro_info['auth_img'];
  210. $v['auth_name'] = $pro_info['auth_name'];
  211. unset($v['pro_info']);
  212. }
  213. $this->success('成功',$list);
  214. }
  215. /**
  216. * @title 藏品详情
  217. * @desc 藏品详情
  218. * @author Gavin
  219. * @method POST
  220. * @tag 编辑信息
  221. * @url /api/User_center/myCollectionDetail
  222. * @header name:Authorization require:1 desc:Token
  223. * @param name:id type:int require:1 default:-- desc:藏品ID
  224. *
  225. * @return name:id type:int require:0 default:0 desc:藏品ID
  226. * @return name:tag type:string require:0 default:0 desc:唯一标签
  227. * @return name:collectors_name type:string require:0 default:0 desc:收藏者
  228. * @return name:collectors_hash type:string require:0 default:0 desc:收藏者hash
  229. * @return name:create_at type:string require:0 default:0 desc:收藏时间
  230. * @return name:company type:string require:0 default:0 desc:流转公司
  231. * @return name:company_hash type:string require:0 default:0 desc:流转公司hash
  232. * @return name:examples_illustrate type:string require:0 default:0 desc:转赠说明
  233. * @return name:pro_info@name type:string require:0 default:0 desc:藏品名称
  234. * @return name:pro_info@price type:string require:0 default:0 desc:藏品价格
  235. * @return name:pro_info@label type:string require:0 default:0 desc:藏品标签
  236. * @return name:pro_info@cover type:string require:0 default:0 desc:藏品图片
  237. * @return name:pro_info@auth_img type:string require:0 default:0 desc:作者头像
  238. * @return name:pro_info@auth_name type:string require:0 default:0 desc:作者姓名
  239. * @return name:pro_info@warm_prompt type:string require:0 default:0 desc:温馨提示
  240. * @return name:pro_info@share_img type:string require:0 default:0 desc:分享二维码
  241. */
  242. public function myCollectionDetail(){
  243. $id = input('id');
  244. if (!$id) $this->error('参数错误');
  245. $info = Db::name('store_order_info')->where('id',$id)->find();
  246. if (!$info) $this->error('藏品不存在');
  247. $info['pro_info'] = json_decode($info['pro_info'],true);
  248. if (!isset($info['pro_info']['share_img'])){
  249. $info['pro_info']['share_img'] = Db::name('store_collection')->where('id',$info['pro_info']['id'])->value('share_img');
  250. }
  251. $info['collectors_name'] = Db::name('store_member')->where('id',$this->uid)->value('name');
  252. $info['collectors_hash'] = $info['collectors_hash']=='' ? "发放中" : $info['collectors_hash'];
  253. $info['collectors_hash_time'] = $info['collectors_hash_time']=='' ? "发放中" : $info['collectors_hash_time'];
  254. $info['examples_illustrate'] = Db::table('system_config')->where('name','examples_illustrate')->value('value');
  255. $this->success('成功',$info);
  256. }
  257. /**
  258. * @title 转赠
  259. * @desc 转赠
  260. * @author Gavin
  261. * @method POST
  262. * @tag 编辑信息
  263. * @url /api/User_center/examples
  264. * @header name:Authorization require:1 desc:Token
  265. * @param name:id type:int require:1 default:-- desc:藏品ID
  266. * @param name:phone type:string require:1 default:-- desc:手机号
  267. * @param name:wallet_address type:int require:1 default:-- desc:钱包地址
  268. * @param name:second_password type:int require:1 default:-- desc:二级密码
  269. *
  270. */
  271. public function examples(){
  272. $id = input('id');
  273. $phone = input('phone');
  274. $wallet_address = input('wallet_address');
  275. $second_password = input('second_password');
  276. if (!$id || !$phone || !$wallet_address) $this->error('参数错误');
  277. $info = Db::name('store_order_info')->where('id',$id)->find();
  278. if (!$info) $this->error('藏品不存在');
  279. if ($info['status']==2) $this->error('藏品已转赠');
  280. $member = Db::name('store_member')->where('phone',$phone)->where('wallet_address',$wallet_address)->find();
  281. if (!$member) $this->error('转赠用户不存在');
  282. $examples_number = Db::name('store_member')->where('id',$this->uid)->value('examples_number');
  283. $date = date('Y-m');
  284. $number = Db::name('store_collect_examples_log')
  285. ->where('mid',$this->uid)
  286. ->where('date',$date)
  287. ->count();
  288. //if ($number>=$examples_number) $this->error('转赠次数不足,无法转赠');
  289. if (!$info['collectors_hash']) $this->error('发放中,无法转赠');
  290. $mem = getMemberInfoHash($this->uid);
  291. if ($mem['second_password']!=md5($second_password)) $this->error('密码错误');
  292. if ($mem['id']==$member['id']) $this->error('无法转给自己');
  293. //$pro_info = json_decode($info['pro_info'],true);
  294. $pro_info = Db::name('store_collection')->where('id',$info['c_id'])->find();
  295. $log = Db::name('store_collect_examples_log')
  296. ->where('order_info_id',$id)
  297. ->find();
  298. if (!$log){
  299. if ($pro_info['one_given_day']!=0){
  300. $exam_time = strtotime($info['create_at'])+($pro_info['one_given_day']*24*60*60);
  301. if ($exam_time>time()) $this->error('持有时间限制,无法转赠');
  302. }
  303. }else{
  304. if ($pro_info['other_given_day']!=0){
  305. $exam_time = strtotime($log['create_at'])+($pro_info['other_given_day']*24*60*60);
  306. if ($exam_time>time()) $this->error('持有时间限制,无法转赠');
  307. }
  308. }
  309. if ($info['is_business']==0 || $info['is_gas']==0){
  310. $recharge_address = $mem['wallet_address'];
  311. $data = [];
  312. if ($info['is_business']==0){
  313. //授权平台
  314. $rand = get_order_sn();
  315. $money = '30';
  316. $url = "http://192.144.219.204:8083/ddc/rechargeBusiness?money=$money&address=$recharge_address&transSn=".$rand;
  317. $res=curlRequest($url);
  318. $result = json_decode($res,true);
  319. if (isset($result['code']) && $result['code']==0){
  320. $data['is_business'] = 1;
  321. $data['business'] = $money;
  322. }else{
  323. $this->error('充值失败,请稍后再试');
  324. }
  325. }
  326. if ($info['is_gas']==0){
  327. $rand2 = get_order_sn();
  328. $money2 = '40';
  329. $url2 = "http://192.144.219.204:8083/ddc/rechargeGas?money=$money2&address=$recharge_address&transSn=".$rand2;
  330. $res2=curlRequest($url2);
  331. $result2 = json_decode($res2,true);
  332. if (isset($result2['code']) && $result2['code']==0){
  333. $data['is_gas'] = 1;
  334. $data['gas'] = $money2;
  335. }else{
  336. $this->error('充值失败,请稍后再试');
  337. }
  338. }
  339. if ($data){
  340. Db::name('store_order_info')->where('id',$id)->update($data);
  341. }
  342. //$this->error('能量值/业务费不足,不能转赠');
  343. }
  344. $com = true;
  345. Db::startTrans();
  346. try {
  347. Db::name('store_order_info')
  348. ->where('id',$id)
  349. ->update(['status'=>2,'over_time'=>date('Y-m-d H:i:s'),'to_mid'=>$member['id']]);
  350. $to_date = [
  351. 'order_id'=>$info['order_id'],
  352. 'order_no'=>get_order_sn(),
  353. 'tag'=>$info['tag'],
  354. 'mid'=>$member['id'],
  355. 'c_id'=>$info['c_id'],
  356. 'pro_info'=>$info['pro_info'],
  357. 'status'=>3,
  358. 'to_mid'=>$this->uid,
  359. 'over_time'=>date('Y-m-d H:i:s'),
  360. 'company'=>'象寻数字科技(上海)有限公司',
  361. 'company_hash'=>$info['company_hash'],
  362. 'company_hash_time'=>$info['company_hash_time'],
  363. 'ddcid'=>$info['ddcid'],
  364. 'collectors_hash'=>'',
  365. 'collectors_hash_time'=>date('Y-m-d H:i:s'),
  366. 'type'=>$info['type']
  367. ];
  368. Db::name('store_order_info')->insert($to_date);
  369. $log_date = [
  370. 'order_info_id'=>$id,
  371. 'mid'=>$this->uid,
  372. 'to_mid'=>$member['id'],
  373. 'date'=>date('Y-m')
  374. ];
  375. Db::name('store_collect_examples_log')->insert($log_date);
  376. Db::commit();
  377. }catch (\Exception $e){
  378. $com = false;
  379. Db::rollback();
  380. }
  381. if ($com){
  382. $this->success('转赠成功');
  383. }
  384. $this->error('转赠失败');
  385. }
  386. /**
  387. * @title 消息列表
  388. * @desc 消息列表
  389. * @author Gavin
  390. * @method POST
  391. * @tag 编辑信息
  392. * @url /api/User_center/messageList
  393. * @header name:Authorization require:1 desc:Token
  394. *
  395. * @param name:page type:int : default:1 desc:页数
  396. * @param name:page_num type:int : default:20 desc:每页数
  397. *
  398. * @return name:id type:int require:0 default:0 desc:消息ID
  399. * @return name:title type:string require:0 default:0 desc:标题
  400. * @return name:content type:string require:0 default:0 desc:内容
  401. * @return name:create_at type:string require:0 default:0 desc:发布时间
  402. * @return name:is_read type:string require:0 default:0 desc:是否查看true:已查看false:未查看
  403. */
  404. public function messageList(){
  405. $count = Db::name('store_message')->where('is_deleted',0)->count();
  406. $list = Db::name('store_message')
  407. ->field('is_deleted,update_at',true)
  408. ->where('is_deleted',0)
  409. ->order('id desc')
  410. ->limit($this->off_set,$this->page_num)
  411. ->select();
  412. // echo Db::name('store_message')->getLastSql();die;
  413. foreach ($list as &$v){
  414. $is_read = Db::name('store_message_read_log')->where('mid',$this->uid)->where('message_id',$v['id'])->count();
  415. $v['is_read'] = $is_read ? true : false;
  416. }
  417. $this->success('成功',compact('count','list'));
  418. }
  419. /**
  420. * @title 点击消息
  421. * @desc 点击消息,查看消息
  422. * @author Gavin
  423. * @method POST
  424. * @tag 编辑信息
  425. * @url /api/User_center/readMessage
  426. * @header name:Authorization require:1 desc:Token
  427. *
  428. * @param name:id type:int : default:1 desc:消息ID
  429. *
  430. */
  431. public function readMessage(){
  432. $id = input('id');
  433. if (!$id) $this->error('参数错误');
  434. $log = Db::name('store_message_read_log')->where('message_id',$id)->where('mid',$this->uid)->count();
  435. if (!$log){
  436. $data = [
  437. 'mid'=>$this->uid,
  438. 'message_id'=>$id
  439. ];
  440. Db::name('store_message_read_log')->insert($data);
  441. }
  442. $this->success('成功');
  443. }
  444. /**
  445. * @title 人脸认证sign
  446. * @desc 人脸认证sign
  447. * @author Gavin
  448. * @method POST
  449. * @tag 编辑信息
  450. * @url /api/User_center/getFaceSign
  451. * @header name:Authorization require:1 desc:Token
  452. *
  453. *
  454. * @param name:name type:string default:1 desc:姓名
  455. * @param name:idNo type:string default:1 desc:身份证号
  456. *
  457. * @return name:sign type:string require: default:-- desc:签名
  458. *
  459. */
  460. public function getFaceSign(){
  461. $name = input('name');
  462. $idNo = input('idNo');
  463. if (!$name || !$idNo) $this->error('参数错误');
  464. $userId = $this->uid;
  465. //$userId = get32Str();
  466. $data = getfaceid($name,$idNo,$userId);
  467. $this->success('成功',$data);
  468. }
  469. /**
  470. * @title 邀请记录
  471. * @desc 邀请记录
  472. * @author Gavin
  473. * @method POST
  474. * @tag 编辑信息
  475. * @url /api/User_center/invitedRecord
  476. * @header name:Authorization require:1 desc:Token
  477. *
  478. * @param name:page type:int : default:1 desc:页数
  479. * @param name:page_num type:int : default:20 desc:每页数
  480. *
  481. * @return name:id type:int require:0 default:0 desc:用户ID
  482. * @return name:headimg type:string require:0 default:0 desc:头像
  483. * @return name:name type:string require:0 default:0 desc:名称
  484. * @return name:create_at type:string require:0 default:0 desc:时间
  485. */
  486. public function invitedRecord(){
  487. $count = Db::name('store_member')->where('pid',$this->uid)->count();
  488. $list = Db::name('store_member')
  489. ->field('id,headimg,name,create_at')
  490. ->where('pid',$this->uid)
  491. ->order('id desc')
  492. ->limit($this->off_set,$this->page_num)
  493. ->select();
  494. $this->success('成功',compact('count','list'));
  495. }
  496. /**
  497. * @title 签到
  498. * @desc 签到
  499. * @author Gavin
  500. * @method POST
  501. * @tag 编辑信息
  502. * @url /api/User_center/sign
  503. * @header name:Authorization require:1 desc:Token
  504. *
  505. */
  506. public function sign(){
  507. $date = date('Y-m-d');
  508. $log = Db::name('store_member_sign')->where('mid',$this->uid)->where('date',$date)->count();
  509. if ($log) $this->error('今日已签到');
  510. $data = [
  511. 'mid'=>$this->uid,
  512. 'date'=>$date
  513. ];
  514. $com = true;
  515. Db::startTrans();
  516. try {
  517. $id = Db::name('store_member_sign')->insertGetId($data);
  518. $sign_integral = getConfigValue('sign_integral');
  519. if ($sign_integral>0){
  520. memberMoneyChange($sign_integral,1,$this->uid,'签到',1,$id);
  521. }
  522. Db::commit();
  523. }catch (\Exception $e){
  524. $com=false;
  525. Db::rollback();
  526. }
  527. if ($com){
  528. $this->success('签到成功');
  529. }
  530. $this->error('签到失败');
  531. }
  532. /**
  533. * @title 积分记录
  534. * @desc 积分记录
  535. * @author Gavin
  536. * @method POST
  537. * @tag 编辑信息
  538. * @url /api/User_center/integralLog
  539. * @header name:Authorization require:1 desc:Token
  540. *
  541. * @param name:page type:int : default:1 desc:页数
  542. * @param name:page_num type:int : default:20 desc:每页数
  543. *
  544. * @return name:id type:int require:0 default:0 desc:id
  545. * @return name:change type:string require:0 default:0 desc:变动数值
  546. * @return name:title type:string require:0 default:0 desc:标题
  547. * @return name:create_at type:string require:0 default:0 desc:时间
  548. */
  549. public function integralLog(){
  550. $where = [
  551. 'm_id'=>$this->uid,
  552. 'type'=>1
  553. ];
  554. $count = Db::name('store_member_log')->where($where)->count();
  555. $list = Db::name('store_member_log')
  556. ->field('id,pm,change,title,create_at')
  557. ->where($where)
  558. ->order('id desc')
  559. ->limit($this->off_set,$this->page_num)
  560. ->select();
  561. foreach ($list as &$v){
  562. if ($v['pm']==1){
  563. $v['change'] = '+'.$v['change'];
  564. }else{
  565. $v['change'] = '-'.$v['change'];
  566. }
  567. }
  568. $this->success('成功',compact('count','list'));
  569. }
  570. /**
  571. * @title 钱包
  572. * @desc 钱包
  573. * @author M
  574. * @method POST
  575. * @url /api/User_center/wallet
  576. * @header name:Authorization require:1 desc:Token
  577. *
  578. * @param name:page type:int : default:1 desc:页数
  579. * @param name:page_num type:int : default:20 desc:每页数
  580. *
  581. * @return name:money type:int require:0 default:0 desc:余额
  582. * @return name:list@change type:string require:0 default:0 desc:变动金额
  583. * @return name:list@reason type:string require:0 default:0 desc:变动说明
  584. * @return name:list@time type:string require:0 default:0 desc:变动时间
  585. */
  586. public function wallet(){
  587. $uid = $this->uid;
  588. $user_info = Db::name('store_member')
  589. ->field('money')
  590. ->where('id',$uid)
  591. ->find();
  592. if(empty($user_info)) $this->error('用户信息不正确');
  593. $list = Db::name('system_money_record')
  594. ->field('id,pm,change,reason,time')
  595. ->where('mem_id',$uid)
  596. ->order('time desc')
  597. ->limit($this->off_set,$this->page_num)
  598. ->select();
  599. foreach ($list as &$v){
  600. if ($v['pm']==1){
  601. $v['change'] = '+'.$v['change'];
  602. }else{
  603. $v['change'] = '-'.$v['change'];
  604. }
  605. $v['time'] = date('Y-m-d H:i:s',$v['time']);
  606. }
  607. $user_info['list'] = $list;
  608. $this->success('获取成功',$user_info);
  609. }
  610. /**
  611. * @title 充值页面
  612. * @desc 充值页面
  613. * @author M
  614. * @method POST
  615. * @url /api/User_center/recharge
  616. * @header name:Authorization require:1 desc:Token
  617. *
  618. * @return name:money type:int require:0 default:0 desc:余额
  619. * @return name:pay_way@img type:string require:0 default:0 desc:支付方式logo
  620. * @return name:pay_way@name type:string require:0 default:0 desc:支付方式
  621. * @return name:pay_way@code type:string require:0 default:0 desc:支付方式code
  622. */
  623. public function recharge(){
  624. $uid = $this->uid;
  625. $user_info = Db::name('store_member')
  626. ->field('money')
  627. ->where('id',$uid)
  628. ->find();
  629. if(empty($user_info)) $this->error('用户信息不正确');
  630. $detail['money'] = $user_info['money'];
  631. $list = Db::name('SystemPayWay')->where('status = 1 and code != "yue"')->field('img,name,code')->select();
  632. $detail['pay_way'] = $list;
  633. $this->success('获取成功',$detail);
  634. }
  635. /**
  636. * @title 提交充值
  637. * @desc 提交充值
  638. * @author M
  639. * @method POST
  640. * @url /api/User_center/toRecharge
  641. * @header name:Authorization require:1 desc:Token
  642. *
  643. * @param name:money type:int require:1 default:0.01 desc:充值金额
  644. * @param name:pay_way type:string require:1 default:-- desc:支付方式
  645. *
  646. * @return name:order_no type:int require:0 default:0 desc:订单号
  647. * @return name:pay type:string require:0 default:0 desc:支付信息
  648. */
  649. public function toRecharge(){
  650. $data = $this->request->post();
  651. $param_arr = [
  652. 'money'=>'请输入充值金额',
  653. 'pay_way'=>'请选择支付方式',
  654. ];
  655. foreach ($param_arr as $key=>$v){
  656. if(!isset($data[$key]) || $data[$key] == ''){
  657. $this->error($v);
  658. }
  659. }
  660. $uid = $this->uid;
  661. if($data['money'] <= 0) $this->error('充值数量不能小于0');
  662. $order['number'] = get_order_sn();
  663. $order['money'] = $data['money'];
  664. $order['need_pay'] = $data['money'];
  665. $order['mem_id'] = $uid;
  666. $order['time'] = time();
  667. $re_id = Db::name('SystemRecharge')->insertGetId($order);
  668. if($re_id){
  669. $body = '象寻在线充值';
  670. $order_no = $order['number'];
  671. $total_fee = $data['money'];
  672. switch ($data['pay_way']) {
  673. case 'wx':
  674. $config = retrunWxConfig();
  675. $total_fee = $total_fee * 100;
  676. $config['notify_url'] = $this->request->root(true).'/api/Pay/WxRechargeNotify';
  677. $app = Factory::payment($config);
  678. $result = $app->order->unify([
  679. 'body' => $body,
  680. 'out_trade_no' => $order_no,
  681. 'total_fee' => $total_fee,
  682. 'trade_type' => 'APP', // 请对应换成你的支付方式对应的值类型
  683. ]);
  684. if ($result['return_code']=='SUCCESS'){
  685. $jssdk = $app->jssdk;
  686. $order1 = $jssdk->appConfig($result['prepay_id']);
  687. $retrun_data['order_no'] = $order_no;
  688. $retrun_data['pay'] = $order1;
  689. }else{
  690. $this->error('调用微信支付失败');
  691. }
  692. break;
  693. case 'zfb':
  694. $zfb = new AliPay();
  695. $notify_url = $this->request->root(true).'/api/Pay/alipayRechargeNotify';//回调地址
  696. $order = $zfb->aliPay($body, $total_fee, $order_no, $notify_url);//调用支付宝支付的方法
  697. $retrun_data['order_no'] = $order_no;
  698. $retrun_data['pay'] = $order;
  699. break;
  700. case 'apple':
  701. $retrun_data['order_no'] = $order_no;
  702. $retrun_data['pay'] = ['order_no'=>$order_no];
  703. break;
  704. default:
  705. $this->error('支付方式错误');
  706. }
  707. $this->success('成功',$retrun_data);
  708. }else{
  709. $this->error('充值失败');
  710. }
  711. }
  712. }