作者 SHW\戥岁。。

计算折扣

... ... @@ -21,7 +21,7 @@ class Litestoregoods extends Model
'spec_type_text',
'deduct_stock_type_text',
'goods_status_text',
'is_delete_text'
'is_delete_text',
];
... ... @@ -36,32 +36,32 @@ class Litestoregoods extends Model
public function getSpecTypeList()
{
return ['10' => __('Spec_type 10'),'20' => __('Spec_type 20')];
return ['10' => __('Spec_type 10'), '20' => __('Spec_type 20')];
}
public function getDeductStockTypeList()
{
return ['10' => __('Deduct_stock_type 10'),'20' => __('Deduct_stock_type 20')];
return ['10' => __('Deduct_stock_type 10'), '20' => __('Deduct_stock_type 20')];
}
public function getMakeforList()
{
return ['1' => __('Makefor 1'),'2' => __('Makefor 2')];
return ['1' => __('Makefor 1'), '2' => __('Makefor 2')];
}
public function getIsIndexList()
{
return ['0' => __('Is_index 0'),'1' => __('Is_index 1')];
return ['0' => __('Is_index 0'), '1' => __('Is_index 1')];
}
public function getGoodsStatusList()
{
return ['10' => __('Goods_status 10'),'20' => __('Goods_status 20')];
return ['10' => __('Goods_status 10'), '20' => __('Goods_status 20')];
}
public function getIsDeleteList()
{
return ['0' => __('Is_delete 0'),'1' => __('Is_delete 1')];
return ['0' => __('Is_delete 0'), '1' => __('Is_delete 1')];
}
... ... @@ -118,7 +118,7 @@ class Litestoregoods extends Model
*/
public function spec()
{
return $this->hasMany('Litestoregoodsspec','goods_id','goods_id');
return $this->hasMany('Litestoregoodsspec', 'goods_id', 'goods_id');
}
/**
... ... @@ -126,7 +126,7 @@ class Litestoregoods extends Model
*/
public function specRel()
{
return $this->belongsToMany('Litestorespecvalue', 'litestore_goods_spec_rel','spec_value_id','goods_id');
return $this->belongsToMany('Litestorespecvalue', 'litestore_goods_spec_rel', 'spec_value_id', 'goods_id');
}
/**
... ... @@ -146,7 +146,7 @@ class Litestoregoods extends Model
* @param $isUpdate
* @throws \Exception
*/
public function addGoodsSpec(&$data,$params,$specparams,$isUpdate = false)
public function addGoodsSpec(&$data, $params, $specparams, $isUpdate = false)
{
// 更新模式: 先删除所有规格
$model = new Litestoregoodsspec;
... ... @@ -154,19 +154,22 @@ class Litestoregoods extends Model
// 添加规格数据
if ($data['spec_type'] === '10') {
// 单规格
$specparams['discount'] = (round($specparams['line_price'] / $specparams['goods_price'], 2) * 100) . '折';
$this->spec()->save($specparams);
} else if ($data['spec_type'] === '20') {
// 添加商品与规格关系记录
$model->addGoodsSpecRel($this['goods_id'],$params['spec_attr']);
$model->addGoodsSpecRel($this['goods_id'], $params['spec_attr']);
// 添加商品sku
$model->addSkuList($this['goods_id'],$params['spec_list']);
$model->addSkuList($this['goods_id'], $params['spec_list']);
}
}
public function removesku(){
public function removesku()
{
// 删除商品sku
(new Litestoregoodsspec)->removeAll($this['goods_id']);
}
/**
* 获取规格信息
*/
... ...
<?php
namespace app\admin\model\litestore;
use think\Model;
class Litestoregoodsspec extends Model
... ... @@ -30,6 +31,8 @@ class Litestoregoodsspec extends Model
$data[] = array_merge($item['form'], [
'spec_sku_id' => $item['spec_sku_id'],
'goods_id' => $goods_id,
'discount' => (round($item['form']['line_price'] / $item['form']['goods_price'], 2) * 100) . '折',
]);
}
return $this->saveAll($data);
... ... @@ -66,7 +69,7 @@ class Litestoregoodsspec extends Model
public function removeAll($goods_id)
{
$model = new Litestoregoodsspecrel;
$model->where('goods_id','=', $goods_id)->delete();
return $this->where('goods_id','=', $goods_id)->delete();
$model->where('goods_id', '=', $goods_id)->delete();
return $this->where('goods_id', '=', $goods_id)->delete();
}
}
... ...
... ... @@ -134,6 +134,7 @@ class Classification extends Api
->find();
$item['price'] = $goods_spec['goods_price'];
$item['line_price'] = $goods_spec['line_price'];
$item['discount'] = $goods_spec['discount'];
// 总库存
$item->append(['stock_num']);
});
... ...