model = new \app\admin\model\app\AppProduct; $this->view->assign("statusList", $this->model->getStatusList()); } public function import() { parent::import(); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } // list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $offset = $this->request->get("offset", 0); $limit = $this->request->get("limit", 0); $params = json_decode(input('filter'), true); $op = json_decode(input('op'), true); if (count($params) > 0) { $new_params = $new_op = []; foreach ($params as $key => $value) { if ($key == 'curr_name') { $new_params['c.name'] = $value; $new_op['c.name'] = $op[$key]; }else { $new_params['aa.' . $key] = $value; $new_op['aa.' . $key] = $op[$key]; } } $w = $this->rewriteQuery($new_params, $new_op); } else { $w['aa.id'] = array('>', 0); } $admin_id = $this->auth->id; if($admin_id > 1){ $user = Db::name("user")->where("admin_id",$admin_id)->find(); if($user){ $w['b.path'] = array("like",$user['path']."%"); } } // echo "
";var_dump( $w );die;
$total = Db::name('app_product')
->alias('aa')
->field('aa.*,c.name as curr_name')
->join('app_currency c', 'aa.curr_id = c.id' , 'left')
->where($w)
->count();
$list = Db::name('app_product')
->alias('aa')
->field('aa.*,c.name as curr_name')
->join('app_currency c', 'aa.curr_id = c.id' , 'left')
->where($w)
->order('aa.id', 'desc')
->limit($offset, $limit)
->select();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}