Userwallet.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  16. $this->success('success',$wallet);
  17. }
  18. //我的余额日志
  19. public function my_money_log(){
  20. $type = input('type',0);
  21. $map = [
  22. 'user_id' => $this->auth->id,
  23. ];
  24. if($type == 1){
  25. $map['change_value'] = ['gt',0];
  26. }
  27. if($type == 2){
  28. $map['change_value'] = ['lt',0];
  29. }
  30. $list = Db::name('user_money_log')
  31. ->field('id,log_type,before,change_value,remain,remark,createtime')
  32. ->where($map)->order('id desc')->autopage()->select();
  33. // $list = $this->list_appen_logtext($list);
  34. $this->success('success',$list);
  35. }
  36. //追加log_text
  37. private function list_appen_logtext($list){
  38. if(!empty($list)){
  39. $conf = config('wallet.logtype');
  40. foreach($list as $key => $val){
  41. $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  42. }
  43. }
  44. return $list;
  45. }
  46. }