作者 SHW\戥岁。。

判断是否打折

... ... @@ -503,12 +503,18 @@ class Litestoregoods extends Backend
$goods_ids = explode(',', $goods_ids);
//接收所设置的折扣
$discount = $this->request->get('discount');
$discount = ($discount > 10) ? 10 : $discount;
$new_discount = $discount / 10;
foreach ($goods_ids as &$v) {
$spec_goods_ids = Db::name('litestore_goods_spec')->where('goods_id', $v)->field('goods_spec_id,goods_price')->select();
$spec_goods_ids = Db::name('litestore_goods_spec')->where('goods_id', $v)->field('goods_spec_id,goods_price,line_price')->select();
foreach ($spec_goods_ids as &$item) {
$goods_price = round($item['goods_price'] * $new_discount, 1);
Db::name('litestore_goods_spec')->where('goods_spec_id', $item['goods_spec_id'])->update(['discount' => $discount, 'goods_price' => $goods_price]);
//如果是十折则代表不再打折,否则就进行打折
if ($discount == 10) {
Db::name('litestore_goods_spec')->where('goods_spec_id', $item['goods_spec_id'])->update(['discount' => $discount]);
} else {
$goods_price = round($item['line_price'] * $new_discount, 1);
Db::name('litestore_goods_spec')->where('goods_spec_id', $item['goods_spec_id'])->update(['discount' => $discount, 'goods_price' => $goods_price]);
}
}
}
$this->success('设置成功');
... ...
... ... @@ -418,7 +418,7 @@ class Classification extends Api
$item['line_price'] = round($goods_spec['line_price'], 2);
//判断是否打折
$item['is_discount'] = 'is';
if (empty($goods_spec['discount'])) {
if (empty($goods_spec['discount']) || $goods_spec['discount'] == 10) {
$item['is_discount'] = 'no';
}
$item['discount'] = $goods_spec['discount'] . '折';
... ... @@ -459,7 +459,7 @@ class Classification extends Api
$spec_value['cart_number'] = $number ?? 0;
//判断是否打折
$spec_value['is_discount'] = 'is';
if (empty($spec_value['discount'])) {
if (empty($spec_value['discount']) || $spec_value['discount'] == 10) {
$spec_value['is_discount'] = 'no';
}
$spec_value['discount'] = $spec_value['discount'] . '折';
... ... @@ -489,7 +489,7 @@ class Classification extends Api
$item['line_price'] = round($goods_spec['line_price'], 2);
//判断是否打折
$item['is_discount'] = 'is';
if (empty($goods_spec['discount'])) {
if (empty($goods_spec['discount']) || $goods_spec['discount'] == 10) {
$item['is_discount'] = 'no';
}
$item['discount'] = $goods_spec['discount'] . '折';
... ... @@ -531,7 +531,7 @@ class Classification extends Api
$spec_value['cart_number'] = $number ?? 0;
//判断是否打折
$spec_value['is_discount'] = 'is';
if (empty($spec_value['discount'])) {
if (empty($spec_value['discount']) || $spec_value['discount'] == 10) {
$spec_value['is_discount'] = 'no';
}
$spec_value['discount'] = $spec_value['discount'] . '折';
... ...
... ... @@ -62,10 +62,10 @@ class Goods extends Api
$goods['line_price'] = $goods_spec['line_price'];
//判断是否打折
$goods['is_discount'] = 'is';
if (empty($goods_spec['discount'])) {
if (empty($goods_spec['discount']) || $goods_spec['discount'] == 10) {
$goods['is_discount'] = 'no';
}
$goods['discount'] = $goods_spec['discount'].'折';
$goods['discount'] = $goods_spec['discount'] . '折';
// 产地
$makerfor_list = ['1' => '国产', '2' => '进口'];
$goods['makefor'] = isset($makerfor_list[$goods['makefor']]) ? $makerfor_list[$goods['makefor']] : '未知';
... ... @@ -161,10 +161,10 @@ class Goods extends Api
}
//判断是否打折
$value['is_discount'] = 'is';
if (empty($value['discount'])) {
if (empty($value['discount']) || $value['discount'] == 10) {
$value['is_discount'] = 'no';
}
$value['discount'] = $value['discount'].'折';
$value['discount'] = $value['discount'] . '折';
}
$this->success('商品规格', ['list' => $goods_spec, 'sku' => $array]);
}
... ...