123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace app\admin\controller\manage;
- use app\common\controller\Backend;
- use app\common\service\BookService;
- /**
- * 运营管理-标题管理
- *
- * @icon fa fa-circle-o
- */
- class Title extends Backend
- {
- /**
- * ManageTitle模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('ManageTitle');
- $this->view->assign("statusList", $this->model->getStatusList());
- $this->view->assign("sexList", $this->model->getSexList());
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
- * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 查看
- */
- 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();
- }
- public function batchaddtitle()
- {
- if ($this->request->isPost()) {
- $titles = explode("\r\n", trim($this->request->post('titles')));
- $titles = array_filter($titles, function ($value) {
- if (trim($value)) {
- return true;
- }
- return false;
- });
- $status = $this->request->post('status');
- $sex = $this->request->post('sex');
- $result = BookService::instance()->batchAddTitle($titles, $status, $sex);
- if ($result['code'] == 0) {
- $this->success();
- } else {
- $this->error($result['msg']);
- }
- } else {
- return $this->view->fetch();
- }
- }
- }
|