全部
常见问题
产品动态
精选推荐

商品采集参数未保存问题

管理 管理 编辑 删除

问题说明:商品采集参数未保存

修改文件: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,找到这个文件,搜索“添加参数”,修改这段代码。

642d4202411071026346410.jpg

src/pages/product/components/productDetails.vue,找到这个文件,搜索“添加参数”,修改这段代码。

98185202411071027534038.png

后台文件修改完成后需要重新打包,打包文档: https://doc.crmeb.com/pro/crmebprov3_1/15816

请登录后查看

轻煮时光 最后编辑于2024-11-07 10:28:02

快捷回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
排序 默认正序 回复倒序 点赞倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest==1? '取消推荐': '推荐'}}
沙发 板凳 地板 {{item.floor}}#
{{item.user_info.title}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

作者 管理员 企业

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}   {{itemc.ip_address}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
回复
回复
201
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

快速安全登录

使用微信扫码登录
{{item.label}} {{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
加精
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 源码下载 CRMEB帮助文档 帮助文档
返回顶部 返回顶部
CRMEB客服