添加:商品添加购物协议

This commit is contained in:
wuhui_zzw 2024-03-30 18:05:12 +08:00
parent 3f85b8baa6
commit 34f7b5d187
2 changed files with 47 additions and 10 deletions

View File

@ -372,6 +372,10 @@ class Product extends BaseModel
{
return $this->hasOne(ProductContent::class,'product_id','product_id');
}
public function buyAgreement()
{
return $this->hasOne(ProductContent::class,'product_id','product_id');
}
protected function temp()
{
return $this->hasOne(ShippingTemplate::class,'shipping_template_id','temp_id');

View File

@ -54,7 +54,7 @@ class ProductRepository extends BaseRepository
protected $dao;
const CREATE_PARAMS = [
"is_copy", "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "unit_name", "sort" , "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free','param_temp_id','extend',
"is_copy", "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "unit_name", "sort" , "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content","buy_agreement", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free','param_temp_id','extend',
["mer_cate_id",[]],
['refund_switch',0],
["brand_id",0],
@ -234,16 +234,21 @@ class ProductRepository extends BaseRepository
'content' => $conType ? json_encode($data['content']) : $data['content'] ,
'type' => $conType
];
$buyAgreement = [
'content' => $conType ? json_encode($data['buy_agreement']) : $data['buy_agreement'] ,
'type' => 11
];
$product = $this->setProduct($data);
event('product.create.before', compact('data','productType','conType'));
return Db::transaction(function () use ($data, $productType,$conType,$content,$product) {
return Db::transaction(function () use ($data, $productType,$conType,$content,$buyAgreement,$product) {
$activity_id = 0;
$result = $this->dao->create($product);
$settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0);
$settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']);
$settleParams['attr'] = $this->setAttr($data['attr'], $result->product_id);
if ($productType ==0 ) app()->make(ParameterValueRepository::class)->create($result->product_id, $data['params'] ?? [],$data['mer_id']);
$this->save($result->product_id, $settleParams, $content,$product,$productType);
$this->save($result->product_id, $settleParams, $content,$product,$productType, $buyAgreement);
if (in_array($productType, [0, 1])) {
if ($productType == 1) { //秒杀商品
$dat = $this->setSeckillProduct($data);
@ -284,12 +289,17 @@ class ProductRepository extends BaseRepository
'content' => $conType ? json_encode($data['content']) : $data['content'] ,
'type' => $conType
];
$buyAgreement = [
'content' => $conType ? json_encode($data['buy_agreement']) : $data['buy_agreement'] ,
'type' => 11
];
$spuData['price'] = $settleParams['data']['price'];
$spuData['mer_id'] = $merId;
$spuData['mer_labels'] = $data['mer_labels'];
Db::transaction(function () use ($id, $data, $productType, $settleParams,$content,$product,$spuData,$merId) {
$this->save($id, $settleParams, $content, $product, $productType);
Db::transaction(function () use ($id, $data, $productType, $settleParams,$content,$buyAgreement,$product,$spuData,$merId) {
$this->save($id, $settleParams, $content, $product, $productType,$buyAgreement);
if ($productType == 1) { //秒杀商品
$dat = $this->setSeckillProduct($data);
app()->make(StoreSeckillActiveRepository::class)->updateByProduct($id, $dat);
@ -351,7 +361,7 @@ class ProductRepository extends BaseRepository
* @param $content
* @return int
*/
public function save($id, $settleParams, $content, $data = [], $productType = 0)
public function save($id, $settleParams, $content, $data = [], $productType = 0,$buyAgreement = '')
{
$res = $this->dao->get($id);
@ -378,6 +388,11 @@ class ProductRepository extends BaseRepository
$this->dao->createContent($res->product_id, $content);
}
if ($buyAgreement){
app()->make(ProductContentRepository::class)->clearAttr($res->product_id,$buyAgreement['type']);
$this->dao->createContent($res->product_id, $buyAgreement);
}
if (isset($settleParams['data'])) $data =array_merge($data,$settleParams['data']);
$this->dao->update($id,$data);
if(isset($data['status']) && $data['status'] !== 1 ){
@ -716,12 +731,24 @@ class ProductRepository extends BaseRepository
*/
public function getAdminOneProduct(int $id, ?int $activeId, $conType = 0)
{
$with = ['attr', 'attrValue.productCdkey', 'oldAttrValue', 'merCateId.category', 'storeCategory', 'brand', 'temp', 'seckillActive',
'content' => function($query) use($conType){
$with = [
'attr',
'attrValue.productCdkey',
'oldAttrValue',
'merCateId.category',
'storeCategory',
'brand',
'temp',
'seckillActive',
'content' => function($query) use ($conType){
$query->where('type',$conType);
},
'merchant'=> function($query){
$query->with(['typeName','categoryName'])->field('mer_id,category_id,type_id,mer_avatar,mer_name,is_trader');
'buyAgreement' => function($query) use ($conType){
$query->where('type',11);
},
'merchant' => function($query){
$query->with(['typeName','categoryName'])
->field('mer_id,category_id,type_id,mer_avatar,mer_name,is_trader');
},
'guarantee.templateValue.value',
];
@ -822,6 +849,11 @@ class ProductRepository extends BaseRepository
unset($data['content']);
$data['content'] = $content;
$buyAgreement = $data['buyAgreement']['content'] ?? '';
unset($data['buyAgreement']);
$data['buy_agreement'] = $buyAgreement;
// 查找该商品积分抵扣比例
if(!empty($data['merchant'])) $data['merchant'] = merchantConfig($data['merchant']['mer_id'],['mer_integral_status','mer_integral_rate','mer_integral_money','mer_integral_order_rate']);
@ -1372,6 +1404,7 @@ class ProductRepository extends BaseRepository
if (!$res){
$productType = $product['product_type'];
$res['content'] = $this->getContent($product['product_id']);
$res['buy_agreement'] = app()->make(ProductContentRepository::class)->getWhere(['product_id' => $productId,'type'=>11]);
$res['temp'] = app()->make(ShippingTemplateRepository::class)->getSearch([])->where('shipping_template_id',$product['temp_id'])->find();
if(in_array($product['product_type'],[0,2])) {
$product_id = $product['product_id'];