Userwallet.php 1.8 KB

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