企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 淘宝导入 淘宝导入 文件路径:shop/controllers/Seller/Goods/TBImportCtl.php; ###### 导入csv文件 商品分类: ``` <pre class="calibre14">``` <span class="token"><</span>select name<span class="token">=</span><span class="token4">"sgcate_id[]"</span> class<span class="token">=</span><span class="token4">"sgcategory"</span><span class="token">></span> <span class="token"><</span>option value<span class="token">=</span><span class="token4">"0"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">__</span><span class="token1">(</span><span class="token4">'请选择'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token"><</span><span class="token">/</span>option<span class="token">></span> <span class="token"><</span><span class="token">?</span>php <span class="token2">if</span> <span class="token1">(</span><span class="token">!</span><span class="token3">empty</span><span class="token1">(</span>$shop_goods_cat_rows<span class="token1">)</span><span class="token1">)</span><span class="token1">{</span> <span class="token">?</span><span class="token">></span> <span class="token"><</span><span class="token">?</span>php foreach <span class="token1">(</span>$shop_goods_cat_rows as $shop_goods_cat_id <span class="token">=</span><span class="token">></span> $shop_goods_cat_data<span class="token1">)</span> <span class="token1">{</span> <span class="token">?</span><span class="token">></span> <span class="token"><</span>option data<span class="token">-</span>parent_id<span class="token">=</span><span class="token4">"<?= $shop_goods_cat_data['parent_id'] ?>"</span> value<span class="token">=</span><span class="token4">"<?= $shop_goods_cat_id ?>"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span> $shop_goods_cat_data<span class="token1">[</span><span class="token4">'shop_goods_cat_name'</span><span class="token1">]</span> <span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>option<span class="token">></span> <span class="token"><</span><span class="token">?</span>php <span class="token1">}</span> <span class="token">?</span><span class="token">></span> <span class="token"><</span><span class="token">?</span>php <span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span> <span class="token">?</span><span class="token">></span> <span class="token"><</span>option value<span class="token">=</span><span class="token4">"-1"</span><span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">__</span><span class="token1">(</span><span class="token4">'暂无分类'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token"><</span><span class="token">/</span>option<span class="token">></span> <span class="token"><</span><span class="token">?</span>php <span class="token1">}</span> <span class="token">?</span><span class="token">></span> <span class="token"><</span><span class="token">/</span>select<span class="token">></span> $<span class="token1">.</span><span class="token3">get</span><span class="token1">(</span>SITE_URL <span class="token">+</span> <span class="token4">'?ctl=Seller_Goods_Cat&met=cat&typ=json'</span><span class="token1">,</span> <span class="token1">{</span>cat_id<span class="token1">:</span> cat_id<span class="token1">}</span><span class="token1">,</span> <span class="token2">function</span><span class="token1">(</span>data<span class="token1">)</span><span class="token1">{</span> <span class="token2">if</span> <span class="token1">(</span>data<span class="token1">.</span>status <span class="token">==</span> <span class="token6">200</span><span class="token1">)</span> <span class="token1">{</span> <span class="token5">//没有数据</span> <span class="token2">if</span><span class="token1">(</span>data<span class="token1">.</span>data<span class="token1">.</span>length <span class="token">===</span> <span class="token6">0</span><span class="token1">)</span><span class="token1">{</span> <span class="token2">return</span> <span class="token6">false</span><span class="token1">;</span> <span class="token1">}</span> var option_rows <span class="token">=</span> <span class="token1">[</span><span class="token1">]</span><span class="token1">,</span> cat_data <span class="token">=</span> data<span class="token1">.</span>data<span class="token1">;</span> <span class="token2">if</span> <span class="token1">(</span>change<span class="token1">)</span> <span class="token1">{</span> option_rows<span class="token1">.</span><span class="token3">push</span><span class="token1">(</span><span class="token4">"<option value='0'>请选择</option>"</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token2">for</span> <span class="token1">(</span>var i <span class="token">=</span> <span class="token6">0</span><span class="token1">;</span> i <span class="token"><</span> cat_data<span class="token1">.</span>length<span class="token1">;</span> i<span class="token">++</span><span class="token1">)</span> <span class="token1">{</span> option_rows<span class="token1">.</span><span class="token3">push</span><span class="token1">(</span><span class="token4">"<option value="</span> <span class="token">+</span> cat_data<span class="token1">[</span>i<span class="token1">]</span><span class="token1">.</span>cat_id <span class="token">+</span> <span class="token4">">"</span> <span class="token">+</span> cat_data<span class="token1">[</span>i<span class="token1">]</span><span class="token1">.</span>cat_name <span class="token">+</span> <span class="token4">"</option>"</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token2">if</span> <span class="token1">(</span>change<span class="token1">)</span><span class="token1">{</span> <span class="token5">//first create select</span> <span class="token2">if</span> <span class="token1">(</span>option_rows<span class="token1">.</span>length <span class="token">></span> <span class="token6">0</span><span class="token1">)</span> <span class="token1">{</span> <span class="token5">//default first goods_cat</span> $<span class="token1">(</span><span class="token4">"#gc_id"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">val</span><span class="token1">(</span>cat_data<span class="token1">[</span><span class="token6">0</span><span class="token1">]</span><span class="token1">.</span>cat_id<span class="token1">)</span><span class="token1">,</span> $<span class="token1">(</span><span class="token4">"#cat_name"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">val</span><span class="token1">(</span>cat_data<span class="token1">[</span><span class="token6">0</span><span class="token1">]</span><span class="token1">.</span>cat_name<span class="token1">)</span><span class="token1">;</span> var next_deep <span class="token">=</span> deep <span class="token">+</span> <span class="token6">1</span><span class="token1">;</span> $<span class="token1">(</span><span class="token4">"span[nctype=gc"</span> <span class="token">+</span> next_deep <span class="token">+</span> <span class="token4">"]"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">append</span><span class="token1">(</span><span class="token4">"<select data-deep="</span> <span class="token">+</span> next_deep <span class="token">+</span> <span class="token4">">"</span> <span class="token">+</span> option_rows<span class="token1">.</span><span class="token3">join</span><span class="token1">(</span><span class="token4">""</span><span class="token1">)</span> <span class="token">+</span> <span class="token4">"</select>"</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span> $select<span class="token1">.</span><span class="token3">append</span><span class="token1">(</span>option_rows<span class="token1">.</span><span class="token3">join</span><span class="token1">(</span><span class="token4">""</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span> Public<span class="token1">.</span>tips<span class="token1">.</span><span class="token3">error</span><span class="token1">(</span>data<span class="token1">.</span>msg<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span> ``` ``` 所在地: ``` <pre class="calibre14">``` <span class="token2">function</span> <span class="token3">getDistrictList</span><span class="token1">(</span>province_id<span class="token1">,</span> change<span class="token1">)</span> <span class="token1">{</span> change <span class="token">&&</span> $<span class="token1">(</span><span class="token4">"#city_id"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">remove</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> <span class="token2">if</span> <span class="token1">(</span>$<span class="token1">.</span><span class="token3">inArray</span><span class="token1">(</span>province_id<span class="token1">,</span> <span class="token1">[</span><span class="token6">1</span><span class="token1">,</span> <span class="token6">2</span><span class="token1">,</span> <span class="token6">9</span><span class="token1">,</span> <span class="token6">22</span><span class="token1">]</span><span class="token1">)</span> <span class="token">!=</span> <span class="token">-</span><span class="token6">1</span><span class="token1">)</span> <span class="token2">return</span><span class="token1">;</span> $<span class="token1">.</span><span class="token3">get</span><span class="token1">(</span>SITE_URL <span class="token">+</span> <span class="token4">'?ctl=Base_District&met=district&pid=0&typ=json'</span><span class="token1">,</span> <span class="token1">{</span>pid<span class="token1">:</span> province_id<span class="token1">}</span><span class="token1">,</span> <span class="token2">function</span> <span class="token1">(</span>data<span class="token1">)</span> <span class="token1">{</span> <span class="token2">if</span> <span class="token1">(</span>data<span class="token1">.</span>status <span class="token">==</span> <span class="token6">200</span><span class="token1">)</span> <span class="token1">{</span> var district_data <span class="token">=</span> data<span class="token1">.</span>data<span class="token1">.</span>items<span class="token1">,</span> district_row <span class="token">=</span> <span class="token1">[</span><span class="token1">]</span><span class="token1">;</span> <span class="token2">for</span> <span class="token1">(</span> var i<span class="token">=</span><span class="token6">0</span><span class="token1">;</span> i<span class="token"><</span>district_data<span class="token1">.</span>length<span class="token1">;</span> i<span class="token">++</span> <span class="token1">)</span> <span class="token1">{</span> district_row<span class="token1">.</span><span class="token3">push</span><span class="token1">(</span><span class="token4">"<option value="</span> <span class="token">+</span> district_data<span class="token1">[</span>i<span class="token1">]</span><span class="token1">.</span>district_id <span class="token">+</span> <span class="token4">">"</span> <span class="token">+</span> district_data<span class="token1">[</span>i<span class="token1">]</span><span class="token1">.</span>district_name <span class="token">+</span> <span class="token4">"</option>"</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> district_row <span class="token">=</span> district_row<span class="token1">.</span><span class="token3">join</span><span class="token1">(</span><span class="token4">""</span><span class="token1">)</span><span class="token1">;</span> <span class="token2">if</span> <span class="token1">(</span>change<span class="token1">)</span> <span class="token1">{</span> $<span class="token1">(</span><span class="token4">'#province_id'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">after</span><span class="token1">(</span><span class="token4">"<select id='city_id'>"</span> <span class="token">+</span> district_row <span class="token">+</span> <span class="token4">"</select>"</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span> $<span class="token1">(</span><span class="token4">'#province_id'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">append</span><span class="token1">(</span>district_row<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span> Public<span class="token1">.</span>tips<span class="token1">.</span><span class="token3">error</span><span class="token1">(</span>data<span class="token1">.</span>msg<span class="token1">)</span> <span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> ``` ``` 新增分类: ``` <pre class="calibre14">``` $<span class="token1">(</span><span class="token4">'#add_sgcategory'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">on</span><span class="token1">(</span><span class="token4">'click'</span><span class="token1">,</span> <span class="token2">function</span> <span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> $<span class="token1">(</span><span class="token4">".sgcategory:last"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">after</span><span class="token1">(</span>$<span class="token1">(</span><span class="token4">".sgcategory:last"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">clone</span><span class="token1">(</span><span class="token6">true</span><span class="token1">)</span><span class="token1">.</span><span class="token3">val</span><span class="token1">(</span><span class="token6">0</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> ``` ``` 文件上传: 上传路径:shop/controllers/UploadCtl.php; 方法名:uploadGoodsExcel(); ##### 上传商品图片 实例化 ``` <pre class="calibre14">``` uploader <span class="token">=</span> WebUploader<span class="token1">.</span><span class="token3">create</span><span class="token1">(</span><span class="token1">{</span> pick<span class="token1">:</span> <span class="token1">{</span> id<span class="token1">:</span> <span class="token4">'#filePicker'</span><span class="token1">,</span> label<span class="token1">:</span> <span class="token4">'点击选择图片'</span> <span class="token1">}</span><span class="token1">,</span> formData<span class="token1">:</span> <span class="token1">{</span> uid<span class="token1">:</span> <span class="token6">123</span> <span class="token1">}</span><span class="token1">,</span> dnd<span class="token1">:</span> <span class="token4">'#dndArea'</span><span class="token1">,</span> paste<span class="token1">:</span> <span class="token4">'#uploader'</span><span class="token1">,</span> chunked<span class="token1">:</span> <span class="token6">false</span><span class="token1">,</span> chunkSize<span class="token1">:</span> <span class="token6">512</span> <span class="token">*</span> <span class="token6">1024</span><span class="token1">,</span> accept<span class="token1">:</span> <span class="token1">{</span> title<span class="token1">:</span> <span class="token4">'taobaoImage'</span><span class="token1">,</span> extensions<span class="token1">:</span> <span class="token4">"tbi,jpg"</span> <span class="token1">}</span><span class="token1">,</span> swf<span class="token1">:</span> BASE_URL <span class="token">+</span> <span class="token4">'/shop/static/common/js/Uploader.swf'</span><span class="token1">,</span> server<span class="token1">:</span> SITE_URL <span class="token">+</span> <span class="token4">"?ctl=Upload&action=uploadTaoBaoImage&typ=json"</span><span class="token1">,</span> fileVal<span class="token1">:</span> <span class="token4">'upfile'</span><span class="token1">,</span> <span class="token5">// 禁掉全局的拖拽功能。这样不会出现图片拖进页面的时候,把图片打开。</span> disableGlobalDnd<span class="token1">:</span> <span class="token6">true</span><span class="token1">,</span> fileNumLimit<span class="token1">:</span> <span class="token6">300</span><span class="token1">,</span> fileSizeLimit<span class="token1">:</span> <span class="token6">200</span> <span class="token">*</span> <span class="token6">1024</span> <span class="token">*</span> <span class="token6">1024</span><span class="token1">,</span> <span class="token5">// 200 M</span> fileSingleSizeLimit<span class="token1">:</span> <span class="token6">50</span> <span class="token">*</span> <span class="token6">1024</span> <span class="token">*</span> <span class="token6">1024</span> <span class="token5">// 50 M</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> ``` ``` 上传路径:shop/controllers/UploadCtl.php; 方法名:uploadTaoBaoImage() ``` <pre class="calibre15">``` <span class="token5">// 生成上传实例对象并完成上传 </span> $up <span class="token">=</span> <span class="token2">new</span> <span class="token3">Yf_Uploader</span><span class="token1">(</span>$field_name<span class="token1">,</span> $config<span class="token1">,</span> <span class="token4">"upload"</span><span class="token1">)</span><span class="token1">;</span> <span class="token5">//修改goods_common表</span> $goodsCommonModel<span class="token">-</span><span class="token">></span><span class="token3">editCommon</span><span class="token1">(</span>$common_id<span class="token1">,</span> <span class="token3">array</span><span class="token1">(</span><span class="token4">"common_image"</span> <span class="token">=</span><span class="token">></span> $image_url<span class="token1">)</span><span class="token1">)</span><span class="token1">;</span> <span class="token5">//修改goods_image</span> $goodsImagesModel<span class="token">-</span><span class="token">></span><span class="token3">editImages</span><span class="token1">(</span> $images_id<span class="token1">,</span> <span class="token3">array</span><span class="token1">(</span><span class="token4">"images_image"</span> <span class="token">=</span><span class="token">></span> $image_url<span class="token1">)</span> <span class="token1">)</span><span class="token1">;</span> <span class="token5">//修改goods_base</span> $goodsBaseModel<span class="token">-</span><span class="token">></span><span class="token3">editBase</span><span class="token1">(</span>$goods_id<span class="token1">,</span> $update_goods_data<span class="token1">,</span> <span class="token6">false</span><span class="token1">)</span><span class="token1">;</span> ``` ```