12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use think\Exception;
- class UserMoneyLog extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = '*';
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = Db::name('user_money_log');
- }
- /**
- * 列表
- * @return void
- */
- public function getList()
- {
- try {
- $status = $this->request->param('status',1);//状态:1待使用,2已失效
- $userId = $this->auth->id;
- $companyId = $this->auth->company_id;
- $field = 'id,coupon_name,coupon_info,endtime,number,remain';
- $where['user_id'] = $userId;
- $where['company_id'] = $companyId;
- $whereOr = [];
- if ($status == 1) {
- $where['remain'] = ['gt',0];
- } else {
- $whereOr['remain'] = ['elt',0];
- $whereOr['endtime'] = ['lt',time()];
- }
- $result = $this->model->field($field)->where($where)->where(function($query) use ($whereOr){
- $query->whereOr($whereOr);
- })->order('createtime desc')->autopage()->select();
- if (!empty($result)) {
- foreach ($result as $key => &$value) {
- !empty($value['endtime']) && $value['endtime'] = date('Y.m.d H:i:s',$value['endtime']);
- }
- }
- $this->success('获取成功',$result);
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
- }
|