feat: 修改商品逻辑并增强商品详情获取功能
This commit is contained in:
parent
d1c648fac7
commit
f0976184b3
@ -44,8 +44,12 @@ class StoreProductLogic extends BaseLogic
|
||||
'purchase' => $params['purchase'],
|
||||
'rose' => $params['rose'],
|
||||
];
|
||||
$rose_price = bcmul($params['cost'], $params['rose'], 2);
|
||||
$data['price'] = bcadd($params['cost'], $rose_price, 2);
|
||||
if ($params['rose'] > 0) {
|
||||
$rose_price = bcmul($params['cost'], $params['rose'], 2);
|
||||
$data['price'] = bcadd($params['cost'], $rose_price, 2);
|
||||
} else {
|
||||
$data['price'] = 0;
|
||||
}
|
||||
$res = StoreProduct::create($data);
|
||||
StoreProductAttrValue::create([
|
||||
"bar_code" => $params["bar_code"] ?? '',
|
||||
@ -98,7 +102,7 @@ class StoreProductLogic extends BaseLogic
|
||||
StoreCategory::where('id', $params['cate_id'])->inc('three')->update();
|
||||
StoreCategory::where('id', $StoreProduct['cate_id'])->dec('three')->update();
|
||||
}
|
||||
StoreProduct::where('id', $params['id'])->update([
|
||||
$data = [
|
||||
'store_name' => $params['store_name'],
|
||||
'image' => $params['image'],
|
||||
'bar_code' => $params['bar_code'] ?? '',
|
||||
@ -108,7 +112,14 @@ class StoreProductLogic extends BaseLogic
|
||||
'cost' => $params['cost'],
|
||||
'purchase' => $params['purchase'],
|
||||
'rose' => $params['rose'],
|
||||
]);
|
||||
];
|
||||
if ($params['rose'] > 0) {
|
||||
$rose_price = bcmul($params['cost'],bcdiv($params['rose'], 100, 2), 2);
|
||||
$data['price'] = bcadd($params['cost'], $rose_price, 2);
|
||||
} else {
|
||||
$data['price'] = 0;
|
||||
}
|
||||
StoreProduct::where('id', $params['id'])->update($data);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
@ -134,7 +145,7 @@ class StoreProductLogic extends BaseLogic
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品列表详情
|
||||
* @notes 获取商品详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
@ -142,7 +153,20 @@ class StoreProductLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return StoreProduct::where('id',$params['id'])->findOrEmpty()->toArray();
|
||||
$data = StoreProduct::where('id', $params['id'])->findOrEmpty()->toArray();
|
||||
if ($data) {
|
||||
$data['cate_arr'] = [];
|
||||
$id_1 = StoreCategory::where('id', $data['cate_id'])->value('pid');
|
||||
if ($id_1) {
|
||||
$id_2 = StoreCategory::where('id', $id_1)->value('pid');
|
||||
if ($id_2 == 0) {
|
||||
$data['cate_arr'] = [$id_1, $data['cate_id']];
|
||||
} else {
|
||||
$data['cate_arr'] = [$id_2, $id_1, $data['cate_id']];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,7 +214,7 @@ class StoreProductLogic extends BaseLogic
|
||||
'price' => $find['price'],
|
||||
'store_id' => $store_id,
|
||||
'sales' => 0,
|
||||
'stock' =>0,
|
||||
'stock' => 0,
|
||||
];
|
||||
StoreBranchProduct::create($product);
|
||||
$arr = [
|
||||
|
@ -21,6 +21,7 @@ class StoreProductValidate extends BaseValidate
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'store_name' => 'require',
|
||||
'rose' => 'require|integer',
|
||||
];
|
||||
|
||||
|
||||
@ -31,6 +32,7 @@ class StoreProductValidate extends BaseValidate
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'store_name' => '商品名称',
|
||||
'rose'=>'上浮比率'
|
||||
];
|
||||
|
||||
|
||||
@ -42,7 +44,7 @@ class StoreProductValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['store_name']);
|
||||
return $this->only(['store_name','rose']);
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +56,7 @@ class StoreProductValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','store_name']);
|
||||
return $this->only(['id','store_name','rose']);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user