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; + } + } }