123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wanggb
- * Date: 2019/2/19
- * Time: 18:00
- */
- namespace app\admin\controller\manage;
- use app\common\controller\Backend;
- class Sharedesc extends Backend
- {
- /**
- * ManageSharedesc模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('ManageSharedesc');
- $this->view->assign("statusList", $this->model->getStatusList());
- $this->view->assign("sectionList", $this->model->getSectionList());
- }
- /**
- * 添加
- */
- public function addmany()
- {
- if ($this->request->isPost())
- {
- $time = time();
- $desc = $this->request->post('desc');
- $section = $this->request->post('section');
- $status = $this->request->post('status');
- if ($desc)
- {
- $str = str_replace(array("\r\n", "\r", "\n"), "||", $desc);
- $descArr = explode("||",$str);
- $insertList = [];
- foreach($descArr as $val){
- if ($val) {
- $tmp = [
- 'desc' => trim($val),
- 'status' => $status,
- 'createtime' => $time,
- 'updatetime' => $time,
- 'section' => $section,
- ];
- $insertList[] = $tmp;
- }
- }
- try
- {
- $result = $this->model->insertAll($insertList);
- 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()
- {
- return $this->index();
- }
- }
|