where('is_delete', 0) ->order('id desc') ->field('id, profit, subsidy') ->paginate([ 'list_rows'=> $get['limit'], 'page'=> $get['page'], ]); foreach ($lists as &$v) { $v['profit'] = self::formatStr($v['profit']); $v['subsidy'] = self::formatStr($v['subsidy']); } return ['count' => $lists->total(), 'lists' => $lists->getCollection()]; } public function getSubsidyById($id) { $result = $this->where(['id' => $id, 'is_delete' => 0])->field('id, profit, subsidy')->find(); $result['profit'] = self::formatStr($result['profit']); $result['subsidy'] = self::formatStr($result['subsidy']); return $result; } public static function formatStr($str) { $s = explode('.', $str); return $s[1] > 0 ? $s . '%' : intval($str) . '%'; } }