getList($goods_status, $category_id, $goods_name); return $this->fetch('index', compact('list', 'catgory')); } /** * 添加商品 * @return array|mixed * @throws \think\exception\PDOException */ public function add() { if (!$this->request->isAjax()) { // 商品分类 $catgory = Category::getCacheTree(); // 配送模板 $delivery = Delivery::getAll(); return $this->fetch('add', compact('catgory', 'delivery')); } $model = new GoodsModel; if ($model->add($this->postData('goods'))) { return $this->renderSuccess('添加成功', url('goods/index')); } return $this->renderError($model->getError() ?: '添加失败'); } /** * 一键复制 * @param $goods_id * @return array|mixed * @throws \think\exception\PDOException */ public function copy($goods_id) { // 商品详情 $model = GoodsModel::detail($goods_id); if (!$this->request->isAjax()) { // 商品分类 $catgory = Category::getCacheTree(); // 配送模板 $delivery = Delivery::getAll(); // 商品sku数据 $specData = 'null'; if ($model['spec_type'] == 20) { $specData = json_encode($model->getManySpecData($model['spec_rel'], $model['sku']), JSON_UNESCAPED_SLASHES); } return $this->fetch('edit', compact('model', 'catgory', 'delivery', 'specData')); } $model = new GoodsModel; if ($model->add($this->postData('goods'))) { return $this->renderSuccess('添加成功', url('goods/index')); } return $this->renderError($model->getError() ?: '添加失败'); } /** * 商品编辑 * @param $goods_id * @return array|mixed * @throws \think\exception\PDOException */ public function edit($goods_id) { // 商品详情 $model = GoodsModel::detail($goods_id); if (!$this->request->isAjax()) { // 商品分类 $catgory = Category::getCacheTree(); // 配送模板 $delivery = Delivery::getAll(); // 商品sku数据 $specData = 'null'; if ($model['spec_type'] == 20) { $specData = json_encode($model->getManySpecData($model['spec_rel'], $model['sku']), JSON_UNESCAPED_SLASHES); } return $this->fetch('edit', compact('model', 'catgory', 'delivery', 'specData')); } // 更新记录 if ($model->edit($this->postData('goods'))) { return $this->renderSuccess('更新成功', url('goods/index')); } return $this->renderError($model->getError() ?: '更新失败'); } /** * 修改商品状态 * @param $goods_id * @param boolean $state * @return array */ public function state($goods_id, $state) { // 商品详情 $model = GoodsModel::detail($goods_id); if (!$model->setStatus($state)) { return $this->renderError('操作失败'); } return $this->renderSuccess('操作成功'); } /** * 删除商品 * @param $goods_id * @return array */ public function delete($goods_id) { // 商品详情 $model = GoodsModel::detail($goods_id); if (!$model->setDelete()) { return $this->renderError('删除失败'); } return $this->renderSuccess('删除成功'); } }