ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
:-: 发布新商品 文件路径:shop/controllers/Seller/GoodsCtl.php; 发布:add(); 编辑:online();参数:action=edit_goods ##### 1、选择分类 显示分类: $Goods_CatModel = new Goods_CatModel(); $cat_rows = $Goods_CatModel->getCatTreeData(0, false, 0, true); foreach ($cat_rows as $cat_id=>$cat_row) { ?> <li id="<?=$cat_row['cat_id']?>|<?=$cat_row['cat_level']?>" onclick="selClass(this);" class=""><a href="javascript:void(0)"><i class="iconfont icon-angle-right"></i><?=$cat_row['cat_name']?></a></li> <?php } ?> 选择分类: function selClass(obj){ $('.item_list').css('background',''); $("#span").hide(); $("#dt").show(); $("#dd").show(); $(obj).siblings('li').children('a').attr('class',''); $(obj).children('a').attr('class','selected'); tonextClass(obj.id); } ##### 2、填写商品信息 商品品牌: <select name="brand_id" class="w250" onchange="brandName(this)" > <option value=""><?=__('请选择')?></option> <?php foreach ( $data['brand'] as $key => $val ) { ?> <option <?php if(!empty($common_data) && $common_data['brand_id']==$val['brand_id']) echo 'selected'; ?> value="<?php echo $val['brand_id']; ?>"><?php echo $val['brand_name']; ?></option> <?php } ?> </select> function brandName(e) { var brandName = $(e).find(':selected').html(); $('input[name="brand_name"]').val(brandName); } 商品属性: <?php foreach ( $data['property'] as $key => $val ) { ?> <?php if ( $val['property_format'] == 'select' ) { ?> <tr> <th style="width: 15%;"><?php echo $val['property_name'] ?>:</th> <td> <input type='hidden' name='property[property_<?php echo $val['property_id']; ?>][0]' value='<?php echo $val['property_name']; ?>'/> <input type='hidden' name='property[property_<?php echo $val['property_id']; ?>][2]' value='select'/> <select name='property[property_<?php echo $val['property_id']; ?>][1]'> <?php if ( !empty($val['property_values']) ) { ?> <?php foreach ($val['property_values'] as $k => $v){ ?> <option <?php if ( !empty($common_data) && $common_data['common_property']['property_' . $val['property_id']][1] == $v['property_value_id'] ) { echo 'selected'; } ?> value='<?php echo $v['property_value_id'] ?>'><?php echo $v['property_value_name']; ?></option> <?php } ?> <?php } ?> </select></td></tr> <?php } else if ( $val['property_format'] == 'checkbox' ) { ?> <tr> <th><?php echo $val['property_name']; ?>:</th> <td><dd class="spec"><ul> <?php if ( !empty($val['property_values']) ) { ?> <input type='hidden' name='property[property_<?php echo $val['property_id']; ?>][0]' value='<?php echo $val['property_name']; ?>'/> <input type='hidden' name='property[property_<?php echo $val['property_id']; ?>][2]' value='checkbox'/> <?php foreach ($val['property_values'] as $k => $v){ ?> <li> <span data-type="input_checkbox"> <input type="checkbox" value="<?php echo $v['property_value_id'] ?>" data-type="<?php echo $v['property_value_id'] ?>" name="property[property_<?php echo $val['property_id']; ?>][1][<?php echo $v['property_value_id']; ?>]"> </span> <span data-type="pv_name"><?php echo $v['property_value_name']; ?></span> </li> <?php } ?> <?php } ?> </ul></dd></dl></form> <?php } else { ?> <tr> <th><?php echo $val['property_name']; ?>:</th> <td> <input type='hidden' name='property[property_<?php echo $val['property_id']; ?>][0]' value='<?php echo $val['property_name']; ?>'/> <input type='hidden' name='property[property_<?php echo $val['property_id']; ?>][2]' value='text'/> <input class='text' type='text' name='property[property_<?php echo $val['property_id']; ?>][1]' value='<?php if ( !empty($common_data) ) { echo $common_data['common_property']['property_' . $val['property_id']][1]; } ?>'> </td></tr> <?php } ?> <?php } ?> 添加规格值: $('a[data-type="add-spec"]').click(function(){ var _parent = $(this).parents('li:first'); _parent.find('div[data-type="add-spec1"]').hide(); _parent.find('div[data-type="add-spec2"]').show(); _parent.find('input').focus(); }); 取消规格: $('a[data-type="add-spec-cancel"]').click(function(){ var _parent = $(this).parents('li:first'); _parent.find('div[data-type="add-spec1"]').show(); _parent.find('div[data-type="add-spec2"]').hide(); _parent.find('input').val(''); }); 提交规格: $('a[data-type="add-spec-submit"]').on('click',function(){ var _parent = $(this).parents('li:first'); eval('var data_str = ' + _parent.attr('data-param')); var _input = _parent.find('input'); if(_input.val()) { var url = SITE_URL + "?ctl=Seller_Goods_Spec&met=saveSpecValue&typ=json&position=storeAddGoods"; $.getJSON(url, {class_id : data_str.class_id , spec_id : data_str.spec_id , name : _input.val()}, function(data){ if (data.status == 200) { var data = data.data; _parent.before('<li><span nctype="input_checkbox" data-type="input_checkbox"><input type="checkbox" name="spec_val[' + data_str.spec_id + '][' + data.spec_value_id + ']" nc_type="' + data.spec_value_id + '" data-type="' + data.spec_value_id + '" value="' +_input.val()+ '" /></span><span nctype="pv_name" data-type="pv_name">' + _input.val() + '</span></li>'); _input.val(''); } _parent.find('div[data-type="add-spec1"]').show(); _parent.find('div[data-type="add-spec2"]').hide(); }); } }); //如果存在旧规格 $flag = $this->goodsSpecValueModel->editSpecValue($key, $update_data); //如果存在新规格 $this->goodsSpecValueModel->addSpecValue($update_data); //商城添加规格值 $spec_value_id = $this->goodsSpecValueModel->addSpecValue($update_data, true); 选择售卖区域: $('#postageButton').on('click', function () { var falg = true; if ( falg ) { falg = false; $.dialog({ title: '选择售卖区域', content: 'url:' + SITE_URL + '?ctl=Seller_Transport&met=chooseTranDialog&typ=e', data: { callback: callback }, width: 800, height: 400, max: false, min: false, lock: true }); } }); //售卖区域 $data = $type_model->getByWhere(array('shop_id'=>$shop_id)); foreach ($data as $key => $value){ $area_ids = array(); if($value['area_ids'] == 0){ $data[$key]['area_name'] = __('全国'); }else{ $district_name = $type_model->getDistrictName($value['area_ids']); $data[$key]['area_name'] = mb_strimwidth($district_name, 0, 20, '...', 'utf8'); } } 新增分类: $('#add_sgcategory').on('click', function () { $(".sgcategory:last").after($(".sgcategory:last").clone(true).val(0)); }); 图片空间: $('#image_space').on('click', function () { aloneImage = $.dialog({ content: 'url: ' + SITE_URL + '?ctl=Upload&met=image&typ=e', height: 585, width: 900, data: { callback: function( list ) { //只取第一张图片 $('#goodsImage').prop('src', list[0].src); $('#imagePath').prop('value', list[0].src).isValid(); } } }) }); 商品提交: $.post( SITE_URL + "?ctl=Seller_Goods&met=addOrEditShopGoods&typ=json", $('#form').serialize(), function(data) { if( data.status == 200 ) { Public.tips({ content: '保存成功!', type: 3 }); setTimeout(function () { if ( data.data.action && data.data.action == 'edit' ) { if(data.data.dist_goods){ window.location.href = SITE_URL + "?ctl=Seller_Supplier_Goods&met=online&typ=e"; }else{ window.location.href = SITE_URL + "?ctl=Seller_Goods&met=online&typ=e"; } } else { window.location.href = SITE_URL + "?ctl=Seller_Goods&met=add&action=goodsImageManage&typ=e&common_id=" + data.data.common_id; } }, 3000); } else { if(data.msg=='') { data.msg = '保存失败!'; } Public.tips({ content: data.msg, type: 1 }); firstSub = true; } }); 商品发布提交: $common_id = $this->goodsCommonModel->addCommon($common_data, true); 商品编辑提交: $edit_status = $this->goodsCommonModel->editCommon($common_id, $common_data); 将商品同步到im: $rs = get_url_with_encrypt($key, sprintf('%s?ctl=Api_User_Goods&met=addOrEditUserGoods&typ=json', $url), $formvars); 编辑商品详情: 添加详情:$this->goodsCommonDetailModel->addCommonDetail($common_detail_data); 编辑详情:$this->goodsCommonDetailModel->editCommonDetail($common_id, $common_detail_data); 修改库存配置: 添加库存:$goods_id = $this->goodsBaseModel->addBase($goods_data, true); 修改库存:$goods_id = $this->goodsBaseModel->editBase($retain_f_goods_id, $goods_data, false); 添加或修改成功后向统计中心发送数据: 添加: Yf_Plugin_Manager::getInstance()->trigger('analyticsGoodsAdd',$analytics_data); 编辑: Yf_Plugin_Manager::getInstance()->trigger('analyticsGoodsEdit',$analytics_data);