问题说明:商品采集参数未保存
修改文件:app\services\product\product\StoreProductServices
修改方法:save()
public function save(int $id, array $data, int $type = 0, int $relation_id = 0)
{
if (count($data['cate_id']) < 1) throw new AdminException('请选择商品分类');
if ($type == 1 && $relation_id) {
/** @var SystemStoreServices $storeServices */
$storeServices = app()->make(SystemStoreServices::class);
$storeInfo = $storeServices->getStoreInfo($relation_id);
//有自建商品分类权限门店
if ($storeInfo['product_category_status'] && isset($data['store_cate_id']) && count($data['store_cate_id']) < 1) {
throw new AdminException('请选择门店商品分类');
}
}
if (!$data['store_name']) throw new AdminException('请输入商品名称');
if (count($data['slider_image']) < 1) throw new AdminException('请上传商品轮播图');
if ($data['product_type'] == 0 && isset($data['delivery_type']) && count($data['delivery_type']) < 1) throw new AdminException('请选择商品配送方式');
if (in_array($data['product_type'], [1, 2, 3, 4])) {//除普通商品外,都免运费
$data['freight'] = 1;
$data['temp_id'] = 0;
$data['postage'] = 0;
} else {
if ($data['freight'] == 1) {
$data['temp_id'] = 0;
$data['postage'] = 0;
} elseif ($data['freight'] == 2) {
$data['temp_id'] = 0;
} elseif ($data['freight'] == 3) {
$data['postage'] = 0;
}
if ($data['freight'] == 2 && !$data['postage']) {
throw new AdminException('请设置运费金额');
}
if ($data['freight'] == 3 && !$data['temp_id']) {
throw new AdminException('请选择运费模版');
}
}
////供应商商品仅平台
if (isset($data['type']) && $data['type'] == 2) {
$data['delivery_type'] = [1];
$data['applicable_type'] = 0;
}
// 开启ERP后商品编码验证
$isOpen = sys_config('erp_open');
if ($isOpen && $data['product_type'] == 0 && empty($data['code'])) {
throw new AdminException('请输入商品编码');
}
$detail = $data['attrs'];
$attr = $data['items'];
$coupon_ids = $data['coupon_ids'];
//关联补充信息
$relationData = [];
$relationData['cate_id'] = $data['cate_id'] ?? [];
if (isset($data['store_cate_id'])) {
$relationData['store_cate_id'] = $data['store_cate_id'] ?? [];
}
$relationData['brand_id'] = $data['brand_id'] ?? [];
$relationData['store_label_id'] = $data['store_label_id'] ?? [];
$relationData['label_id'] = $data['label_id'] ?? [];
$relationData['ensure_id'] = $data['ensure_id'] ?? [];
$relationData['specs_id'] = $data['specs_id'] ?? [];
$relationData['coupon_ids'] = $data['coupon_ids'] ?? [];
$description = $data['description'];
$data['type'] = $type;
$data['relation_id'] = $relation_id;
$supplier_id = $data['supplier_id'] ?? 0;
if ($supplier_id) {
$data['type'] = 2;
$data['relation_id'] = $supplier_id;
}
if ($data['type'] == 0) {//平台商品不需要审核
$data['is_verify'] = 1;
}
$is_copy = $data['is_copy'];
unset($data['supplier_id'], $data['is_copy']);
//视频
if ($data['video_link'] && strpos($data['video_link'], 'http') === false) {
$data['video_link'] = sys_config('site_url') . $data['video_link'];
}
//品牌
$data['brand_com'] = $data['brand_id'] ? implode(',', $data['brand_id']) : '';
$data['brand_id'] = $data['brand_id'] ? end($data['brand_id']) : 0;
$data['is_vip'] = $type == 0 && in_array(0, $data['is_sub']) ? 1 : 0;
$data['is_sub'] = in_array(1, $data['is_sub']) ? 1 : 0;
$data['product_type'] = intval($data['product_type']);
$data['is_vip_product'] = intval($type == 0 && $data['is_vip_product']);
if($type == 0) {
$data['is_presale_product'] = intval($data['is_presale_product']);
$data['presale_start_time'] = $data['is_presale_product'] ? strtotime($data['presale_time'][0]) : 0;
$data['presale_end_time'] = $data['is_presale_product'] ? strtotime($data['presale_time'][1]) : 0;
if ($data['presale_start_time'] && $data['presale_start_time'] < time()) {
throw new AdminException('预售开始时间不能小于当前时间');
}
if ($data['presale_end_time'] && $data['presale_end_time'] < time()) {
throw new AdminException('预售结束时间不能小于当前时间');
}
}
$data['auto_on_time'] = $data['auto_on_time'] ? strtotime($data['auto_on_time']) : 0;
$data['auto_off_time'] = $data['auto_off_time'] ? strtotime($data['auto_off_time']) : 0;
if ($data['auto_on_time']) {
$data['is_show'] = 0;
}
$data['is_limit'] = intval($data['is_limit']);
if (!$data['is_limit']) {
$data['limit_type'] = 0;
$data['limit_num'] = 0;
} else {
if (!in_array($data['limit_type'], [1, 2])) throw new AdminException('请选择限购类型');
if ($data['limit_num'] <= 0) throw new AdminException('限购数量不能小于1');
}
$data['custom_form'] = json_encode($data['custom_form']);
$storeLabelId = $data['store_label_id'];
if ($data['store_label_id']) {
$data['store_label_id'] = is_array($data['store_label_id']) ? implode(',', $data['store_label_id']) : $data['store_label_id'];
} else {
$data['store_label_id'] = '';
}
if ($data['ensure_id']) {
$data['ensure_id'] = is_array($data['ensure_id']) ? implode(',', $data['ensure_id']) : $data['ensure_id'];
} else {
$data['ensure_id'] = '';
}
if (!$data['specs_id'] && !$data['specs']) {
$data['specs'] = '';
}
if ($data['specs']) {
$specs = [];
if (is_array($data['specs'])) {
/** @var StoreProductSpecsServices $storeProductSpecsServices */
$storeProductSpecsServices = app()->make(StoreProductSpecsServices::class);
foreach ($data['specs'] as $item) {
$specs[] = $storeProductSpecsServices->checkSpecsData($item);
}
$data['specs'] = json_encode($specs);
}
} else {
$data['specs'] = '';
}
if ($data['spec_type'] == 0) {
$attr = [
[
'value' => '规格',
'detailValue' => '',
'attrHidden' => '',
'detail' => ['默认']
]
];
$detail[0]['value1'] = '默认';
$detail[0]['detail'] = ['规格' => '默认'];
}
foreach ($detail as &$item) {
if ($isOpen && $data['product_type'] == 0 && (!isset($item['code']) || !$item['code'])) {
throw new AdminException('请输入【' . ($item['values'] ?? '默认') . '】商品编码');
}
if ($type == 2 && !$item['settle_price']) {
throw new AdminException('请输入结算价');
}
if (isset($item['price']) && $item['price'] > 0 && $type == 2 && $item['settle_price'] > $item['price']) {
throw new AdminException('结算价不能超过商品售价');
}
$item['product_type'] = $data['product_type'];
if ($data['is_sub'] == 0) {
$item['brokerage'] = 0;
$item['brokerage_two'] = 0;
}
if (!isset($item['price'])) $item['price'] = 0;
if (!isset($item['ot_price'])) $item['ot_price'] = 0;
if (!isset($item['settle_price'])) $item['settle_price'] = 0;
if (($item['brokerage'] + $item['brokerage_two']) > $item['price']) {
throw new AdminException('一二级返佣相加不能大于商品售价');
}
//验证次卡商品数据
if ($data['product_type'] == 4) {
if (!isset($item['write_times']) || !$item['write_times']) {
throw new AdminException('请输入核销次数');
}
if (!isset($item['write_valid'])) {
throw new AdminException('请选择核销时效类型');
}
switch ($item['write_valid']) {
case 1://永久
$item['days'] = 0;
$item['section_time'] = [0, 0];
break;
case 2://购买后n天
$item['section_time'] = [0, 0];
if (!isset($item['days']) || !$item['days']) {
throw new AdminException('填写时效天数');
}
break;
case 3://固定时间
$item['days'] = 0;
if (!isset($item['section_time']) || !$item['section_time'] || !is_array($item['section_time']) || count($item['section_time']) != 2) {
throw new AdminException('请选择固定有效时间段或时间格式错误');
}
[$start, $end] = $item['section_time'];
$data['start_time'] = $start ? strtotime($start) : 0;
$data['end_time'] = $end ? strtotime($end) : 0;
if ($data['start_time'] && $data['end_time'] && $data['end_time'] <= $data['start_time']) {
throw new AdminException('请重新选择:结束时间必须大于开始时间');
}
break;
default:
throw new AdminException('请选择核销时效类型');
break;
}
}
}
foreach ($data['activity'] as $k => $v) {
if ($v == '秒杀') {
$data['activity'][$k] = 1;
} elseif ($v == '砍价') {
$data['activity'][$k] = 2;
} elseif ($v == '拼团') {
$data['activity'][$k] = 3;
} else {
$data['activity'][$k] = 0;
}
}
$data['activity'] = implode(',', $data['activity']);
$data['recommend_list'] = count($data['recommend_list']) ? implode(',', $data['recommend_list']) : '';
$data['price'] = min(array_column($detail, 'price'));
$data['settle_price'] = min(array_column($detail, 'settle_price'));
$data['ot_price'] = min(array_column($detail, 'ot_price'));
$data['cost'] = min(array_column($detail, 'cost'));
if (!$data['cost']) {
$data['cost'] = 0;
}
$data['cate_id'] = implode(',', $data['cate_id']);
if (isset($data['store_cate_id'])) {
$data['store_cate_id'] = implode(',', $data['store_cate_id']);
}
$data['label_id'] = implode(',', $data['label_id']);
$data['image'] = $data['slider_image'][0];//封面图
$slider_image = $data['slider_image'];
$data['slider_image'] = json_encode($data['slider_image']);
$data['stock'] = array_sum(array_column($detail, 'stock'));
$stock = min(array_column($detail, 'stock'));
//是否售罄
$data['is_sold'] = $stock ? 0 : 1;
unset($data['description'], $data['coupon_ids'], $data['items'], $data['attrs'], $data['recommend']);
/** @var StoreDescriptionServices $storeDescriptionServices */
$storeDescriptionServices = app()->make(StoreDescriptionServices::class);
/** @var StoreProductAttrServices $storeProductAttrServices */
$storeProductAttrServices = app()->make(StoreProductAttrServices::class);
/** @var StoreProductCouponServices $storeProductCouponServices */
$storeProductCouponServices = app()->make(StoreProductCouponServices::class);
/** @var StoreDiscountsProductsServices $storeDiscountProduct */
$storeDiscountProduct = app()->make(StoreDiscountsProductsServices::class);
/** @var StoreProductVirtualServices $productVirtual */
$productVirtual = app()->make(StoreProductVirtualServices::class);
//同一链接不多次保存
if (!$id && $data['soure_link']) {
$productInfo = $this->dao->getOne(['soure_link' => $data['soure_link'], 'is_del' => 0], 'id');
if ($productInfo) $id = (int)$productInfo['id'];
}
[$skuList, $id, $is_new, $data] = $this->transaction(function () use ($id, $data, $description, $storeDescriptionServices, $storeProductAttrServices, $storeProductCouponServices, $detail, $attr, $coupon_ids, $storeDiscountProduct, $productVirtual, $slider_image) {
if ($id) {
//上下架处理
$this->setShow([$id], $data['is_show']);
$oldInfo = $this->get($id)->toArray();
if ($oldInfo['product_type'] != $data['product_type']) {
throw new AdminException('商品类型不能切换!');
}
//修改不改变商品来源
if ($oldInfo['type']) {
$data['type'] = $oldInfo['type'];
$data['relation_id'] = $oldInfo['relation_id'];
}
unset($data['sales']);
$res = $this->dao->update($id, $data);
if (!$res) throw new AdminException('修改失败');
// 修改优惠套餐商品的运费模版id
$storeDiscountProduct->update(['product_id' => $id], ['temp_id' => $data['temp_id']]);
if (!empty($coupon_ids)) {
$storeProductCouponServices->setCoupon($id, $coupon_ids);
} else {
$storeProductCouponServices->delete(['product_id' => $id]);
}
if ($oldInfo['type'] == 1 && !$oldInfo['pid'] && $data['is_verify'] < 1) {
/** @var StoreCartServices $cartService */
$cartService = app()->make(StoreCartServices::class);
$cartService->batchUpdate([$id], ['status' => 0], 'product_id');
}
$is_new = 1;
} else {
//默认评分
$data['star'] = config('admin.product_default_star');
$data['add_time'] = time();
$data['code_path'] = '';
$data['spu'] = $this->createSpu();
$res = $this->dao->save($data);
if (!$res) throw new AdminException('添加失败');
$id = (int)$res->id;
if (!empty($coupon_ids)) $storeProductCouponServices->setCoupon($id, $coupon_ids);
$is_new = 0;
}
//商品详情
$storeDescriptionServices->saveDescription($id, $description);
$skuList = $storeProductAttrServices->validateProductAttr($attr, $detail, $id, 0, (int)$data['is_vip']);
foreach ($skuList['valueGroup'] as &$item) {
if (!isset($item['sum_stock']) || !$item['sum_stock']) $item['sum_stock'] = $item['stock'] ?? 0;
}
$proudctVipPrice = 0;
$detailTemp = array_column($skuList['valueGroup'], 'vip_price');
if ($detailTemp) {
$proudctVipPrice = min($detailTemp);
}
$this->dao->update($id, ['vip_price' => $proudctVipPrice]);
$valueGroup = $storeProductAttrServices->saveProductAttr($skuList, $id);
if (!$valueGroup) throw new AdminException('添加失败!');
if ($data['product_type'] == 1) {
$productVirtual->saveProductVirtual($id, $valueGroup);
}
return [$skuList, $id, $is_new, $data];
});
event('product.create', [$id, $data, $skuList, $is_new, $slider_image, $description, $is_copy, $relationData]);
}
后台商品详情页:
src/pages/product/productAdd/index.vue,找到这个文件,搜索“添加参数”,修改这段代码。
src/pages/product/components/productDetails.vue,找到这个文件,搜索“添加参数”,修改这段代码。
后台文件修改完成后需要重新打包,打包文档: https://doc.crmeb.com/pro/crmebprov3_1/15816
{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}
作者 管理员 企业
{{itemf.name}}
{{itemc.user_info.nickname}}
{{itemc.user_name}}
回复 {{itemc.comment_user_info.nickname}}
{{itemf.name}}