<noframes id="bhrfl"><address id="bhrfl"></address>

    <address id="bhrfl"></address>

    <noframes id="bhrfl"><address id="bhrfl"><th id="bhrfl"></th></address>

    <form id="bhrfl"><th id="bhrfl"><progress id="bhrfl"></progress></th></form>

    <em id="bhrfl"><span id="bhrfl"></span></em>

    全部
    常見問題
    產品動態
    精選推薦

    商品采集參數未保存問題

    管理 管理 編輯 刪除

    問題說明:商品采集參數未保存

    修改文件: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.www.2233z.cn/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}} LV.{{ item.user_info.bbs_level }}

    作者 管理員 企業

    {{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
    {{item.is_suggest == 1? '取消推薦': '推薦'}}
    沙發 板凳 地板 {{item.floor}}#
    {{item.user_info.title || '暫無簡介'}}
    附件

    {{itemf.name}}

    {{item.created_at}}  {{item.ip_address}}
    打賞
    已打賞¥{{item.reward_price}}
    {{item.like_count}}
    {{item.showReply ? '取消回復' : '回復'}}
    刪除
    回復
    回復

    {{itemc.user_info.nickname}}

    {{itemc.user_name}}

    回復 {{itemc.comment_user_info.nickname}}

    附件

    {{itemf.name}}

    {{itemc.created_at}}
    打賞
    已打賞¥{{itemc.reward_price}}
    {{itemc.like_count}}
    {{itemc.showReply ? '取消回復' : '回復'}}
    刪除
    回復
    回復
    查看更多
    打賞
    已打賞¥{{reward_price}}
    1492
    {{like_count}}
    {{collect_count}}
    添加回復 ({{post_count}})

    相關推薦

    快速安全登錄

    使用微信掃碼登錄
    {{item.label}} 加精
    {{item.label}} {{item.label}} 板塊推薦 常見問題 產品動態 精選推薦 首頁頭條 首頁動態 首頁推薦
    取 消 確 定
    回復
    回復
    問題:
    問題自動獲取的帖子內容,不準確時需要手動修改. [獲取答案]
    答案:
    提交
    bug 需求 取 消 確 定
    打賞金額
    當前余額:¥{{rewardUserInfo.reward_price}}
    {{item.price}}元
    請輸入 0.1-{{reward_max_price}} 范圍內的數值
    打賞成功
    ¥{{price}}
    完成 確認打賞

    微信登錄/注冊

    切換手機號登錄

    {{ bind_phone ? '綁定手機' : '手機登錄'}}

    {{codeText}}
    切換微信登錄/注冊
    暫不綁定
    亚洲欧美字幕
    CRMEB客服

    CRMEB咨詢熱線 咨詢熱線

    400-8888-794

    微信掃碼咨詢

    CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
    返回頂部 返回頂部
    CRMEB客服