UserCenter.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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. $this->error('系统升级中...');
  273. $id = input('id');
  274. $phone = input('phone');
  275. $wallet_address = input('wallet_address');
  276. $second_password = input('second_password');
  277. if (!$id || !$phone || !$wallet_address) $this->error('参数错误');
  278. $info = Db::name('store_order_info')->where('id',$id)->find();
  279. if (!$info) $this->error('藏品不存在');
  280. if ($info['status']==2) $this->error('藏品已转赠');
  281. $member = Db::name('store_member')->where('phone',$phone)->where('wallet_address',$wallet_address)->find();
  282. if (!$member) $this->error('转赠用户不存在');
  283. $examples_number = Db::name('store_member')->where('id',$this->uid)->value('examples_number');
  284. $date = date('Y-m');
  285. $number = Db::name('store_collect_examples_log')
  286. ->where('mid',$this->uid)
  287. ->where('date',$date)
  288. ->count();
  289. //if ($number>=$examples_number) $this->error('转赠次数不足,无法转赠');
  290. if (!$info['collectors_hash']) $this->error('发放中,无法转赠');
  291. $mem = getMemberInfoHash($this->uid);
  292. if ($mem['second_password']!=md5($second_password)) $this->error('密码错误');
  293. if ($mem['id']==$member['id']) $this->error('无法转给自己');
  294. //$pro_info = json_decode($info['pro_info'],true);
  295. $pro_info = Db::name('store_collection')->where('id',$info['c_id'])->find();
  296. $log = Db::name('store_collect_examples_log')
  297. ->where('order_info_id',$id)
  298. ->find();
  299. if (!$log){
  300. if ($pro_info['one_given_day']!=0){
  301. $exam_time = strtotime($info['create_at'])+($pro_info['one_given_day']*24*60*60);
  302. if ($exam_time>time()) $this->error('持有时间限制,无法转赠');
  303. }
  304. }else{
  305. if ($pro_info['other_given_day']!=0){
  306. $exam_time = strtotime($log['create_at'])+($pro_info['other_given_day']*24*60*60);
  307. if ($exam_time>time()) $this->error('持有时间限制,无法转赠');
  308. }
  309. }
  310. if ($info['is_business']==0 || $info['is_gas']==0){
  311. $recharge_address = $mem['wallet_address'];
  312. $data = [];
  313. if ($info['is_business']==0){
  314. //授权平台
  315. $rand = get_order_sn();
  316. $money = '30';
  317. $url = "http://192.144.219.204:8083/ddc/rechargeBusiness?money=$money&address=$recharge_address&transSn=".$rand;
  318. $res=curlRequest($url);
  319. $result = json_decode($res,true);
  320. if (isset($result['code']) && $result['code']==0){
  321. $data['is_business'] = 1;
  322. $data['business'] = $money;
  323. }else{
  324. $this->error('充值失败,请稍后再试');
  325. }
  326. }
  327. if ($info['is_gas']==0){
  328. $rand2 = get_order_sn();
  329. $money2 = '40';
  330. $url2 = "http://192.144.219.204:8083/ddc/rechargeGas?money=$money2&address=$recharge_address&transSn=".$rand2;
  331. $res2=curlRequest($url2);
  332. $result2 = json_decode($res2,true);
  333. if (isset($result2['code']) && $result2['code']==0){
  334. $data['is_gas'] = 1;
  335. $data['gas'] = $money2;
  336. }else{
  337. $this->error('充值失败,请稍后再试');
  338. }
  339. }
  340. if ($data){
  341. Db::name('store_order_info')->where('id',$id)->update($data);
  342. }
  343. //$this->error('能量值/业务费不足,不能转赠');
  344. }
  345. $com = true;
  346. Db::startTrans();
  347. try {
  348. Db::name('store_order_info')
  349. ->where('id',$id)
  350. ->update(['status'=>2,'over_time'=>date('Y-m-d H:i:s'),'to_mid'=>$member['id']]);
  351. $to_date = [
  352. 'order_id'=>$info['order_id'],
  353. 'order_no'=>get_order_sn(),
  354. 'tag'=>$info['tag'],
  355. 'mid'=>$member['id'],
  356. 'c_id'=>$info['c_id'],
  357. 'pro_info'=>$info['pro_info'],
  358. 'status'=>3,
  359. 'to_mid'=>$this->uid,
  360. 'over_time'=>date('Y-m-d H:i:s'),
  361. 'company'=>'象寻数字科技(上海)有限公司',
  362. 'company_hash'=>$info['company_hash'],
  363. 'company_hash_time'=>$info['company_hash_time'],
  364. 'ddcid'=>$info['ddcid'],
  365. 'collectors_hash'=>'',
  366. 'collectors_hash_time'=>date('Y-m-d H:i:s'),
  367. 'type'=>$info['type']
  368. ];
  369. Db::name('store_order_info')->insert($to_date);
  370. $log_date = [
  371. 'order_info_id'=>$id,
  372. 'mid'=>$this->uid,
  373. 'to_mid'=>$member['id'],
  374. 'date'=>date('Y-m')
  375. ];
  376. Db::name('store_collect_examples_log')->insert($log_date);
  377. Db::commit();
  378. }catch (\Exception $e){
  379. $com = false;
  380. Db::rollback();
  381. }
  382. if ($com){
  383. $this->success('转赠成功');
  384. }
  385. $this->error('转赠失败');
  386. }
  387. /**
  388. * @title 消息列表
  389. * @desc 消息列表
  390. * @author Gavin
  391. * @method POST
  392. * @tag 编辑信息
  393. * @url /api/User_center/messageList
  394. * @header name:Authorization require:1 desc:Token
  395. *
  396. * @param name:page type:int : default:1 desc:页数
  397. * @param name:page_num type:int : default:20 desc:每页数
  398. *
  399. * @return name:id type:int require:0 default:0 desc:消息ID
  400. * @return name:title type:string require:0 default:0 desc:标题
  401. * @return name:content type:string require:0 default:0 desc:内容
  402. * @return name:create_at type:string require:0 default:0 desc:发布时间
  403. * @return name:is_read type:string require:0 default:0 desc:是否查看true:已查看false:未查看
  404. */
  405. public function messageList(){
  406. $count = Db::name('store_message')->where('is_deleted',0)->count();
  407. $list = Db::name('store_message')
  408. ->field('is_deleted,update_at',true)
  409. ->where('is_deleted',0)
  410. ->order('id desc')
  411. ->limit($this->off_set,$this->page_num)
  412. ->select();
  413. // echo Db::name('store_message')->getLastSql();die;
  414. foreach ($list as &$v){
  415. $is_read = Db::name('store_message_read_log')->where('mid',$this->uid)->where('message_id',$v['id'])->count();
  416. $v['is_read'] = $is_read ? true : false;
  417. }
  418. $this->success('成功',compact('count','list'));
  419. }
  420. /**
  421. * @title 点击消息
  422. * @desc 点击消息,查看消息
  423. * @author Gavin
  424. * @method POST
  425. * @tag 编辑信息
  426. * @url /api/User_center/readMessage
  427. * @header name:Authorization require:1 desc:Token
  428. *
  429. * @param name:id type:int : default:1 desc:消息ID
  430. *
  431. */
  432. public function readMessage(){
  433. $id = input('id');
  434. if (!$id) $this->error('参数错误');
  435. $log = Db::name('store_message_read_log')->where('message_id',$id)->where('mid',$this->uid)->count();
  436. if (!$log){
  437. $data = [
  438. 'mid'=>$this->uid,
  439. 'message_id'=>$id
  440. ];
  441. Db::name('store_message_read_log')->insert($data);
  442. }
  443. $this->success('成功');
  444. }
  445. /**
  446. * @title 人脸认证sign
  447. * @desc 人脸认证sign
  448. * @author Gavin
  449. * @method POST
  450. * @tag 编辑信息
  451. * @url /api/User_center/getFaceSign
  452. * @header name:Authorization require:1 desc:Token
  453. *
  454. *
  455. * @param name:name type:string default:1 desc:姓名
  456. * @param name:idNo type:string default:1 desc:身份证号
  457. *
  458. * @return name:sign type:string require: default:-- desc:签名
  459. *
  460. */
  461. public function getFaceSign(){
  462. $name = input('name');
  463. $idNo = input('idNo');
  464. if (!$name || !$idNo) $this->error('参数错误');
  465. $userId = $this->uid;
  466. //$userId = get32Str();
  467. $data = getfaceid($name,$idNo,$userId);
  468. $this->success('成功',$data);
  469. }
  470. /**
  471. * @title 邀请记录
  472. * @desc 邀请记录
  473. * @author Gavin
  474. * @method POST
  475. * @tag 编辑信息
  476. * @url /api/User_center/invitedRecord
  477. * @header name:Authorization require:1 desc:Token
  478. *
  479. * @param name:page type:int : default:1 desc:页数
  480. * @param name:page_num type:int : default:20 desc:每页数
  481. *
  482. * @return name:id type:int require:0 default:0 desc:用户ID
  483. * @return name:headimg type:string require:0 default:0 desc:头像
  484. * @return name:name type:string require:0 default:0 desc:名称
  485. * @return name:create_at type:string require:0 default:0 desc:时间
  486. */
  487. public function invitedRecord(){
  488. $count = Db::name('store_member')->where('pid',$this->uid)->count();
  489. $list = Db::name('store_member')
  490. ->field('id,headimg,name,create_at')
  491. ->where('pid',$this->uid)
  492. ->order('id desc')
  493. ->limit($this->off_set,$this->page_num)
  494. ->select();
  495. $this->success('成功',compact('count','list'));
  496. }
  497. /**
  498. * @title 签到
  499. * @desc 签到
  500. * @author Gavin
  501. * @method POST
  502. * @tag 编辑信息
  503. * @url /api/User_center/sign
  504. * @header name:Authorization require:1 desc:Token
  505. *
  506. */
  507. public function sign(){
  508. $date = date('Y-m-d');
  509. $log = Db::name('store_member_sign')->where('mid',$this->uid)->where('date',$date)->count();
  510. if ($log) $this->error('今日已签到');
  511. $data = [
  512. 'mid'=>$this->uid,
  513. 'date'=>$date
  514. ];
  515. $com = true;
  516. Db::startTrans();
  517. try {
  518. $id = Db::name('store_member_sign')->insertGetId($data);
  519. $sign_integral = getConfigValue('sign_integral');
  520. if ($sign_integral>0){
  521. memberMoneyChange($sign_integral,1,$this->uid,'签到',1,$id);
  522. }
  523. Db::commit();
  524. }catch (\Exception $e){
  525. $com=false;
  526. Db::rollback();
  527. }
  528. if ($com){
  529. $this->success('签到成功');
  530. }
  531. $this->error('签到失败');
  532. }
  533. /**
  534. * @title 积分记录
  535. * @desc 积分记录
  536. * @author Gavin
  537. * @method POST
  538. * @tag 编辑信息
  539. * @url /api/User_center/integralLog
  540. * @header name:Authorization require:1 desc:Token
  541. *
  542. * @param name:page type:int : default:1 desc:页数
  543. * @param name:page_num type:int : default:20 desc:每页数
  544. *
  545. * @return name:id type:int require:0 default:0 desc:id
  546. * @return name:change type:string require:0 default:0 desc:变动数值
  547. * @return name:title type:string require:0 default:0 desc:标题
  548. * @return name:create_at type:string require:0 default:0 desc:时间
  549. */
  550. public function integralLog(){
  551. $where = [
  552. 'm_id'=>$this->uid,
  553. 'type'=>1
  554. ];
  555. $count = Db::name('store_member_log')->where($where)->count();
  556. $list = Db::name('store_member_log')
  557. ->field('id,pm,change,title,create_at')
  558. ->where($where)
  559. ->order('id desc')
  560. ->limit($this->off_set,$this->page_num)
  561. ->select();
  562. foreach ($list as &$v){
  563. if ($v['pm']==1){
  564. $v['change'] = '+'.$v['change'];
  565. }else{
  566. $v['change'] = '-'.$v['change'];
  567. }
  568. }
  569. $this->success('成功',compact('count','list'));
  570. }
  571. /**
  572. * @title 钱包
  573. * @desc 钱包
  574. * @author M
  575. * @method POST
  576. * @url /api/User_center/wallet
  577. * @header name:Authorization require:1 desc:Token
  578. *
  579. * @param name:page type:int : default:1 desc:页数
  580. * @param name:page_num type:int : default:20 desc:每页数
  581. *
  582. * @return name:money type:int require:0 default:0 desc:余额
  583. * @return name:list@change type:string require:0 default:0 desc:变动金额
  584. * @return name:list@reason type:string require:0 default:0 desc:变动说明
  585. * @return name:list@time type:string require:0 default:0 desc:变动时间
  586. */
  587. public function wallet(){
  588. $uid = $this->uid;
  589. $user_info = Db::name('store_member')
  590. ->field('money')
  591. ->where('id',$uid)
  592. ->find();
  593. if(empty($user_info)) $this->error('用户信息不正确');
  594. $list = Db::name('system_money_record')
  595. ->field('id,pm,change,reason,time')
  596. ->where('mem_id',$uid)
  597. ->order('time desc')
  598. ->limit($this->off_set,$this->page_num)
  599. ->select();
  600. foreach ($list as &$v){
  601. if ($v['pm']==1){
  602. $v['change'] = '+'.$v['change'];
  603. }else{
  604. $v['change'] = '-'.$v['change'];
  605. }
  606. $v['time'] = date('Y-m-d H:i:s',$v['time']);
  607. }
  608. $user_info['list'] = $list;
  609. $this->success('获取成功',$user_info);
  610. }
  611. /**
  612. * @title 充值页面
  613. * @desc 充值页面
  614. * @author M
  615. * @method POST
  616. * @url /api/User_center/recharge
  617. * @header name:Authorization require:1 desc:Token
  618. *
  619. * @return name:money type:int require:0 default:0 desc:余额
  620. * @return name:pay_way@img type:string require:0 default:0 desc:支付方式logo
  621. * @return name:pay_way@name type:string require:0 default:0 desc:支付方式
  622. * @return name:pay_way@code type:string require:0 default:0 desc:支付方式code
  623. */
  624. public function recharge(){
  625. $uid = $this->uid;
  626. $user_info = Db::name('store_member')
  627. ->field('money')
  628. ->where('id',$uid)
  629. ->find();
  630. if(empty($user_info)) $this->error('用户信息不正确');
  631. $detail['money'] = $user_info['money'];
  632. $list = Db::name('SystemPayWay')->where('status = 1 and code != "yue"')->field('img,name,code')->select();
  633. $detail['pay_way'] = $list;
  634. $this->success('获取成功',$detail);
  635. }
  636. /**
  637. * @title 提交充值
  638. * @desc 提交充值
  639. * @author M
  640. * @method POST
  641. * @url /api/User_center/toRecharge
  642. * @header name:Authorization require:1 desc:Token
  643. *
  644. * @param name:money type:int require:1 default:0.01 desc:充值金额
  645. * @param name:pay_way type:string require:1 default:-- desc:支付方式
  646. *
  647. * @return name:order_no type:int require:0 default:0 desc:订单号
  648. * @return name:pay type:string require:0 default:0 desc:支付信息
  649. */
  650. public function toRecharge(){
  651. $this->error('系统升级中...');
  652. $data = $this->request->post();
  653. $param_arr = [
  654. 'money'=>'请输入充值金额',
  655. 'pay_way'=>'请选择支付方式',
  656. ];
  657. foreach ($param_arr as $key=>$v){
  658. if(!isset($data[$key]) || $data[$key] == ''){
  659. $this->error($v);
  660. }
  661. }
  662. $uid = $this->uid;
  663. if($data['money'] <= 0) $this->error('充值数量不能小于0');
  664. $order['number'] = get_order_sn();
  665. $order['money'] = $data['money'];
  666. $order['need_pay'] = $data['money'];
  667. $order['mem_id'] = $uid;
  668. $order['time'] = time();
  669. $re_id = Db::name('SystemRecharge')->insertGetId($order);
  670. if($re_id){
  671. $body = '象寻在线充值';
  672. $order_no = $order['number'];
  673. $total_fee = $data['money'];
  674. switch ($data['pay_way']) {
  675. case 'wx':
  676. $config = retrunWxConfig();
  677. $total_fee = $total_fee * 100;
  678. $config['notify_url'] = $this->request->root(true).'/api/Pay/WxRechargeNotify';
  679. $app = Factory::payment($config);
  680. $result = $app->order->unify([
  681. 'body' => $body,
  682. 'out_trade_no' => $order_no,
  683. 'total_fee' => $total_fee,
  684. 'trade_type' => 'APP', // 请对应换成你的支付方式对应的值类型
  685. ]);
  686. if ($result['return_code']=='SUCCESS'){
  687. $jssdk = $app->jssdk;
  688. $order1 = $jssdk->appConfig($result['prepay_id']);
  689. $retrun_data['order_no'] = $order_no;
  690. $retrun_data['pay'] = $order1;
  691. }else{
  692. $this->error('调用微信支付失败');
  693. }
  694. break;
  695. case 'zfb':
  696. $zfb = new AliPay();
  697. $notify_url = $this->request->root(true).'/api/Pay/alipayRechargeNotify';//回调地址
  698. $order = $zfb->aliPay($body, $total_fee, $order_no, $notify_url);//调用支付宝支付的方法
  699. $retrun_data['order_no'] = $order_no;
  700. $retrun_data['pay'] = $order;
  701. break;
  702. case 'apple':
  703. $retrun_data['order_no'] = $order_no;
  704. $retrun_data['pay'] = ['order_no'=>$order_no];
  705. break;
  706. default:
  707. $this->error('支付方式错误');
  708. }
  709. $this->success('成功',$retrun_data);
  710. }else{
  711. $this->error('充值失败');
  712. }
  713. }
  714. }