model = new \app\admin\model\functional\Deal; $this->view->assign("statusList", $this->model->getStatusList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ public function index() { $ra_id=input('ids'); if(empty($ra_id)){ $ra_id=session('fid'); }else{ session('fid',$ra_id); } //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if (false === $this->request->isAjax()) { return $this->view->fetch(); } //如果发送的来源是 Selectpage,则转发到 Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $dts['fid'] =$ra_id; $list = $this->model ->where($where) ->where($dts) ->order($sort, $order) ->paginate($limit); $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } public function deletecache() { $ra_id=input('ids'); if(empty($ra_id)){ $ra_id=session('xids'); }else{ session('xids',$ra_id); } $model = new \app\admin\model\functional\Fal; $row = $model->get($ra_id); $data['name']=$row->name; $website=$row->website; $url =''; if($website=='alipearlhair'){ $url ='https://www.alipearlhair.com/app-api/cache/deleteImageCache'; } if($website=='wigginshair'){ $url ='https://www.wigginshair.com/app-api/cache/deleteImageCache'; } if(empty($url)){ $this->error(__('网站出错')); } self::request($url, $data, 'POST'); $this->success(); } public static function request($url, $params = [], $method = 'GET', $headers = [], $options = []) { $ch = curl_init(); // 设置请求方法 $method = strtoupper($method); // 设置参数 if ($method == 'GET' && !empty($params)) { $url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($params); } // 设置 URL curl_setopt($ch, CURLOPT_URL, $url); // 设置请求方法 if ($method == 'POST') { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); } elseif ($method == 'PUT' || $method == 'DELETE') { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); } // 设置请求头 if (!empty($headers)) { $headerArr = []; foreach ($headers as $key => $value) { $headerArr[] = $key . ': ' . $value; } curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr); } // 默认选项 $defaultOptions = [ CURLOPT_RETURNTRANSFER => true, // 返回结果而不输出 CURLOPT_HEADER => false, // 不包含响应头 CURLOPT_FOLLOWLOCATION => true, // 跟随重定向 CURLOPT_MAXREDIRS => 10, // 最大重定向次数 CURLOPT_TIMEOUT => 30, // 超时时间(秒) CURLOPT_CONNECTTIMEOUT => 10, // 连接超时时间 CURLOPT_SSL_VERIFYPEER => false, // 不验证 SSL 证书 CURLOPT_SSL_VERIFYHOST => false, // 不验证主机名 CURLOPT_USERAGENT => 'FastAdmin/' . config('fastadmin.version'), // User-Agent ]; // 合并选项 foreach ($defaultOptions as $key => $value) { if (!isset($options[$key])) { $options[$key] = $value; } } // 设置 cURL 选项 foreach ($options as $key => $value) { curl_setopt($ch, $key, $value); } // 执行请求 $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); $errno = curl_errno($ch); curl_close($ch); return [ 'success' => $errno === 0 && $response !== false, 'http_code' => $httpCode, 'response' => $response, 'error' => $error, 'errno' => $errno ]; } /** * 添加 * * @return string * @throws \think\Exception */ public function add() { if (false === $this->request->isPost()) { return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); if ($this->dataLimit && $this->dataLimitFieldAutoFill) { $params[$this->dataLimitField] = $this->auth->id; } $params['fid']=session('fid'); $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->model->validateFailException()->validate($validate); } $result = $this->model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('No rows were inserted')); } $this->success(); } }