修改商品分组价格
This commit is contained in:
parent
7e8f5aacf4
commit
6cdf2b1e09
@ -27,7 +27,7 @@ class StoreProductGroupPriceLists extends BaseAdminDataLists implements ListsSea
|
|||||||
public function setSearch(): array
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'=' => ['id'],
|
'=' => ['product_id'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ use app\common\model\Config;
|
|||||||
use app\common\model\dict\DictType;
|
use app\common\model\dict\DictType;
|
||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
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\store_product_unit\StoreProductUnit;
|
||||||
use app\common\model\user\User;
|
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');
|
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$list = StoreProductGroupPrice::resetProductsPrice($list, $user_ship);
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ use app\common\lists\ListsSortInterface;
|
|||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
use app\common\model\Config;
|
use app\common\model\Config;
|
||||||
|
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
//use app\common\model\goods\GoodsLabel;
|
//use app\common\model\goods\GoodsLabel;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
@ -111,7 +112,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
|
|||||||
$this->searchWhere[] = ['is_show', '=', 1];
|
$this->searchWhere[] = ['is_show', '=', 1];
|
||||||
$this->searchWhere[] = ['product_type', 'in', [0,4]];
|
$this->searchWhere[] = ['product_type', 'in', [0,4]];
|
||||||
// $this->searchWhere[] = ['stock', '>', 0];
|
// $this->searchWhere[] = ['stock', '>', 0];
|
||||||
return StoreProduct::where($this->searchWhere)
|
$list = StoreProduct::where($this->searchWhere)
|
||||||
->field($fields)
|
->field($fields)
|
||||||
->with(['className', 'unitName'])
|
->with(['className', 'unitName'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
@ -127,6 +128,8 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
|
|||||||
return $item;
|
return $item;
|
||||||
})
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
|
$list = StoreProductGroupPrice::resetProductsPrice($list, $user_ship);
|
||||||
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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_order_cart_info\StoreOrderCartInfo;
|
||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
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_log\StoreProductLog;
|
||||||
use app\common\model\store_product_unit\StoreProductUnit;
|
use app\common\model\store_product_unit\StoreProductUnit;
|
||||||
use app\common\model\system_store\SystemStore;
|
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();
|
$find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->find();
|
||||||
} else {
|
} else {
|
||||||
$find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find();
|
$find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find();
|
||||||
|
$find = StoreProductGroupPrice::resetProductPrice($find, $user['user_ship']);
|
||||||
}
|
}
|
||||||
if (!$find) {
|
if (!$find) {
|
||||||
throw new BusinessException('商品不存在');
|
throw new BusinessException('商品不存在');
|
||||||
@ -123,25 +125,8 @@ class OrderLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
unset($cart_select[$k]['id']);
|
unset($cart_select[$k]['id']);
|
||||||
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
|
$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 = self::getProductPrice($v['source'], $off_activity, $params['store_id'], $find, $user);
|
||||||
$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'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$cart_select[$k]['price'] = $price;
|
$cart_select[$k]['price'] = $price;
|
||||||
$cart_select[$k]['cost'] = $find['cost'];
|
$cart_select[$k]['cost'] = $find['cost'];
|
||||||
@ -887,4 +872,30 @@ class OrderLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
return $pay_price;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,5 +18,26 @@ class StoreProductGroupPrice extends BaseModel
|
|||||||
protected $name = 'store_product_group_price';
|
protected $name = 'store_product_group_price';
|
||||||
protected $deleteTime = 'delete_time';
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user