model = model('Resource'); $this->view->assign("showTypeList", $this->model->getShowTypeList()); $this->view->assign("typeList", $this->model->getTypeList()); $this->view->assign("statusList", $this->model->getStatusList()); $this->view->assign("popRangeList", $this->model->getPopRangeList()); $this->view->assign("classifyList", $this->model->getClassifyList()); $this->aid = $this->request->get('aid'); if ($this->request->has('resource_type')) { $this->resource_type = intval($this->request->get('resource_type')); } $this->assign('aid', $this->aid); $this->assign('resource_type', $this->resource_type ?? ''); $this->assignconfig('aid', $this->aid); $this->assignconfig('resource_type', $this->resource_type ?? ''); //业务线 if ($this->request->has('business_line')) { $this->business_line = intval($this->request->get('business_line')); } $this->assignconfig('business_line', $this->business_line); $this->assign('business_line', $this->business_line); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法 * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { $map['activity_id'] = $this->aid; //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('pkey_name')) { return $this->selectpage(); } if ($this->resource_type !== null) { $map['resource_type'] = $this->resource_type; } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $total = $this->model ->where($where) ->where($map) ->count(); $list = $this->model->alias('r') ->join(['goods' => 'g'], 'r.goods_id = g.id', 'LEFT') ->field([ 'r.*', 'g.show_type' => 'g_show_type', 'g.type' => 'g_type', 'g.money' => 'g_money', 'g.kandian' => 'g_kandian', 'g.free_kandian' => 'g_free_kandian', 'g.icon' => 'g_icon', 'g.free_day' => 'g_free_day', 'g.day' => 'g_day', ]) ->where($where) ->where($map) ->order($sort, $order) ->limit($offset, $limit) ->select(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } public function select(){ $map['activity_id'] = $this->aid; //设置过滤方法 $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(); if ($this->resource_type !== null) { $map['resource_type'] = $this->resource_type; } $total = $this->model ->where($where) ->where($map) ->count(); $list = $this->model->alias('r') ->join(['goods' => 'g'], 'r.goods_id = g.id', 'LEFT') ->field([ 'r.*', 'g.show_type' => 'g_show_type', 'g.type' => 'g_type', 'g.money' => 'g_money', 'g.kandian' => 'g_kandian', 'g.free_kandian' => 'g_free_kandian', 'g.icon' => 'g_icon', 'g.free_day' => 'g_free_day', 'g.day' => 'g_day', ]) ->where($where) ->where($map) ->order($sort, $order) ->limit($offset, $limit) ->select(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 添加 */ public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { if ($this->dataLimit) { $params[$this->dataLimitField] = $this->auth->id; } try { //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate; $this->model->validate($validate); } if (isset($params['activity_id']) && $params['activity_id'] > 0) { //验证平台活动 是否已经添加了资源 if (model("Resource")->where('activity_id', 'eq', $params['activity_id'])->count() > 0) { $this->error("活动仅支持配置一条资源"); } } $result = $this->model->allowField(true)->save($params); if ($result !== false) { $this->success(); } else { $this->error($this->model->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } if (in_array($this->resource_type, [0, 1, 2])) { return $this->view->fetch('addgoodsresource'); } else { return $this->view->fetch('add'); } } /** * 编辑 */ public function edit($ids = NULL) { $row = $this->model->get($ids); if (!$row) $this->error(__('No Results were found')); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { //$params['warning'] = str_replace("/n","
",$params['warning']);die; Log::write($params['warning'],'congcongtest'); try { //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate; $row->validate($validate); } $result = $row->allowField(true)->save($params); if ($result !== false) { //清一下缓存 $key = 'A-R-R:'.$ids; $key2 = 'R-I:'.$ids; Redis::instance()->del($key); Redis::instance()->del($key2); $this->success(); } else { $this->error($row->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } $goods = [ 'show_type_text' => '', 'type_text' => '', 'money' => '', 'kandian' => '', 'free_kandian' => '', 'icon' => '', 'id' => '', 'free_day' => '', 'type' => '', 'day' => '', ]; if (!empty($row['goods_id'])) { $goodsModel = model('goods'); $goods = $goodsModel->where('id', $row['goods_id'])->find(); } $this->view->assign("goods", $goods); $this->view->assign("row", $row); if (in_array($this->resource_type, [0, 1])) { return $this->view->fetch('editgoodsresource'); } else { return $this->view->fetch('edit'); } } }