From e59b5e1446670b49993a41345b65a5441eb783da Mon Sep 17 00:00:00 2001 From: lvdongyang <2022862913@qq.com> Date: Mon, 24 Mar 2025 07:02:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E8=81=94=E4=BA=A7=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/model/goods/Goods.php | 11 ++- app/model/order/OrderCreate.php | 52 +++++++++++- app/shop/controller/Goods.php | 17 +++- app/shop/view/goods/add_goods.html | 117 +++++++++++++++++++++++--- app/shop/view/goods/edit_goods.html | 95 +++++++++++++++++++++ app/shop/view/public/js/goods_edit.js | 15 +++- 6 files changed, 288 insertions(+), 19 deletions(-) diff --git a/app/model/goods/Goods.php b/app/model/goods/Goods.php index 1dc352b..549ea5f 100644 --- a/app/model/goods/Goods.php +++ b/app/model/goods/Goods.php @@ -103,6 +103,9 @@ class Goods extends BaseModel 'market_price_show' => $data['market_price_show'] ?? 1, 'barrage_show' => $data['barrage_show'] ?? 1, 'is_zmxx' => $data['is_zmxx'] ?? 0, + 'is_correlation' => $data['is_correlation'] ?? 0, + 'correlation_type' => $data['is_correlation'] ?? 1, + 'correlation_goods_ids' => json_encode($data['correlation_goods_ids'] ? explode(',',$data['correlation_goods_ids']) : []) ); $common_data = array( 'goods_name' => $data['goods_name'], @@ -907,6 +910,10 @@ class Goods extends BaseModel if (isset($info['real_stock'])) { $info['real_stock'] = numberFormat($info['real_stock']); } + if(isset($info['correlation_goods_ids'])){ + $info['correlation_goods_ids'] = json_decode($info['correlation_goods_ids'],true); + $info['correlation_select_goods_ids'] = implode(',',$info['correlation_goods_ids']); + } return $this->success($info); } return $this->error(); @@ -1114,7 +1121,9 @@ class Goods extends BaseModel if (isset($v['real_stock'])) { $res['list'][$k]['real_stock'] = numberFormat($res['list'][$k]['real_stock']); } - $res['list'][$k]['goods_kind_name'] = $res['list'][$k]['goods_kind_id'] ? '报单商品' : '进货商品'; + if(isset($v['goods_kind_id'])){ + $res['list'][$k]['goods_kind_name'] = $res['list'][$k]['goods_kind_id'] ? '报单商品' : '进货商品'; + } } return $this->success($res); } diff --git a/app/model/order/OrderCreate.php b/app/model/order/OrderCreate.php index e0cb613..15d55ef 100644 --- a/app/model/order/OrderCreate.php +++ b/app/model/order/OrderCreate.php @@ -34,7 +34,6 @@ use app\model\BaseModel; use app\model\message\Message; use addon\pointcash\model\Config as PointCashConfig; use think\facade\Db; - /** * 订单创建(普通订单) * @@ -499,6 +498,8 @@ class OrderCreate extends BaseModel //商品列表信息 $shop_goods_list = $this->getOrderGoodsCalculate($data); //获取产品信息 + $buy_goods_ids = array_column($shop_goods_list['goods_list'],'goods_id'); + $correlationList = $this->getGoodsCorrelationList($buy_goods_ids); $kind = array_column($shop_goods_list['goods_list'],'goods_kind_id'); $search = array_search(0,$kind); @@ -576,6 +577,7 @@ class OrderCreate extends BaseModel $data['member_card_money'] = $this->member_card_money; $data['recommend_member_card'] = $this->recommend_member_card; $data['legumes_integral_money'] = $this->legumesIntegralMoney; + $data['buy_list'] = $correlationList; // 豆豆积分抵扣 if ($data['is_legumes_integral'] != 1) { @@ -729,7 +731,6 @@ class OrderCreate extends BaseModel public function getOrderGoodsCalculate($data) { $shop_goods = $this->getCartGoodsList($data); - $shop_goods['promotion_money'] = 0; $shop_goods_list = $shop_goods; // 会员卡项抵扣 @@ -1944,6 +1945,53 @@ class OrderCreate extends BaseModel } return $goods_list; } + public function getGoodsCorrelationList($buy_goods_ids){ + $goods_model = new Goods(); + $condition = [ + ['goods_id' ,'in',$buy_goods_ids], + ['is_correlation' ,'=' ,1] + ]; + $field = 'goods_id,goods_name,site_id,correlation_type,correlation_goods_ids'; + $res = $goods_model->getGoodsList($condition,$field); + $all_ids = $one_ids = $all_list = $one_list = []; + //说明有必须关联购买的产品 + if($res['data']){ + foreach($res['data'] as $k => $v){ + $correlation_goods_ids = json_decode($v['correlation_goods_ids'],true); + //购买其中一件 + if($v['correlation_type'] == 1){ + $intersection = array_intersect($correlation_goods_ids, $buy_goods_ids); + //没有交集说明没有购买其中一件商品 + if(!$intersection){ + $one_ids = array_merge($one_ids,$correlation_goods_ids); + } + }else if($v['correlation_type'] == 2){ + $diff = array_diff($buy_goods_ids, $correlation_goods_ids); + //不包含设置的所有元素 + if(!empty($diff)){ + $all_ids = array_merge($all_ids,$diff); + } + } + } + if($one_ids){ + $one_condition = [ + ['goods_id', 'IN' ,$one_ids], + ['goods_state' ,'=' ,1], + ['is_delete' , '=' ,0] + ]; + $one_list = $goods_model->getGoodsList($one_condition)['data']; + } + if($all_ids){ + $all_condition = [ + ['goods_id', 'IN' ,$all_ids], + ['goods_state' ,'=' ,1], + ['is_delete' , '=' ,0] + ]; + $all_list = $goods_model->getGoodsList($all_condition)['data']; + } + } + return compact('all_list','one_list'); + } } diff --git a/app/shop/controller/Goods.php b/app/shop/controller/Goods.php index 1e70938..3264d4f 100644 --- a/app/shop/controller/Goods.php +++ b/app/shop/controller/Goods.php @@ -302,6 +302,9 @@ class Goods extends BaseShop 'is_unify_pirce' => input('is_unify_pirce', '1'), 'is_zmxx' => input('is_zmxx', 0), 'cat_id' => input('cat_id', ''), + 'is_correlation' => input('is_correlation', 0), + 'correlation_type' => input('correlation_type', 1), + 'correlation_goods_ids' => input('correlation_goods_ids', []), ]; $goods_model = new GoodsModel(); $res = $goods_model->addGoods($data); @@ -392,6 +395,9 @@ class Goods extends BaseShop $is_alipay_goods = 0; if ($config_info) $is_alipay_goods = 1; $this->assign("is_alipay_goods", $is_alipay_goods); + //商品信息 + $this->assign('goods_list', []); + $this->assign('goods_ids_arr', []); // 获取平台抽成设置 $this->assign([ 'finalSet' => (new Setting())->getFinalSet((int)$this->site_id),// 获取店铺级 最终设置 @@ -469,6 +475,9 @@ class Goods extends BaseShop 'is_unify_pirce' => input('is_unify_pirce','1'), 'is_zmxx' => input('is_zmxx',0), 'cat_id' => input('cat_id',''), + 'is_correlation' => input('is_correlation', 0), + 'correlation_type' => input('correlation_type', 1), + 'correlation_goods_ids' => input('correlation_goods_ids', []), ]; $res = $goods_model->editGoods($data); // 处理平台抽成 商品设置 @@ -486,7 +495,13 @@ class Goods extends BaseShop $goods_sku_list = $goods_model->getGoodsSkuList([['goods_id', '=', $goods_id], ['site_id', '=', $this->site_id]], "sku_id,sku_name,sku_no,sku_spec_format,price,market_price,cost_price,stock,weight,volume,sku_image,sku_images,goods_spec_format,goods_supplier_format,spec_name,stock_alarm,is_default", '')['data']; $goods_info['sku_list'] = $goods_sku_list; $this->assign("goods_info", $goods_info); - + // 商品信息 + $goodsIdsArr = $goods_info['correlation_goods_ids'] ?? []; + $goodsList = model('goods')->getList([ + ['goods_id', 'in', $goodsIdsArr] + ], 'goods_id,goods_name,price,goods_stock'); + $this->assign('goods_list', $goodsList); + $this->assign('goods_ids_arr', $goodsIdsArr); //获取一级商品分类 $goods_category_model = new GoodsCategoryModel(); diff --git a/app/shop/view/goods/add_goods.html b/app/shop/view/goods/add_goods.html index bffb523..60cb17e 100644 --- a/app/shop/view/goods/add_goods.html +++ b/app/shop/view/goods/add_goods.html @@ -43,6 +43,15 @@ right: 18px; } .hide{display: none;} + .goods-list{ + margin-top: 10px; + width: 100%; + padding-left: 140px; + display: inline-flex; + } + .goods-list .layui-table-view{ + width: 900px!important; + } {/block} {block name="main"} @@ -683,23 +692,50 @@ - - {if $form_is_exit}
- -
- + +
+ +
-
- 创建商品表单 - 刷新 +
开启后用户购买此产品必须连同关联商品一并购买
+
+ +
+ +
+ + +
+
关联商品是否全部购买才可下单
+
+
+ +
+ + +
+
+
+ + {if $form_is_exit} +
+ +
+ +
+ +
{/if}
@@ -1082,5 +1118,60 @@ {/block} diff --git a/app/shop/view/goods/edit_goods.html b/app/shop/view/goods/edit_goods.html index 0413df3..873b2de 100644 --- a/app/shop/view/goods/edit_goods.html +++ b/app/shop/view/goods/edit_goods.html @@ -43,6 +43,15 @@ right: 18px; } .hide{display: none;} + .goods-list{ + margin-top: 10px; + width: 100%; + padding-left: 140px; + display: inline-flex; + } + .goods-list .layui-table-view{ + width: 900px!important; + } {/block} {block name="main"} @@ -755,6 +764,34 @@ +
+ +
+ + 0} checked {/if}> +
+
开启后用户购买此产品必须连同关联商品一并购买
+
+ +
+ +
+ + +
+
关联商品是否全部购买才可下单
+
+
+ +
+ + +
+
+
+
+
+ {if $form_is_exit}
@@ -1178,6 +1215,8 @@ {/block} diff --git a/app/shop/view/public/js/goods_edit.js b/app/shop/view/public/js/goods_edit.js index e18b077..23f3f48 100644 --- a/app/shop/view/public/js/goods_edit.js +++ b/app/shop/view/public/js/goods_edit.js @@ -19,7 +19,6 @@ var regExp = { number: /^\d{0,10}$/, digit: /^\d{0,10}(.?\d{0,2})$/ }; - // 监听窗口 $(window).resize(function () { var width = $(".layui-tab-content").outerWidth(); @@ -133,7 +132,16 @@ $(function () { type: 'datetime', min: currentTime }); - + //关联商品 + form.on('radio(is_correlation)', function(data){ + if(data.value == 1){ + $('.correlation_type').removeClass('layui-hide'); + $('.correlation_goods_ids').removeClass('layui-hide'); + }else{ + $('.correlation_type').addClass('layui-hide'); + $('.correlation_goods_ids').addClass('layui-hide'); + } + }); //是否上架 form.on('radio(goods_state)', function(data){ value = parseInt(data.value); @@ -1116,8 +1124,11 @@ $(function () { }); + + }); + //社群二维码 function couponSelected() { if (!$("#goods tbody tr input:checked").length) {