From d86673a589c5ad4e61aeabf9125c57665ab5302d Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Thu, 5 Sep 2024 17:29:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/LocalStoreGoods.php | 10 +++++++++ app/api/logic/LocalStoreGoodsLogic.php | 30 ++++++++++++++------------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/app/api/controller/LocalStoreGoods.php b/app/api/controller/LocalStoreGoods.php index 86942eef..34e39371 100755 --- a/app/api/controller/LocalStoreGoods.php +++ b/app/api/controller/LocalStoreGoods.php @@ -38,6 +38,16 @@ class LocalStoreGoods extends Api return JsonServer::success('提交成功', [], 1, 1); } + public function editPrice() + { + $form = $this->request->post(); + $result = LocalStoreGoodsLogic::editPrice($form, $this->user_id); + if ($result === false) { + return JsonServer::error('修改失败'); + } + return JsonServer::success('修改成功', [], 1, 1); + } + public function shopDetails() { $get = $this->request->get(); diff --git a/app/api/logic/LocalStoreGoodsLogic.php b/app/api/logic/LocalStoreGoodsLogic.php index 38e8da25..1c6ff724 100644 --- a/app/api/logic/LocalStoreGoodsLogic.php +++ b/app/api/logic/LocalStoreGoodsLogic.php @@ -87,7 +87,7 @@ class LocalStoreGoodsLogic extends Logic 'create_time' => time(), ]); } else if ($form['type'] === 'edit') { - LocalStoreGoods::where(['id' => $form['id']])->update([ + LocalStoreGoods::where(['id' => $form['id'], 'user_id' => $user_id])->update([ 'title' => $form['title'], 'price' => $form['price'], 'desc' => $form['desc'] ?? '', @@ -98,22 +98,15 @@ class LocalStoreGoodsLogic extends Logic LocalStoreGoodsPic::where(['lsg_id' => $form['id']])->delete(); $id = $form['id']; - } else if ($form['type'] === 'price') { - LocalStoreGoods::where(['id' => $form['id']])->update([ - 'price' => $form['price'], - 'update_time' => time(), - ]); } - if ($form['type'] != 'price') { - // 处理图片 - $data = []; - foreach ($form['url'] as $k => &$v) { - $data[$k]['lsg_id'] = $id; - $data[$k]['url'] = substr($v, $len, strlen($v)); - } - LocalStoreGoodsPic::insertAll($data); + // 处理图片 + $data = []; + foreach ($form['url'] as $k => &$v) { + $data[$k]['lsg_id'] = $id; + $data[$k]['url'] = substr($v, $len, strlen($v)); } + LocalStoreGoodsPic::insertAll($data); return true; } catch (\Exception $e) { @@ -122,6 +115,15 @@ class LocalStoreGoodsLogic extends Logic } } + public static function editPrice($form, $user_id) + { + LocalStoreGoods::where(['id' => $form['id'], 'user_id' => $user_id])->update([ + 'price' => $form['price'], + 'update_time' => time(), + ]); + return true; + } + public static function editGoods($form, $user_id) { try {