From 13395e424ca82505599e0f0ac823c4138b8ffd61 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 3 Jun 2024 17:49:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=BA=90=E8=8E=B7=E5=8F=96=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system_store/SystemStoreController.php | 25 ++++++++++++++++++- .../logic/store_product/StoreProductLogic.php | 24 ++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/app/admin/controller/system_store/SystemStoreController.php b/app/admin/controller/system_store/SystemStoreController.php index bb4badff3..169743b44 100644 --- a/app/admin/controller/system_store/SystemStoreController.php +++ b/app/admin/controller/system_store/SystemStoreController.php @@ -6,6 +6,7 @@ namespace app\admin\controller\system_store; use app\admin\controller\BaseAdminController; use app\admin\lists\system_store\SystemStoreLists; use app\admin\lists\system_store\SystemStoreSourceLists; +use app\admin\logic\store_product\StoreProductLogic; use app\admin\logic\system_store\SystemStoreLogic; use app\admin\validate\system_store\SystemStoreValidate; @@ -39,7 +40,29 @@ class SystemStoreController extends BaseAdminController { return $this->dataLists(new SystemStoreSourceLists()); } - + /** + * @notes 根据商品源获取门店列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function source_product_update_store() + { + $addList=$this->request->post('addList'); + $product_id=$this->request->post('product_id'); + if($addList){ + foreach ($addList as $key=>$value){ + StoreProductLogic::copy($product_id,$value); + } + } + $removeList=$this->request->post('removeList'); + if($removeList){ + foreach ($removeList as $key=>$value){ + StoreProductLogic::store_del($product_id,$value); + } + } + return $this->dataLists(new SystemStoreSourceLists()); + } /** * @notes 添加门店列表 diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 5c3c64476..3fda22b3a 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -114,7 +114,7 @@ class StoreProductLogic extends BaseLogic 'rose' => $params['rose'], ]; if ($params['rose'] > 0) { - $rose_price = bcmul($params['cost'],bcdiv($params['rose'], 100, 2), 2); + $rose_price = bcmul($params['cost'], bcdiv($params['rose'], 100, 2), 2); $data['price'] = bcadd($params['cost'], $rose_price, 2); } else { $data['price'] = 0; @@ -195,7 +195,7 @@ class StoreProductLogic extends BaseLogic /** * 复制商品到门店 */ - public static function copy($id, $store_id,$stock=0) + public static function copy($id, $store_id, $stock = 0) { $find = StoreProduct::where('id', $id)->findOrEmpty()->toArray(); $store_find = StoreBranchProduct::where(['product_id' => $id, 'store_id' => $store_id])->findOrEmpty()->toArray(); @@ -236,4 +236,24 @@ class StoreProductLogic extends BaseLogic } } } + + /** + * 删除门店商品 + */ + public static function store_del($id, $store_id) + { + + Db::startTrans(); + try { + StoreBranchProduct::where(['product_id' => $id, 'store_id' => $store_id])->update(['delete_time' => time()]); + StoreProductAttrValue::where(['product_id' => $id, 'store_id' => $store_id])->update(['delete_time' => time()]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + d($e); + self::setError($e->getMessage()); + return false; + } + } }