Userwallet.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. //use app\common\model\wallet;
  6. /**
  7. * 用户钱包
  8. */
  9. class Userwallet extends Api
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = ['*'];
  13. //我的钱包余额
  14. public function my_wallet(){
  15. $wallet = model('wallet')->getwallet($this->auth->id);
  16. $wallet['is_vip'] = $wallet['vip_endtime'] > time() ? 1 : 0;
  17. $this->success('success',$wallet);
  18. }
  19. //我的余额日志
  20. public function my_money_log(){
  21. $type = input_post('type',0);
  22. $map = [
  23. 'user_id' => $this->auth->id,
  24. ];
  25. if($type){
  26. $map['log_type'] = $type;
  27. }
  28. $list = Db::name('user_money_log')
  29. ->field('id,log_type,before,change_value,remain,remark,createtime')
  30. ->where($map)->order('id desc')->autopage()->select();
  31. $list = $this->list_appen_logtext($list);
  32. $this->success('success',$list);
  33. }
  34. //金币日志
  35. public function my_gold_log(){
  36. $type = input_post('type',0);
  37. $map = [
  38. 'user_id' => $this->auth->id,
  39. ];
  40. if($type){
  41. $map['log_type'] = $type;
  42. }
  43. $list = Db::name('user_gold_log')
  44. ->field('id,log_type,before,change_value,remain,remark,createtime')
  45. ->where($map)->order('id desc')->autopage()->select();
  46. $list = $this->list_appen_logtext($list);
  47. $this->success('success',$list);
  48. }
  49. //追加log_text
  50. private function list_appen_logtext($list){
  51. if(!empty($list)){
  52. $conf = config('wallet.logtype');
  53. foreach($list as $key => $val){
  54. $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  55. }
  56. }
  57. return $list;
  58. }
  59. }