['l.status','l.action'], ]; } /** * @notes 搜索条件 */ public function queryWhere() { $where = []; if (!empty($this->params['worker'])) { $where[] = ['w.real_name|w.mobile', 'like', '%' . $this->params['worker'] . '%']; } if (!empty($this->params['start_time'])) { $where[] = ['l.create_time', '>=', strtotime($this->params['start_time'])]; } if (!empty($this->params['end_time'])) { $where[] = ['l.create_time', '<=', strtotime($this->params['end_time'])]; } return $where; } /** * @notes 获取列表 * @return array */ public function lists(): array { $field = 'w.real_name,w.mobile,l.*'; $lists = MasterWorkerRetentionMoneyLog::alias('l') ->join('master_worker w', 'w.id = l.worker_id') ->field($field) ->where($this->searchWhere) ->where($this->queryWhere()) ->order('l.id', 'desc') ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); foreach ($lists as &$item) { $symbol = $item['action'] == 1 ? '+' : '-'; $item['amount'] = $symbol . $item['amount']; } return $lists; } /** * @notes 获取数量 * @return int */ public function count(): int { return MasterWorkerRetentionMoneyLog::alias('l') ->join('master_worker w', 'w.id = l.worker_id') ->where($this->queryWhere()) ->where($this->searchWhere) ->count(); } /** * @notes 额外参数 * @return mixed|null */ public function extend() { $count = (new MasterWorkerRetentionMoneyLog())->alias('l') ->join('master_worker w', 'w.id = l.worker_id') ->field([ 'count(l.id) as total', 'count(if(l.action=1, true, null)) as ing', 'count(if(l.action=2, true, null)) as success', ]) ->where($this->searchWhere) ->where($this->queryWhere(false)) ->select()->toArray(); return array_shift($count); } }