commit
f430b87881
@ -6,6 +6,7 @@ namespace app\admin\lists\store_category;
|
|||||||
use app\admin\lists\BaseAdminDataLists;
|
use app\admin\lists\BaseAdminDataLists;
|
||||||
use app\common\model\store_category\StoreCategory;
|
use app\common\model\store_category\StoreCategory;
|
||||||
use app\common\lists\ListsSearchInterface;
|
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
|
public function lists(): array
|
||||||
{
|
{
|
||||||
|
$userGroups = UserShip::field('id,title')->select()->toArray();
|
||||||
|
$userGroups[] = ['id' => 100001, 'title' => '供货价'];
|
||||||
|
$userGroups[] = ['id' => 100002, 'title' => '零售价'];
|
||||||
return StoreCategory::where($this->searchWhere)
|
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)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->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(); // 判断是否有子分类
|
$item['is_children'] = StoreCategory::where('pid', $item->id)->count(); // 判断是否有子分类
|
||||||
return $item->toArray();
|
return $item->toArray();
|
||||||
})
|
})
|
||||||
|
@ -53,7 +53,13 @@ class StoreProductGroupPriceLists extends BaseAdminDataLists implements ListsSea
|
|||||||
->select()->each(function ($item) {
|
->select()->each(function ($item) {
|
||||||
$item['lists'] =StoreProductGroupPrice::where('product_id',$item['id'])->field('id,group_id,price')
|
$item['lists'] =StoreProductGroupPrice::where('product_id',$item['id'])->field('id,group_id,price')
|
||||||
->select()->each(function ($item_two){
|
->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();
|
->toArray();
|
||||||
|
@ -48,12 +48,12 @@ class StoreProductPriceLists extends BaseAdminDataLists implements ListsSearchIn
|
|||||||
$this->searchWhere[]=['product_id','in',$store_id];
|
$this->searchWhere[]=['product_id','in',$store_id];
|
||||||
}
|
}
|
||||||
return StoreProductPrice::where($this->searchWhere)
|
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)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()->each(function($item){
|
->select()->each(function($item){
|
||||||
$find = StoreProduct::with('unitName')->where('id', $item['product_id'])->field('image,store_name,store_info,unit')->find();
|
$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['unit_name']=$find['unitName']['name'] ?? '';
|
||||||
$item['store_name']=$find['store_name'];
|
$item['store_name']=$find['store_name'];
|
||||||
$item['store_info']=$find['store_info'];
|
$item['store_info']=$find['store_info'];
|
||||||
$item['image']=$find['image'];
|
$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\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||||
use app\common\model\delivery_service\DeliveryService;
|
use app\common\model\delivery_service\DeliveryService;
|
||||||
use app\common\model\dict\DictData;
|
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\StoreProduct;
|
||||||
|
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
||||||
use app\common\model\store_product_price\StoreProductPrice;
|
use app\common\model\store_product_price\StoreProductPrice;
|
||||||
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;
|
||||||
@ -138,38 +140,39 @@ class PurchaseProductOfferLogic extends BaseLogic
|
|||||||
'marques' => $params['marques'],
|
'marques' => $params['marques'],
|
||||||
'after_sales' => $params['after_sales'],
|
'after_sales' => $params['after_sales'],
|
||||||
]);
|
]);
|
||||||
$find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
// $find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||||
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('store_name,top_cate_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');
|
$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();
|
self::setProductGroupPrice($params, $product);
|
||||||
$data = [];
|
// $data = [];
|
||||||
$data['bhoid'] = $offer['order_id'];
|
// $dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select();
|
||||||
$data['offer_id'] = $params['id'];
|
// $data['bhoid'] = $offer['order_id'];
|
||||||
$data['product_id'] = $offer['product_id'];
|
// $data['offer_id'] = $params['id'];
|
||||||
$data['purchase_price'] = $params['purchase'];
|
// $data['product_id'] = $offer['product_id'];
|
||||||
$data['status'] = 0;
|
// $data['purchase_price'] = $params['purchase'];
|
||||||
if ($dict_data) {
|
// $data['status'] = 0;
|
||||||
foreach ($dict_data as $k => $v) {
|
// if ($dict_data) {
|
||||||
if ($v['name'] == 'purchase') {
|
// foreach ($dict_data as $k => $v) {
|
||||||
$data['purchase_lv'] = $v['value'];
|
// if ($v['name'] == 'purchase') {
|
||||||
$lv = bcmul($v['value'], $params['purchase'], 2);
|
// $data['purchase_lv'] = $v['value'];
|
||||||
$data['purchase'] = bcadd($lv, $params['purchase'], 2);
|
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||||
} elseif ($v['name'] == 'cost') {
|
// $data['purchase'] = bcadd($lv, $params['purchase'], 2);
|
||||||
$data['cost_lv'] = $v['value'];
|
// } elseif ($v['name'] == 'cost') {
|
||||||
$lv = bcmul($v['value'], $params['purchase'], 2);
|
// $data['cost_lv'] = $v['value'];
|
||||||
$data['cost'] = bcadd($lv, $params['purchase'], 2);
|
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||||
} elseif ($v['name'] == 'price') {
|
// $data['cost'] = bcadd($lv, $params['purchase'], 2);
|
||||||
$data['price_lv'] = $v['value'];
|
// } elseif ($v['name'] == 'price') {
|
||||||
$lv = bcmul($v['value'], $params['purchase'], 2);
|
// $data['price_lv'] = $v['value'];
|
||||||
$data['price'] = bcadd($lv, $params['purchase'], 2);
|
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||||
}
|
// $data['price'] = bcadd($lv, $params['purchase'], 2);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if ($find) {
|
// }
|
||||||
$find->save($data);
|
// if ($find) {
|
||||||
} else {
|
// $find->save($data);
|
||||||
StoreProductPrice::create($data);
|
// } else {
|
||||||
}
|
// StoreProductPrice::create($data);
|
||||||
|
// }
|
||||||
Db::commit();
|
Db::commit();
|
||||||
$offer['store_name']=$product['store_name'];
|
$offer['store_name']=$product['store_name'];
|
||||||
$offer['unit_name']=$unit_name;
|
$offer['unit_name']=$unit_name;
|
||||||
@ -301,4 +304,71 @@ class PurchaseProductOfferLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
return PurchaseProductOffer::destroy($params['id']);
|
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'],
|
'name' => $params['name'],
|
||||||
'data' => $params['data'],
|
'data' => $params['data'],
|
||||||
'pic' => $params['pic'],
|
'pic' => $params['pic'],
|
||||||
'sort' => $params['sort']
|
'sort' => $params['sort'],
|
||||||
|
'price_rate' => $params['price_rate']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
|
@ -106,6 +106,8 @@ class StoreProductGroupPriceLogic extends BaseLogic
|
|||||||
$arr=StoreProductGroupPrice::where('product_id',$params['product_id'])->select()->toArray();
|
$arr=StoreProductGroupPrice::where('product_id',$params['product_id'])->select()->toArray();
|
||||||
$purchase=StoreProduct::where('id',$params['product_id'])->value('purchase');
|
$purchase=StoreProduct::where('id',$params['product_id'])->value('purchase');
|
||||||
$arr_two=UserShip::where('id','>',4)->select()->toArray();
|
$arr_two=UserShip::where('id','>',4)->select()->toArray();
|
||||||
|
$arr_two[] = ['id' => 100001, 'title' => '供货价'];
|
||||||
|
$arr_two[] = ['id' => 100002, 'title' => '零售价'];
|
||||||
foreach ($arr_two as $k=>$v){
|
foreach ($arr_two as $k=>$v){
|
||||||
$arr_two[$k]['purchase']=$purchase;
|
$arr_two[$k]['purchase']=$purchase;
|
||||||
$arr_two[$k]['product_id']=$params['product_id'];
|
$arr_two[$k]['product_id']=$params['product_id'];
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace app\admin\logic\store_product_price;
|
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\model\store_product_price\StoreProductPrice;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
@ -59,7 +60,8 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
'status' => 1,
|
'status' => 1,
|
||||||
'purchase' => $params['purchase'],
|
'purchase' => $params['purchase'],
|
||||||
'cost' => $params['cost'],
|
'cost' => $params['cost'],
|
||||||
'price' => $params['price']
|
'price' => $params['price'],
|
||||||
|
'price_config' => $params['price_config'],
|
||||||
]);
|
]);
|
||||||
StoreProduct::where('id', $find['product_id'])->update([
|
StoreProduct::where('id', $find['product_id'])->update([
|
||||||
'purchase' => $find['purchase'],
|
'purchase' => $find['purchase'],
|
||||||
@ -73,6 +75,7 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
'vip_price' => $find['cost'],
|
'vip_price' => $find['cost'],
|
||||||
'price' => $find['price']
|
'price' => $find['price']
|
||||||
]);
|
]);
|
||||||
|
self::setProductGroupPrice($find);
|
||||||
}
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
@ -109,6 +112,7 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
'vip_price' => $find['cost'],
|
'vip_price' => $find['cost'],
|
||||||
'price' => $find['price']
|
'price' => $find['price']
|
||||||
]);
|
]);
|
||||||
|
self::setProductGroupPrice($find);
|
||||||
}
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
@ -143,4 +147,28 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
return StoreProductPrice::findOrEmpty($params['id'])->toArray();
|
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 $name = 'store_category';
|
||||||
protected $deleteTime = 'delete_time';
|
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 $name = 'store_product_price';
|
||||||
protected $deleteTime = 'delete_time';
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
protected $json = ['price_config'];
|
||||||
|
protected $jsonAssoc = true;
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user