diff --git a/app/admin/lists/store_product_group_price/StoreProductGroupPriceLists.php b/app/admin/lists/store_product_group_price/StoreProductGroupPriceLists.php index 3cf911d7..db95f69c 100644 --- a/app/admin/lists/store_product_group_price/StoreProductGroupPriceLists.php +++ b/app/admin/lists/store_product_group_price/StoreProductGroupPriceLists.php @@ -27,7 +27,7 @@ class StoreProductGroupPriceLists extends BaseAdminDataLists implements ListsSea public function setSearch(): array { return [ - '=' => ['id'], + '=' => ['product_id'], ]; } diff --git a/app/api/lists/order/CartList.php b/app/api/lists/order/CartList.php index e734eb10..d2d6fd7b 100644 --- a/app/api/lists/order/CartList.php +++ b/app/api/lists/order/CartList.php @@ -11,6 +11,7 @@ use app\common\model\Config; use app\common\model\dict\DictType; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_attr_value\StoreProductAttrValue; +use app\common\model\store_product_group_price\StoreProductGroupPrice; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\user\User; @@ -92,6 +93,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); } } + $list = StoreProductGroupPrice::resetProductsPrice($list, $user_ship); return $list; } diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index cffdb016..febedfbd 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -9,6 +9,7 @@ use app\common\lists\ListsSortInterface; use app\common\model\store_product\StoreProduct; use app\common\lists\ListsSearchInterface; use app\common\model\Config; +use app\common\model\store_product_group_price\StoreProductGroupPrice; use app\common\model\user\User; //use app\common\model\goods\GoodsLabel; use think\facade\Db; @@ -111,7 +112,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis $this->searchWhere[] = ['is_show', '=', 1]; $this->searchWhere[] = ['product_type', 'in', [0,4]]; // $this->searchWhere[] = ['stock', '>', 0]; - return StoreProduct::where($this->searchWhere) + $list = StoreProduct::where($this->searchWhere) ->field($fields) ->with(['className', 'unitName']) ->limit($this->limitOffset, $this->limitLength) @@ -127,6 +128,8 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis return $item; }) ->toArray(); + $list = StoreProductGroupPrice::resetProductsPrice($list, $user_ship); + return $list; } diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 4bc03a2f..ed32dbd2 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -24,6 +24,7 @@ use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_attr_value\StoreProductAttrValue; +use app\common\model\store_product_group_price\StoreProductGroupPrice; use app\common\model\store_product_log\StoreProductLog; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\system_store\SystemStore; @@ -101,6 +102,7 @@ class OrderLogic extends BaseLogic $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->find(); } else { $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); + $find = StoreProductGroupPrice::resetProductPrice($find, $user['user_ship']); } if (!$find) { throw new BusinessException('商品不存在'); @@ -123,25 +125,8 @@ class OrderLogic extends BaseLogic } unset($cart_select[$k]['id']); $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 - if ($v['source'] != 4) { - if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 6, 7]))) { - $price = $find['cost']; - } else { - $price = $find['price']; - //单门店活动判断 - if ($params['store_id'] == getenv('ACTIVITY_STORE_ID')) { - $storeBranchPrice = StoreBranchProduct::where('store_id', getenv('ACTIVITY_STORE_ID'))->where('product_id', $v['product_id'])->value('price'); - if ($storeBranchPrice) { - $price = $storeBranchPrice; - } - } - } - if ($off_activity == 0 && $find['top_cate_id'] == 15189 && $user && $user['user_ship'] == 5) { - $price = $find['cost']; - } - } else { - $price = $find['price']; - } + + $price = self::getProductPrice($v['source'], $off_activity, $params['store_id'], $find, $user); $cart_select[$k]['price'] = $price; $cart_select[$k]['cost'] = $find['cost']; @@ -887,4 +872,30 @@ class OrderLogic extends BaseLogic } return $pay_price; } + + public static function getProductPrice($source, $offActivity, $storeId, $product, $user) + { + if ($source == 4) { + return $product['price']; + } + //开启活动或用户身份为 商户、酒店、食堂 展示成本价(即商户价) + //目前已修改为 商品分组报价,根据用户组展示对应的价格 + if ($offActivity == 1 || ($user != null && in_array($user['user_ship'], [4, 6, 7]))) { + $price = $product['cost']; + } else { + $price = $product['price']; + //单门店活动判断 + if ($storeId == getenv('ACTIVITY_STORE_ID')) { + $storeBranchPrice = StoreBranchProduct::where('store_id', getenv('ACTIVITY_STORE_ID'))->where('product_id', $product['id'])->value('price'); + if ($storeBranchPrice) { + $price = $storeBranchPrice; + } + } + } + if ($offActivity == 0 && $product['top_cate_id'] == 15189 && $user && $user['user_ship'] == 5) { + $price = $product['cost']; + } + return $price; + } + } diff --git a/app/common/model/store_product_group_price/StoreProductGroupPrice.php b/app/common/model/store_product_group_price/StoreProductGroupPrice.php index 71cfe984..b6b4e0fe 100644 --- a/app/common/model/store_product_group_price/StoreProductGroupPrice.php +++ b/app/common/model/store_product_group_price/StoreProductGroupPrice.php @@ -18,5 +18,26 @@ class StoreProductGroupPrice extends BaseModel protected $name = 'store_product_group_price'; protected $deleteTime = 'delete_time'; + public static function resetProductsPrice($productList, $userShip) + { + $productIds = array_column($productList, 'product_id'); + $groupPrices = StoreProductGroupPrice::where('group_id', $userShip)->whereIn('product_id', $productIds)->column('product_id,price_type,base_rate,price'); + $groupPrices = reset_index($groupPrices, 'product_id'); + foreach ($productList as &$item) { + if (isset($groupPrices[$item['product_id']])) { + $item['price'] = $groupPrices[$item['product_id']]['price']; + } + } + return $productList; + } + + public static function resetProductPrice($product, $userShip) + { + $groupPrice = StoreProductGroupPrice::where('group_id', $userShip)->whereIn('product_id', $product['id'])->field('product_id,price_type,base_rate,price')->find(); + if (!empty($groupPrice) && $groupPrice['product_id'] == $product['id']) { + $product['price'] = $groupPrice['price']; + } + return $product; + } } \ No newline at end of file