commit
f430b87881
@ -6,6 +6,7 @@ namespace app\admin\lists\store_category;
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\user_ship\UserShip;
|
||||
|
||||
|
||||
/**
|
||||
@ -43,11 +44,26 @@ 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'])
|
||||
->field(['id', 'pid', 'name', 'data', 'pic', 'sort', 'price_rate'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
->select()->each(function ($item) use ($userGroups) {
|
||||
if (empty($item['price_rate'])) {
|
||||
$item['price_rate'] = $userGroups;
|
||||
} else {
|
||||
$priceRate = reset_index($item['price_rate'], 'id');
|
||||
foreach ($userGroups as $userGroup) {
|
||||
if (!isset($priceRate[$userGroup['id']])) {
|
||||
$userGroup['rate'] = 0;
|
||||
$priceRate[] = $userGroup;
|
||||
}
|
||||
}
|
||||
$item['price_rate'] = array_values($priceRate);
|
||||
}
|
||||
$item['is_children'] = StoreCategory::where('pid', $item->id)->count(); // 判断是否有子分类
|
||||
return $item->toArray();
|
||||
})
|
||||
|
@ -53,7 +53,13 @@ class StoreProductGroupPriceLists extends BaseAdminDataLists implements ListsSea
|
||||
->select()->each(function ($item) {
|
||||
$item['lists'] =StoreProductGroupPrice::where('product_id',$item['id'])->field('id,group_id,price')
|
||||
->select()->each(function ($item_two){
|
||||
$item_two['group_name']=UserShip::where('id',$item_two['group_id'])->value('title');
|
||||
if ($item_two['group_id'] == 100001) {
|
||||
$item_two['group_name'] = '供货价';
|
||||
} else if ($item_two['group_id'] == 100002) {
|
||||
$item_two['group_name'] = '零售价';
|
||||
} else {
|
||||
$item_two['group_name'] = UserShip::where('id', $item_two['group_id'])->value('title');
|
||||
}
|
||||
});
|
||||
})
|
||||
->toArray();
|
||||
|
@ -48,12 +48,12 @@ class StoreProductPriceLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
$this->searchWhere[]=['product_id','in',$store_id];
|
||||
}
|
||||
return StoreProductPrice::where($this->searchWhere)
|
||||
->field(['id','bhoid','offer_id', 'product_id', 'purchase_price', 'purchase_lv', 'purchase', 'cost_lv', 'cost', 'price_lv', 'price', 'status'])
|
||||
->field(['id','bhoid','offer_id', 'product_id', 'purchase_price', 'purchase_lv', 'purchase', 'cost_lv', 'cost', 'price_lv', 'price', 'price_config', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
$find = StoreProduct::with('unitName')->where('id', $item['product_id'])->field('image,store_name,store_info,unit')->find();
|
||||
$item['unit_name']=$find['unitName']['name'];
|
||||
$find = StoreProduct::with('unitName')->where('id', $item['product_id'])->field('image,store_name,store_info,unit')->withTrashed()->find();
|
||||
$item['unit_name']=$find['unitName']['name'] ?? '';
|
||||
$item['store_name']=$find['store_name'];
|
||||
$item['store_info']=$find['store_info'];
|
||||
$item['image']=$find['image'];
|
||||
|
@ -10,7 +10,9 @@ use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||
use app\common\model\delivery_service\DeliveryService;
|
||||
use app\common\model\dict\DictData;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
||||
use app\common\model\store_product_price\StoreProductPrice;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\user\User;
|
||||
@ -138,38 +140,39 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
'marques' => $params['marques'],
|
||||
'after_sales' => $params['after_sales'],
|
||||
]);
|
||||
$find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('store_name,top_cate_id')->find();
|
||||
// $find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id')->find();
|
||||
$unit_name=StoreProductUnit::where('id', $offer['unit'])->value('name');
|
||||
$dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select();
|
||||
$data = [];
|
||||
$data['bhoid'] = $offer['order_id'];
|
||||
$data['offer_id'] = $params['id'];
|
||||
$data['product_id'] = $offer['product_id'];
|
||||
$data['purchase_price'] = $params['purchase'];
|
||||
$data['status'] = 0;
|
||||
if ($dict_data) {
|
||||
foreach ($dict_data as $k => $v) {
|
||||
if ($v['name'] == 'purchase') {
|
||||
$data['purchase_lv'] = $v['value'];
|
||||
$lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
$data['purchase'] = bcadd($lv, $params['purchase'], 2);
|
||||
} elseif ($v['name'] == 'cost') {
|
||||
$data['cost_lv'] = $v['value'];
|
||||
$lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
$data['cost'] = bcadd($lv, $params['purchase'], 2);
|
||||
} elseif ($v['name'] == 'price') {
|
||||
$data['price_lv'] = $v['value'];
|
||||
$lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
$data['price'] = bcadd($lv, $params['purchase'], 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($find) {
|
||||
$find->save($data);
|
||||
} else {
|
||||
StoreProductPrice::create($data);
|
||||
}
|
||||
self::setProductGroupPrice($params, $product);
|
||||
// $data = [];
|
||||
// $dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select();
|
||||
// $data['bhoid'] = $offer['order_id'];
|
||||
// $data['offer_id'] = $params['id'];
|
||||
// $data['product_id'] = $offer['product_id'];
|
||||
// $data['purchase_price'] = $params['purchase'];
|
||||
// $data['status'] = 0;
|
||||
// if ($dict_data) {
|
||||
// foreach ($dict_data as $k => $v) {
|
||||
// if ($v['name'] == 'purchase') {
|
||||
// $data['purchase_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['purchase'] = bcadd($lv, $params['purchase'], 2);
|
||||
// } elseif ($v['name'] == 'cost') {
|
||||
// $data['cost_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['cost'] = bcadd($lv, $params['purchase'], 2);
|
||||
// } elseif ($v['name'] == 'price') {
|
||||
// $data['price_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['price'] = bcadd($lv, $params['purchase'], 2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if ($find) {
|
||||
// $find->save($data);
|
||||
// } else {
|
||||
// StoreProductPrice::create($data);
|
||||
// }
|
||||
Db::commit();
|
||||
$offer['store_name']=$product['store_name'];
|
||||
$offer['unit_name']=$unit_name;
|
||||
@ -301,4 +304,71 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
{
|
||||
return PurchaseProductOffer::destroy($params['id']);
|
||||
}
|
||||
|
||||
public static function setProductGroupPrice($params, $product)
|
||||
{
|
||||
$productCatePriceRate = StoreCategory::where('id', $product['top_cate_id'])->value('price_rate');
|
||||
if (empty($productCatePriceRate)) {
|
||||
return;
|
||||
}
|
||||
$storeProductGroupPrice = StoreProductGroupPrice::where('product_id', $product['id'])->select()->toArray();
|
||||
$storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id');
|
||||
$priceConfig = [];
|
||||
$data = [
|
||||
'bhoid' => $params['bhoid'],
|
||||
'offer_id' => $params['id'],
|
||||
'product_id' => $product['id'],
|
||||
'purchase_price' => $params['purchase'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
'status' => 0,
|
||||
];
|
||||
foreach ($productCatePriceRate as $k => $v) {
|
||||
if ($v['id'] == 4) {
|
||||
$data['cost_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['cost'] = bcmul($params['purchase'], bcadd($data['cost_lv'], 1, 2), 2);
|
||||
continue;
|
||||
} elseif ($v['id'] == 100001) {
|
||||
$data['purchase_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['purchase'] = bcmul($params['purchase'], bcadd($data['purchase_lv'], 1, 2), 2);
|
||||
continue;
|
||||
} elseif ($v['id'] == 100002) {
|
||||
$data['price_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['price'] = bcmul($params['purchase'], bcadd($data['price_lv'], 1, 2), 1);
|
||||
if ($product['two_cate_id'] == 15268) {
|
||||
$lastNum = substr($data['price'], -1);
|
||||
if ($lastNum <= 2) {
|
||||
$data['price'] = floor($data['price']);
|
||||
} elseif ($lastNum < 5) {
|
||||
$data['price'] = bcadd(floor($data['price']), 0.5, 1);
|
||||
} else {
|
||||
$data['price'] = bcadd(floor($data['price']), 1, 1);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$baseRate = 100 + $v['rate'];
|
||||
$item = [
|
||||
'product_id' => $product['id'],
|
||||
'group_id' => $v['id'],
|
||||
'group_name' => $v['title'],
|
||||
'price' => bcmul($params['purchase'], $baseRate / 100, 2),
|
||||
'price_type' => 3,
|
||||
'base_rate' => $baseRate,
|
||||
];
|
||||
if (isset($storeProductGroupPrice[$v['id']])) {
|
||||
$item['base_rate'] = $storeProductGroupPrice[$v['id']]['base_rate'];
|
||||
$item['price'] = bcmul($params['purchase'], $item['base_rate'] / 100, 2);
|
||||
$item['id'] = $storeProductGroupPrice[$v['id']]['id'];
|
||||
}
|
||||
$priceConfig[] = $item;
|
||||
}
|
||||
$data['price_config'] = $priceConfig;
|
||||
$find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||
if ($find) {
|
||||
$find->save($data);
|
||||
} else {
|
||||
StoreProductPrice::create($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,8 @@ class StoreCategoryLogic extends BaseLogic
|
||||
'name' => $params['name'],
|
||||
'data' => $params['data'],
|
||||
'pic' => $params['pic'],
|
||||
'sort' => $params['sort']
|
||||
'sort' => $params['sort'],
|
||||
'price_rate' => $params['price_rate']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
|
@ -106,6 +106,8 @@ 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','>',4)->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'];
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace app\admin\logic\store_product_price;
|
||||
|
||||
|
||||
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
||||
use app\common\model\store_product_price\StoreProductPrice;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
@ -59,7 +60,8 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
'status' => 1,
|
||||
'purchase' => $params['purchase'],
|
||||
'cost' => $params['cost'],
|
||||
'price' => $params['price']
|
||||
'price' => $params['price'],
|
||||
'price_config' => $params['price_config'],
|
||||
]);
|
||||
StoreProduct::where('id', $find['product_id'])->update([
|
||||
'purchase' => $find['purchase'],
|
||||
@ -73,6 +75,7 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
'vip_price' => $find['cost'],
|
||||
'price' => $find['price']
|
||||
]);
|
||||
self::setProductGroupPrice($find);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
@ -109,6 +112,7 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
'vip_price' => $find['cost'],
|
||||
'price' => $find['price']
|
||||
]);
|
||||
self::setProductGroupPrice($find);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
@ -143,4 +147,28 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
{
|
||||
return StoreProductPrice::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
public static function setProductGroupPrice($storeProductPrice)
|
||||
{
|
||||
$storeProductGroupPrice = StoreProductGroupPrice::where('product_id', $storeProductPrice['product_id'])->select()->toArray();
|
||||
$storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id');
|
||||
$insertData = [];
|
||||
foreach ($storeProductPrice['price_config'] as $k => $v) {
|
||||
$current = $storeProductGroupPrice[$v['group_id']] ?? [];
|
||||
$item = [
|
||||
'product_id' => $storeProductPrice['product_id'],
|
||||
'group_id' => $v['group_id'],
|
||||
'price' => $v['price'],
|
||||
'price_type' => 3,
|
||||
'base_rate' => $v['base_rate'],
|
||||
];
|
||||
if (!empty($current)) {
|
||||
$item['base_rate'] = $current['base_rate'];
|
||||
$item['id'] = $current['id'];
|
||||
}
|
||||
$insertData[] = $item;
|
||||
}
|
||||
(new StoreProductGroupPrice())->saveAll($insertData);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,5 +18,8 @@ class StoreCategory extends BaseModel
|
||||
protected $name = 'store_category';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
protected $json = ['price_rate'];
|
||||
protected $jsonAssoc = true;
|
||||
|
||||
|
||||
}
|
@ -18,5 +18,7 @@ class StoreProductPrice extends BaseModel
|
||||
protected $name = 'store_product_price';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
protected $json = ['price_config'];
|
||||
protected $jsonAssoc = true;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user