修改商品分类价格配置

This commit is contained in:
lewis 2024-12-27 16:47:56 +08:00
parent 69030f1fbc
commit 26da169c1f
4 changed files with 25 additions and 12 deletions

View File

@ -45,8 +45,6 @@ class StoreCategoryLists extends BaseAdminDataLists implements ListsSearchInterf
public function lists(): array
{
$userGroups = UserShip::field('id,title')->select()->toArray();
$userGroups[] = ['id' => 100001, 'title' => '供货价'];
$userGroups[] = ['id' => 100002, 'title' => '零售价'];
return StoreCategory::where($this->searchWhere)
->field(['id', 'pid', 'name', 'data', 'pic', 'sort', 'price_rate'])
->limit($this->limitOffset, $this->limitLength)
@ -56,13 +54,21 @@ class StoreCategoryLists extends BaseAdminDataLists implements ListsSearchInterf
$item['price_rate'] = $userGroups;
} else {
$priceRate = reset_index($item['price_rate'], 'id');
unset($priceRate[100003], $priceRate[100004]);
$temp = [];
foreach ($userGroups as $userGroup) {
if (!isset($priceRate[$userGroup['id']])) {
$userGroup['rate'] = 0;
$priceRate[] = $userGroup;
if ($userGroup['id'] == 21 && !empty($priceRate[100001]) && empty($userGroup['rate'])) {
$userGroup['rate'] = $priceRate[100001]['rate'];
unset($priceRate[100001]);
} elseif ($userGroup['id'] == 22 && !empty($priceRate[100002]) && empty($userGroup['rate'])) {
$userGroup['rate'] = $priceRate[100002]['rate'];
unset($priceRate[100002]);
} else {
$userGroup['rate'] = $priceRate[$userGroup['id']]['rate'] ?? 0;
}
$temp[] = $userGroup;
}
$item['price_rate'] = array_values($priceRate);
$item['price_rate'] = $temp;
}
$item['is_children'] = StoreCategory::where('pid', $item->id)->count(); // 判断是否有子分类
return $item->toArray();

View File

@ -370,7 +370,7 @@ class PurchaseProductOfferLogic extends BaseLogic
$storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id');
$purchase=0;
foreach ($productCatePriceRate as $k => $v) {
if ($v['id'] == 100001) {
if ($v['id'] == 100001 || $v['id'] == 21) {
//供货
$data['purchase_lv'] = bcdiv($v['rate'], 100, 2);
$data['purchase'] = bcmul($params['purchase'], bcadd($data['purchase_lv'], 1, 2), 2);
@ -384,7 +384,7 @@ class PurchaseProductOfferLogic extends BaseLogic
$data['cost_lv'] = bcdiv($v['rate'], 100, 2);
$data['cost'] = bcmul($purchase, bcadd($data['cost_lv'], 1, 2), 2);
continue;
}elseif ($v['id'] == 100002 &&$purchase>0) {
}elseif (($v['id'] == 100002 || $v['id'] == 22) &&$purchase>0) {
//零售
$data['price_lv'] = bcdiv($v['rate'], 100, 2);
$data['price'] = bcmul($purchase, bcadd($data['price_lv'], 1, 2), 1);

View File

@ -29,12 +29,17 @@ class StoreCategoryLogic extends BaseLogic
{
Db::startTrans();
try {
$priceRate = [];
foreach ($params['price_rate'] as $v) {
$priceRate[$v['id']] = $v;
}
StoreCategory::create([
'pid' => $params['pid'],
'name' => $params['name'],
'data' => $params['data'],
'pic' => $params['pic'],
'sort' => $params['sort']
'sort' => $params['sort'],
'price_rate' => array_values($priceRate)
]);
Db::commit();
@ -57,13 +62,17 @@ class StoreCategoryLogic extends BaseLogic
{
Db::startTrans();
try {
$priceRate = [];
foreach ($params['price_rate'] as $v) {
$priceRate[$v['id']] = $v;
}
StoreCategory::where('id', $params['id'])->update([
'pid' => $params['pid'],
'name' => $params['name'],
'data' => $params['data'],
'pic' => $params['pic'],
'sort' => $params['sort'],
'price_rate' => $params['price_rate']
'price_rate' => array_values($priceRate)
]);
Db::commit();

View File

@ -106,8 +106,6 @@ class StoreProductGroupPriceLogic extends BaseLogic
$arr=StoreProductGroupPrice::where('product_id',$params['product_id'])->select()->toArray();
$purchase=StoreProduct::where('id',$params['product_id'])->value('purchase');
$arr_two=UserShip::where('id','>',0)->select()->toArray();
$arr_two[] = ['id' => 100001, 'title' => '供货价'];
$arr_two[] = ['id' => 100002, 'title' => '零售价'];
foreach ($arr_two as $k=>$v){
$arr_two[$k]['purchase']=$purchase;
$arr_two[$k]['product_id']=$params['product_id'];