model = model('ManageSharetitle'); $this->view->assign("statusList", $this->model->getStatusList()); $this->view->assign("sexList", $this->model->getSexList()); } /** * 添加 */ public function addmany() { if ($this->request->isPost()) { $time = time(); $title = $this->request->post('title'); $sex = $this->request->post('sex'); $status = $this->request->post('status'); if ($title) { $str = str_replace(array("\r\n", "\r", "\n"), "||", $title); $titleArr = explode("||",$str); $queryStr = ''; foreach($titleArr as $val){ $queryStr.= "('".trim($val)."','{$status}',{$time},{$time},'{$sex}'),"; } $queryStr = substr($queryStr,0,-1); $sql = "insert into manage_sharetitle (title,status,createtime,updatetime,sex) values ".$queryStr; try { $result = $this->model->query($sql); if ($result !== false) { return json_encode(['success'=>1]); } else { $this->error($this->model->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } return $this->view->fetch(); } /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('pkey_name')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $whereArr = []; if (strtolower($this->request->action()) == 'select') { $whereArr[] = ['status', '=', 'normal']; $whereArr = function($query) use ($whereArr) { foreach ($whereArr as $k => $v) { if (is_array($v)) { call_user_func_array([$query, 'where'], $v); } else { $query->where($v); } } }; } $total = $this->model ->where($where) ->where($whereArr) ->order($sort, $order) ->count(); $list = $this->model ->where($where) ->where($whereArr) ->order($sort, $order) ->limit($offset, $limit) ->select(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 选择标题 */ public function select() { if ($this->request->isAjax()) { return $this->index(); } return $this->view->fetch(); } /** * ajax方法转发index,用于渠道商/代理商API请求 * @return string|\think\response\Json */ public function ajax() { return $this->index(); } }