UserMoneyLog.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. $status = $this->request->param('status',1);//状态:1待使用,2已失效
  24. $userId = $this->auth->id;
  25. $companyId = $this->auth->company_id;
  26. $field = 'id,coupon_name,coupon_info,endtime,number,remain';
  27. $where['user_id'] = $userId;
  28. $where['company_id'] = $companyId;
  29. $whereOr = [];
  30. if ($status == 1) {
  31. $where['remain'] = ['gt',0];
  32. } else {
  33. $whereOr['remain'] = ['elt',0];
  34. $whereOr['endtime'] = ['lt',time()];
  35. }
  36. $result = $this->model->field($field)->where($where)->where(function($query) use ($whereOr){
  37. $query->whereOr($whereOr);
  38. })->order('createtime desc')->autopage()->select();
  39. if (!empty($result)) {
  40. foreach ($result as $key => &$value) {
  41. !empty($value['endtime']) && $value['endtime'] = date('Y.m.d H:i:s',$value['endtime']);
  42. }
  43. }
  44. $this->success('获取成功',$result);
  45. } catch (Exception $e) {
  46. $this->error($e->getMessage());
  47. }
  48. }
  49. }