viewPath); return View::fetch('index'); } } public function getCategoryList() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } try { $father_code = input('father_code'); $where[] = ['father_code', '=', $father_code]; $order = 'order_id asc,id asc'; $list = Db::name('category')->field('*')->where($where)->order($order)->select()->toArray(); if (!$list) { return $this->errorResponse('暂无菜单'); } $reuslt['list'] = $list; return $this->successResponse($reuslt); } catch (\Exception $e) { return $this->errorResponse($e->getMessage()); } } ///获取平台列表 public function getPlatformList() { try { if (!Request::isPost()) { throw new Exception('请求方式错误'); } $order = 'order_id asc,docking_platform_id asc'; $list = Db::name('docking_platform')->field('*')->order($order)->select()->toArray(); if (!$list) { throw new Exception('暂无平台信息'); } $reuslt['list'] = $list; return $this->successResponse($reuslt); } catch (Exception $e) { return $this->errorResponse($e->getMessage()); } } /** * 保存分类 信息 * @return array|int[] */ public function saveCategory() { Db::startTrans(); try { if (!Request::isPost()) { throw new Exception(lang('request_method_incorrect')); } $data = Request::post(); $id = $data['id']; if (is_numeric($id)) { //更新数据 $validate = new \app\admin\validate\Category(); $result = $validate->check($data); if (!$result) { throw new Exception($validate->getError()); } //////保存//////////// Db::name('category')->where('id', $id)->withoutField('id')->save($data); //////////////////////// ///////执行成功,提交事务/////// Db::commit(); $this->delCache(); $res['message'] = '编辑成功'; return $this->successResponse($res); } else { unset($data['id']); $data['status'] = 1; $validate = new \app\admin\validate\Category(); $result = $validate->check($data); if (!$result) { throw new Exception($validate->getError()); } ////////////////////// $new_id = Db::name('category')->insertGetId($data); if (!$new_id) { throw new Exception('添加失败'); } Db::name('category')->where('id', $new_id)->save(['order_id' => $new_id]); ///////执行成功,提交事务/////// Db::commit(); $this->delCache(); $res['message'] = '添加成功'; return $this->successResponse($res); } } catch (Exception $e) { // 回滚事务 Db::rollback(); return $this->errorResponse($e->getMessage()); } } //保存对接平台信息 public function savePlatform() { Db::startTrans(); try { if (!Request::isPost()) { throw new Exception(lang('request_method_incorrect')); } $data = Request::post(); $docking_platform_id = $data['docking_platform_id']; if (is_numeric($docking_platform_id)) { //更新数据 $validate = new \app\admin\validate\DockingPlatform(); $result = $validate->check($data); if (!$result) { return $this->errorResponse($validate->getError()); } //////保存//////////// Db::name('docking_platform')->where('docking_platform_id', $docking_platform_id)->withoutField('docking_platform_id')->save($data); //////////////////////// Db::commit(); $this->delDPCache(); $res['message'] = '编辑成功'; return $this->successResponse($res); } else { unset($data['docking_platform_id']); $validate = new \app\admin\validate\DockingPlatform(); $result = $validate->check($data); if (!$result) { return $this->errorResponse($validate->getError()); } ////////////////////// $new_id = Db::name('docking_platform')->insertGetId($data); if (!$new_id) { throw new Exception('添加失败'); } Db::name('docking_platform')->where('docking_platform_id', $new_id)->save(['order_id' => $new_id]); ///////执行成功,提交事务/////// $this->delDPCache(); Db::commit(); $res['message'] = '添加成功'; return $this->successResponse($res); } } catch (Exception $e) { // 回滚事务 Db::rollback(); return $this->errorResponse($e->getMessage()); } } /** * 清除缓存 * @return void */ private function delCache() { Cache::tag('category')->clear(); } private function delDPCache() { Cache::tag('docking_platform')->clear(); } }