UserMoneyLog.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Exception;
  6. class UserMoneyLog extends Api
  7. {
  8. protected $noNeedLogin = [];
  9. protected $noNeedRight = '*';
  10. protected $model = null;
  11. public function _initialize()
  12. {
  13. parent::_initialize();
  14. $this->model = Db::name('user_money_log');
  15. }
  16. /**
  17. * 列表
  18. * @return void
  19. */
  20. public function getList()
  21. {
  22. try {
  23. $userId = $this->auth->id;
  24. $companyId = $this->auth->company_id;
  25. $field = 'id,before,change_value,remain,remark,createtime';
  26. $where['user_id'] = $userId;
  27. $where['company_id'] = $companyId;
  28. $result = $this->model->field($field)->where($where)->order('createtime desc')->autopage()->select();
  29. if (!empty($result)) {
  30. foreach ($result as $key => &$value) {
  31. $symbol = $value['remain'] > $value['before'] ? '+' : '-';
  32. $value['symbol'] = $value['remain'] > $value['before'] ? 2 : 1;
  33. $value['change_value_text'] = $symbol.$value['change_value'];
  34. !empty($value['createtime']) && $value['createtime'] = date('Y.m.d H:i:s',$value['createtime']);
  35. }
  36. }
  37. $this->success('获取成功',$result);
  38. } catch (Exception $e) {
  39. $this->error($e->getMessage());
  40. }
  41. }
  42. }