mirror of
https://gitee.com/zongzhige/shopxo.git
synced 2024-11-30 10:59:47 +08:00
新增商品数据更新事件+细节优化
This commit is contained in:
parent
aaebb4da8f
commit
0591348acd
@ -67,8 +67,6 @@ class Payment extends Common
|
||||
// 插件更新信息
|
||||
$upgrade = PaymentService::PaymentUpgradeInfo($ret['data']);
|
||||
MyViewAssign('upgrade_info', $upgrade['data']);
|
||||
// print_r($upgrade);
|
||||
// print_r($ret['data']);
|
||||
|
||||
return MyView();
|
||||
}
|
||||
|
@ -187,6 +187,26 @@ class Goods extends Common
|
||||
return ApiService::ApiDataReturn($ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品数量选择
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2018-12-14
|
||||
* @desc description
|
||||
*/
|
||||
public function Stock()
|
||||
{
|
||||
// 开始处理
|
||||
$params = $this->data_post;
|
||||
$ret = GoodsService::GoodsStock($params);
|
||||
if($ret['code'] == 0)
|
||||
{
|
||||
$ret['data'] = $ret['data']['spec_base'];
|
||||
}
|
||||
return ApiService::ApiDataReturn($ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品分类
|
||||
* @author Devil
|
||||
|
@ -179,7 +179,7 @@ class Goods extends Common
|
||||
$this->IsLogin();
|
||||
|
||||
// 开始处理
|
||||
$params = input('post.');
|
||||
$params = $this->data_post;
|
||||
$params['user'] = $this->user;
|
||||
return GoodsFavorService::GoodsFavorCancel($params);
|
||||
}
|
||||
@ -201,7 +201,7 @@ class Goods extends Common
|
||||
}
|
||||
|
||||
// 开始处理
|
||||
$params = input('post.');
|
||||
$params = $this->data_post;
|
||||
return GoodsService::GoodsSpecType($params);
|
||||
}
|
||||
|
||||
@ -222,10 +222,31 @@ class Goods extends Common
|
||||
}
|
||||
|
||||
// 开始处理
|
||||
$params = input('post.');
|
||||
$params = $this->data_post;
|
||||
return GoodsService::GoodsSpecDetail($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品数量选择
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2018-12-14
|
||||
* @desc description
|
||||
*/
|
||||
public function Stock()
|
||||
{
|
||||
// 是否ajax请求
|
||||
if(!IS_AJAX)
|
||||
{
|
||||
return $this->error('非法访问');
|
||||
}
|
||||
|
||||
// 开始处理
|
||||
$params = $this->data_post;
|
||||
return GoodsService::GoodsStock($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品评论
|
||||
* @author Devil
|
||||
|
@ -17,7 +17,7 @@
|
||||
{{include file="public/goods_category" /}}
|
||||
|
||||
<!-- content -->
|
||||
<div class="am-container cart-content">
|
||||
<div class="am-container cart-content" data-ajax-url="{{:MyUrl('index/cart/stock')}}">
|
||||
{{if !empty($cart_list)}}
|
||||
<!-- 商品列表 -->
|
||||
<table class="am-table">
|
||||
@ -79,7 +79,6 @@
|
||||
<span class="original-price">{{$currency_symbol}}{{$goods.original_price}}</span>
|
||||
{{/if}}
|
||||
<strong class="total-price-content">{{$currency_symbol}}{{$goods.price}}</strong>
|
||||
<span class="wap-number">x{{$goods.stock}}</span>
|
||||
</div>
|
||||
|
||||
<!-- 商品基础后面钩子 开始 -->
|
||||
@ -182,9 +181,9 @@
|
||||
|
||||
<!-- 数量操作 -->
|
||||
{{if $goods['is_error'] eq 0}}
|
||||
<div class="am-input-group am-input-group-sm stock-tag" data-inventory="{{$goods.inventory}}" data-price="{{$goods.price}}" data-ajax-url="{{:MyUrl('index/cart/stock')}}">
|
||||
<div class="am-input-group am-input-group-sm stock-tag" data-inventory="{{$goods.inventory}}" data-price="{{$goods.price}}">
|
||||
<span class="am-input-group-label {{if $goods['is_shelves'] eq 1 and $goods['is_delete_time'] eq 0}}stock-submit{{/if}}" data-type="min">-</span>
|
||||
<input type="number" class="am-form-field" value="{{$goods.stock}}" {{if $goods['is_shelves'] neq 1 or $goods['is_delete_time'] neq 0}}disabled{{/if}} />
|
||||
<input type="number" class="am-form-field" value="{{$goods.stock}}" {{if $goods['is_shelves'] neq 1 or $goods['is_delete_time'] neq 0}}disabled{{/if}} data-min-limit="{{$goods.buy_min_number}}" data-max-limit="{{$goods.buy_max_number}}" data-unit="{{$goods.inventory_unit}}" />
|
||||
<span class="am-input-group-label {{if $goods['is_shelves'] eq 1 and $goods['is_delete_time'] eq 0}}stock-submit{{/if}}" data-type="add">+</span>
|
||||
</div>
|
||||
{{else /}}
|
||||
|
@ -380,7 +380,7 @@
|
||||
<dd>
|
||||
<div class="am-input-group am-input-group-sm number-tag">
|
||||
<button class="am-input-group-label" id="min" type="button">-</button>
|
||||
<input type="number" class="am-form-field" value="{{$goods.buy_min_number}}" id="text_box" min="{{$goods.buy_min_number}}" max="{{if empty($goods['buy_max_number'])}}{{$goods.inventory}}{{else /}}{{$goods.buy_max_number}}{{/if}}" data-original-max="{{$goods.inventory}}" />
|
||||
<input type="number" class="am-form-field" value="{{$goods.buy_min_number}}" id="text_box" min="{{$goods.buy_min_number}}" max="{{if empty($goods['buy_max_number'])}}{{$goods.inventory}}{{else /}}{{$goods.buy_max_number}}{{/if}}" data-original-max="{{$goods.inventory}}" data-ajax-url="{{:MyUrl('index/goods/stock')}}" />
|
||||
<button class="am-input-group-label" id="add" type="button">+</button>
|
||||
</div>
|
||||
<span class="tb-hidden stock-tips"><span>库存</span><span class="stock" data-original-stock="{{$goods.inventory}}" data-min-limit="{{$goods.buy_min_number}}" data-max-limit="{{$goods.buy_max_number}}" data-unit="{{$goods.inventory_unit}}">{{$goods.inventory}}</span><span>{{$goods.inventory_unit}}</span></span>
|
||||
|
@ -248,13 +248,13 @@ class BuyService
|
||||
$v['spec'] = empty($v['spec']) ? null : json_decode($v['spec'], true);
|
||||
|
||||
// 获取商品基础信息
|
||||
$goods_base = GoodsService::GoodsSpecDetail(['id'=>$v['goods_id'], 'spec'=>$v['spec']]);
|
||||
$goods_base = GoodsService::GoodsSpecDetail(['id'=>$v['goods_id'], 'spec'=>$v['spec'], 'stock'=>$v['stock']]);
|
||||
$v['is_invalid'] = 0;
|
||||
if($goods_base['code'] == 0)
|
||||
{
|
||||
$v['inventory'] = $goods_base['data']['spec_base']['inventory'];
|
||||
$v['price'] = (float) $goods_base['data']['spec_base']['price'];
|
||||
$v['original_price'] = (float) $goods_base['data']['spec_base']['original_price'];
|
||||
$v['price'] = $goods_base['data']['spec_base']['price'];
|
||||
$v['original_price'] = $goods_base['data']['spec_base']['original_price'];
|
||||
$v['spec_weight'] = $goods_base['data']['spec_base']['weight'];
|
||||
$v['spec_coding'] = $goods_base['data']['spec_base']['coding'];
|
||||
$v['spec_barcode'] = $goods_base['data']['spec_base']['barcode'];
|
||||
@ -278,7 +278,7 @@ class BuyService
|
||||
$v['goods_url'] = MyUrl('index/goods/index', ['id'=>$v['goods_id']]);
|
||||
$v['images_old'] = $v['images'];
|
||||
$v['images'] = ResourcesService::AttachmentPathViewHandle($v['images']);
|
||||
$v['total_price'] = $v['stock']* ((float) $v['price']);
|
||||
$v['total_price'] = PriceNumberFormat($v['stock']* $v['price']);
|
||||
$v['buy_max_number'] = ($v['buy_max_number'] <= 0) ? $v['inventory']: $v['buy_max_number'];
|
||||
|
||||
// 错误处理
|
||||
@ -432,28 +432,54 @@ class BuyService
|
||||
$stock = intval($params['stock']);
|
||||
|
||||
// 获取购物车数据
|
||||
$cart = Db::name('Cart')->where($where)->select()->toArray();
|
||||
if(empty($cart))
|
||||
$data = Db::name('Cart')->where($where)->field('goods_id,title,price,stock,spec')->find();
|
||||
if(empty($data))
|
||||
{
|
||||
return DataReturn('请先加入购物车', -1);
|
||||
}
|
||||
$cart[0]['stock'] = $stock;
|
||||
$data['stock'] = $stock;
|
||||
$data['spec'] = empty($data['spec']) ? null : json_decode($data['spec'], true);
|
||||
|
||||
// 商品校验
|
||||
$ret = self::BuyGoodsCheck(['goods'=>$cart]);
|
||||
$ret = self::BuyGoodsCheck(['goods'=>[$data]]);
|
||||
if($ret['code'] != 0)
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
$data = [
|
||||
$upd_data = [
|
||||
'stock' => $stock,
|
||||
'upd_time' => time(),
|
||||
];
|
||||
if(Db::name('Cart')->where($where)->update($data))
|
||||
if(Db::name('Cart')->where($where)->update($upd_data))
|
||||
{
|
||||
return DataReturn('更新成功', 0);
|
||||
// 获取商品基础信息、更新商品价格信息
|
||||
$goods_base = GoodsService::GoodsSpecDetail(['id'=>$data['goods_id'], 'spec'=>$data['spec'], 'stock'=>$data['stock']]);
|
||||
if($goods_base['code'] == 0)
|
||||
{
|
||||
$data['price'] = (float) $goods_base['data']['spec_base']['price'];
|
||||
$data['original_price'] = (float) $goods_base['data']['spec_base']['original_price'];
|
||||
}
|
||||
|
||||
// 增加价格总计
|
||||
$data['total_price'] = PriceNumberFormat($data['stock']*$data['price']);
|
||||
|
||||
// 购物车更新成功钩子
|
||||
$hook_name = 'plugins_service_cart_update_success';
|
||||
$ret = EventReturnHandle(MyEventTrigger($hook_name, [
|
||||
'hook_name' => $hook_name,
|
||||
'is_backend' => true,
|
||||
'params' => $params,
|
||||
'data' => &$data,
|
||||
'goods_id' => $params['goods_id']
|
||||
]));
|
||||
if(isset($ret['code']) && $ret['code'] != 0)
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
|
||||
return DataReturn('更新成功', 0, $data);
|
||||
}
|
||||
return DataReturn('更新失败', -100);
|
||||
}
|
||||
@ -519,7 +545,7 @@ class BuyService
|
||||
$goods['spec'] = self::GoodsSpecificationsHandle($params);
|
||||
|
||||
// 获取商品基础信息
|
||||
$goods_base = GoodsService::GoodsSpecDetail(['id'=>$goods['goods_id'], 'spec'=>$goods['spec']]);
|
||||
$goods_base = GoodsService::GoodsSpecDetail(['id'=>$goods['goods_id'], 'spec'=>$goods['spec'], 'stock'=>$params['stock']]);
|
||||
if($goods_base['code'] == 0)
|
||||
{
|
||||
$goods['inventory'] = $goods_base['data']['spec_base']['inventory'];
|
||||
|
@ -2341,6 +2341,46 @@ class GoodsService
|
||||
return DataReturn('没有相关规格类型', -100);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品购买数量获取商品信息
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-10-05
|
||||
* @desc description
|
||||
* @param [array] $params [输入参数]
|
||||
*/
|
||||
public static function GoodsStock($params = [])
|
||||
{
|
||||
// 请求参数
|
||||
$p = [
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'id',
|
||||
'error_msg' => '商品id有误',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'stock',
|
||||
'error_msg' => '购买数量有误',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'min',
|
||||
'key_name' => 'stock',
|
||||
'checked_data' => 1,
|
||||
'error_msg' => '购买数量有误',
|
||||
],
|
||||
];
|
||||
$ret = ParamsChecked($params, $p);
|
||||
if($ret !== true)
|
||||
{
|
||||
return DataReturn($ret, -1);
|
||||
}
|
||||
|
||||
// 获取商品基础信息
|
||||
return self::GoodsSpecDetail($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品分类节点数据
|
||||
* @author Devil
|
||||
|
@ -317,7 +317,7 @@ class SystemBaseService
|
||||
* @desc description
|
||||
* @param [int] $goods_id [商品id]
|
||||
* @param [string] $plugins [插件名称]
|
||||
* @param [int] $is_use [是否使用(0否, 1是)]
|
||||
* @param [int] $is_use [是否使用(0否, 1是)]
|
||||
*/
|
||||
public static function GoodsDiscountRecord($goods_id, $plugins, $is_use = 0)
|
||||
{
|
||||
|
@ -17,8 +17,9 @@ $(function()
|
||||
{
|
||||
if($(this).prop('checked'))
|
||||
{
|
||||
var stock = parseInt($(this).parents('tr').find('.stock-tag input').val());
|
||||
var price = parseFloat($(this).parents('tr').find('.stock-tag').data('price'));
|
||||
var $stock = $(this).parents('tr').find('.stock-tag');
|
||||
var stock = parseInt($stock.find('input').val());
|
||||
var price = parseFloat($stock.attr('data-price'));
|
||||
total_stock += stock;
|
||||
total_price += stock*price;
|
||||
ids.push($(this).val());
|
||||
@ -63,28 +64,28 @@ $(function()
|
||||
|
||||
// ajax请求
|
||||
$.ajax({
|
||||
url: self.parents('.stock-tag').data('ajax-url'),
|
||||
url: $('.cart-content').data('ajax-url'),
|
||||
type: 'post',
|
||||
dataType: "json",
|
||||
timeout: 10000,
|
||||
data: {"id": id, "goods_id": goods_id, "stock": stock},
|
||||
success: function(result)
|
||||
success: function(res)
|
||||
{
|
||||
$.AMUI.progress.done();
|
||||
if(result.code == 0)
|
||||
if(res.code == 0)
|
||||
{
|
||||
self.parents('.stock-tag').find('input').val(stock);
|
||||
self.parents('tr').find('.total-price-content').text(__currency_symbol__+FomatFloat(stock*price, 2));
|
||||
|
||||
Prompt(result.msg, 'success');
|
||||
var $stock = self.parents('.stock-tag');
|
||||
$stock.find('input').val(res.data.stock);
|
||||
$stock.attr('data-price', res.data.price);
|
||||
$stock.find('input').val(res.data.stock);
|
||||
self.parents('tr').find('.total-price-content').text(__currency_symbol__+res.data.total_price);
|
||||
|
||||
// 数量更新
|
||||
self.parents('tr').find('.wap-number').text('x'+stock);
|
||||
Prompt(res.msg, 'success');
|
||||
|
||||
// 计算选择的商品总数和总价
|
||||
CartBaseTotal();
|
||||
} else {
|
||||
Prompt(result.msg);
|
||||
Prompt(res.msg);
|
||||
}
|
||||
},
|
||||
error: function(xhr, type)
|
||||
@ -98,19 +99,56 @@ $(function()
|
||||
// 购物车数量操作
|
||||
$('.stock-tag .stock-submit').on('click', function()
|
||||
{
|
||||
var stock = parseInt($(this).parents('.stock-tag').find('input').val());
|
||||
// 数量参数
|
||||
var $parent = $(this).parents('.stock-tag');
|
||||
var $input = $parent.find('input[type="number"]');
|
||||
var min = parseInt($input.data('min-limit'));
|
||||
var max = parseInt($input.data('max-limit'));
|
||||
var unit = $input.data('unit') || '';
|
||||
var stock = parseInt($input.val());
|
||||
var type = $(this).data('type');
|
||||
var temp_stock = (type == 'add') ? stock+1 : stock-1;
|
||||
if(type == 'add')
|
||||
{
|
||||
var temp_stock = stock+1;
|
||||
if(max > 0 && temp_stock > max)
|
||||
{
|
||||
$input.val(max);
|
||||
Prompt('最大限购数量'+max+unit);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
var temp_stock = stock-1;
|
||||
if(temp_stock < min)
|
||||
{
|
||||
$input.val(min);
|
||||
Prompt('最低起购数量'+min+unit);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
CardNumberUpdate($(this), temp_stock);
|
||||
});
|
||||
|
||||
// 输入事件
|
||||
$('.stock-tag input[type="number"]').on('blur', function()
|
||||
{
|
||||
var stock = $(this).val() || null;
|
||||
if(stock == null)
|
||||
// 数量参数
|
||||
var $input = $(this);
|
||||
var min = parseInt($input.data('min-limit'));
|
||||
var max = parseInt($input.data('max-limit'));
|
||||
var unit = $input.data('unit') || '';
|
||||
var stock = parseInt($input.val());
|
||||
if(isNaN(stock))
|
||||
{
|
||||
stock = 1;
|
||||
stock = min;
|
||||
}
|
||||
if(max > 0 && stock > max)
|
||||
{
|
||||
stock = max;
|
||||
}
|
||||
if(stock < min)
|
||||
{
|
||||
stock = min;
|
||||
}
|
||||
$(this).val(stock);
|
||||
CardNumberUpdate($(this), stock);
|
||||
|
@ -41,13 +41,13 @@ function GoodsCommentsHtml(page)
|
||||
type: 'POST',
|
||||
data: {"goods_id": $('.goods-comment').data('goods-id'), "page": page || 1},
|
||||
dataType: 'json',
|
||||
success: function(result)
|
||||
success: function(res)
|
||||
{
|
||||
$('.goods-page-no-data').addClass('none');
|
||||
if(result.code == 0)
|
||||
if(res.code == 0)
|
||||
{
|
||||
$('.goods-comment-content').html(result.data.data);
|
||||
$('.goods-page-container').html(PageLibrary(result.data.total, result.data.number, page, 2));
|
||||
$('.goods-comment-content').html(res.data.data);
|
||||
$('.goods-page-container').html(PageLibrary(res.data.total, res.data.number, page, 2));
|
||||
}
|
||||
|
||||
// 没有数据
|
||||
@ -65,6 +65,34 @@ function GoodsCommentsHtml(page)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 已选规格
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-10-05
|
||||
* @desc description
|
||||
*/
|
||||
function GoodsSelectedSpec()
|
||||
{
|
||||
// 规格
|
||||
var spec = [];
|
||||
var sku_count = $('.sku-items').length;
|
||||
if(sku_count > 0)
|
||||
{
|
||||
var spec_count = $('.sku-line.selected').length;
|
||||
if(spec_count >= sku_count)
|
||||
{
|
||||
$('.iteminfo_parameter .sku-items').removeClass('sku-not-active');
|
||||
$('.theme-signin-left .sku-items li.selected').each(function(k, v)
|
||||
{
|
||||
spec.push({"type": $(this).data('type-value'), "value": $(this).data('value')})
|
||||
});
|
||||
}
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
||||
/**
|
||||
* 购买/加入购物车校验
|
||||
* @author Devil
|
||||
@ -115,18 +143,17 @@ function BuyCartCheck(e)
|
||||
});
|
||||
Prompt('请选择规格');
|
||||
return false;
|
||||
} else {
|
||||
$('.iteminfo_parameter .sku-items').removeClass('sku-not-active');
|
||||
$('.theme-signin-left .sku-items li.selected').each(function(k, v)
|
||||
{
|
||||
spec.push({"type": $(this).data('type-value'), "value": $(this).data('value')})
|
||||
});
|
||||
}
|
||||
|
||||
// 已选规格
|
||||
spec = GoodsSelectedSpec();
|
||||
}
|
||||
var type =( typeof(e) == 'object') ? e.attr('data-type') : null;
|
||||
return {
|
||||
"id": $('.goods-detail').data('id'),
|
||||
"stock": stock,
|
||||
"spec": spec,
|
||||
"type": e.attr('data-type')
|
||||
"type": type
|
||||
};
|
||||
}
|
||||
|
||||
@ -175,6 +202,50 @@ function BuyCartHandle(e)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品规格详情返回数据处理
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-10-05
|
||||
* @desc description
|
||||
* @param {[object]} data [后端返回数据]
|
||||
*/
|
||||
function GoodsSpecDetailBackHandle(data)
|
||||
{
|
||||
$('.text-info .price-now').text(__currency_symbol__+data.spec_base.price);
|
||||
$('.goods-price').text(data.spec_base.price);
|
||||
$('.number-tag input[type="number"]').attr('max', data.spec_base.inventory);
|
||||
$('.stock-tips .stock').text(data.spec_base.inventory);
|
||||
if(data.spec_base.original_price > 0)
|
||||
{
|
||||
$('.goods-original-price').text(__currency_symbol__+data.spec_base.original_price);
|
||||
$('.goods-original-price').parents('.items').show();
|
||||
} else {
|
||||
$('.goods-original-price').parents('.items').hide();
|
||||
}
|
||||
|
||||
// 已选数量校验、超出规格数量则以规格数量为准
|
||||
var stock = parseInt($('#text_box').val());
|
||||
if(stock > data.spec_base.inventory)
|
||||
{
|
||||
$('#text_box').val(data.spec_base.inventory);
|
||||
}
|
||||
|
||||
// 扩展数据处理
|
||||
var extends_element = data.extends_element || [];
|
||||
if(extends_element.length > 0)
|
||||
{
|
||||
for(var i in extends_element)
|
||||
{
|
||||
if((extends_element[i]['element'] || null) != null && extends_element[i]['content'] !== null)
|
||||
{
|
||||
$(extends_element[i]['element']).html(extends_element[i]['content']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取规格详情
|
||||
* @author Devil
|
||||
@ -200,6 +271,9 @@ function GoodsSpecDetail()
|
||||
spec.push({"type": $(this).data('type-value'), "value": $(this).data('value')})
|
||||
});
|
||||
|
||||
// 已填写数量
|
||||
var stock = parseInt($('#text_box').val()) || 1;
|
||||
|
||||
// 开启进度条
|
||||
$.AMUI.progress.start();
|
||||
|
||||
@ -209,38 +283,19 @@ function GoodsSpecDetail()
|
||||
type: 'post',
|
||||
dataType: "json",
|
||||
timeout: 10000,
|
||||
data: {"id": $('.goods-detail').data('id'), "spec": spec},
|
||||
success: function(result)
|
||||
data: {
|
||||
"id": $('.goods-detail').data('id'),
|
||||
"stock": stock,
|
||||
"spec": spec
|
||||
},
|
||||
success: function(res)
|
||||
{
|
||||
$.AMUI.progress.done();
|
||||
if(result.code == 0)
|
||||
if(res.code == 0)
|
||||
{
|
||||
$('.text-info .price-now').text(__currency_symbol__+result.data.spec_base.price);
|
||||
$('.goods-price').text(result.data.spec_base.price);
|
||||
$('.number-tag input[type="number"]').attr('max', result.data.spec_base.inventory);
|
||||
$('.stock-tips .stock').text(result.data.spec_base.inventory);
|
||||
if(result.data.spec_base.original_price > 0)
|
||||
{
|
||||
$('.goods-original-price').text(__currency_symbol__+result.data.spec_base.original_price);
|
||||
$('.goods-original-price').parents('.items').show();
|
||||
} else {
|
||||
$('.goods-original-price').parents('.items').hide();
|
||||
}
|
||||
|
||||
// 扩展数据处理
|
||||
var extends_element = result.data.extends_element || [];
|
||||
if(extends_element.length > 0)
|
||||
{
|
||||
for(var i in extends_element)
|
||||
{
|
||||
if((extends_element[i]['element'] || null) != null && extends_element[i]['content'] !== null)
|
||||
{
|
||||
$(extends_element[i]['element']).html(extends_element[i]['content']);
|
||||
}
|
||||
}
|
||||
}
|
||||
GoodsSpecDetailBackHandle(res.data);
|
||||
} else {
|
||||
Prompt(result.msg);
|
||||
Prompt(res.msg);
|
||||
}
|
||||
},
|
||||
error: function(xhr, type)
|
||||
@ -286,10 +341,10 @@ function GoodsSpecType()
|
||||
dataType: "json",
|
||||
timeout: 10000,
|
||||
data: {"id": $('.goods-detail').data('id'), "spec": spec},
|
||||
success: function(result)
|
||||
success: function(res)
|
||||
{
|
||||
$.AMUI.progress.done();
|
||||
if(result.code == 0)
|
||||
if(res.code == 0)
|
||||
{
|
||||
var spec_count = spec.length;
|
||||
var index = (spec_count > 0) ? spec_count : 0;
|
||||
@ -299,7 +354,7 @@ function GoodsSpecType()
|
||||
{
|
||||
$(this).removeClass('sku-dont-choose');
|
||||
var value = $(this).data('value').toString();
|
||||
if(result.data.spec_type.indexOf(value) == -1)
|
||||
if(res.data.spec_type.indexOf(value) == -1)
|
||||
{
|
||||
$(this).addClass('sku-items-disabled');
|
||||
} else {
|
||||
@ -309,7 +364,7 @@ function GoodsSpecType()
|
||||
}
|
||||
|
||||
// 扩展数据处理
|
||||
var extends_element = result.data.extends_element || [];
|
||||
var extends_element = res.data.extends_element || [];
|
||||
if(extends_element.length > 0)
|
||||
{
|
||||
for(var i in extends_element)
|
||||
@ -321,7 +376,7 @@ function GoodsSpecType()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Prompt(result.msg);
|
||||
Prompt(res.msg);
|
||||
}
|
||||
},
|
||||
error: function(xhr, type)
|
||||
@ -361,6 +416,64 @@ function GoodsBaseRestore()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数量值改变
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2021-10-05
|
||||
* @desc description
|
||||
*/
|
||||
function GoodsNumberChange()
|
||||
{
|
||||
var stock = parseInt($('#text_box').val()) || 1;
|
||||
var spec = [];
|
||||
var sku_count = $('.sku-items').length;
|
||||
if(sku_count > 0)
|
||||
{
|
||||
// 未完全选择规格则返回
|
||||
var spec_count = $('.sku-line.selected').length;
|
||||
if(spec_count < sku_count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 已选规格
|
||||
spec = GoodsSelectedSpec();
|
||||
}
|
||||
|
||||
// 开启进度条
|
||||
$.AMUI.progress.start();
|
||||
|
||||
// ajax请求
|
||||
$.ajax({
|
||||
url: $('#text_box').data('ajax-url'),
|
||||
type: 'post',
|
||||
dataType: "json",
|
||||
timeout: 10000,
|
||||
data: {
|
||||
"id": $('.goods-detail').data('id'),
|
||||
"stock": stock,
|
||||
"spec": spec
|
||||
},
|
||||
success: function(res)
|
||||
{
|
||||
$.AMUI.progress.done();
|
||||
if(res.code == 0)
|
||||
{
|
||||
GoodsSpecDetailBackHandle(res.data);
|
||||
} else {
|
||||
Prompt(res.msg);
|
||||
}
|
||||
},
|
||||
error: function(xhr, type)
|
||||
{
|
||||
$.AMUI.progress.done();
|
||||
Prompt(HtmlToString(xhr.responseText) || '异常错误', null, 30);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 规格选择显示
|
||||
* @author Devil
|
||||
@ -386,13 +499,9 @@ $(function() {
|
||||
{
|
||||
$(this).find('ul>li').on('click', function()
|
||||
{
|
||||
// 切换规格购买数量清空
|
||||
$('#text_box').val($('.stock-tips .stock').data('min-limit') || 1);
|
||||
|
||||
// 规格处理
|
||||
var length = $('.theme-signin-left .sku-container .sku-items').length;
|
||||
var index = $(this).parents('.sku-items').index();
|
||||
|
||||
if($(this).hasClass('selected'))
|
||||
{
|
||||
$(this).removeClass('selected');
|
||||
@ -527,24 +636,24 @@ $(function() {
|
||||
dataType: "json",
|
||||
timeout: 10000,
|
||||
data: {"id": $('.goods-detail').data('id')},
|
||||
success: function(result)
|
||||
success: function(res)
|
||||
{
|
||||
$.AMUI.progress.done();
|
||||
PoptitClose();
|
||||
|
||||
if(result.code == 0)
|
||||
if(res.code == 0)
|
||||
{
|
||||
$this.find('.goods-favor-text').text(result.data.text);
|
||||
$this.find('.goods-favor-count').text('('+result.data.count+')');
|
||||
if(result.data.status == 1)
|
||||
$this.find('.goods-favor-text').text(res.data.text);
|
||||
$this.find('.goods-favor-count').text('('+res.data.count+')');
|
||||
if(res.data.status == 1)
|
||||
{
|
||||
$this.addClass('text-active');
|
||||
} else {
|
||||
$this.removeClass('text-active');
|
||||
}
|
||||
Prompt(result.msg, 'success');
|
||||
Prompt(res.msg, 'success');
|
||||
} else {
|
||||
Prompt(result.msg);
|
||||
Prompt(res.msg);
|
||||
}
|
||||
},
|
||||
error: function(xhr, type)
|
||||
@ -572,54 +681,75 @@ $(function() {
|
||||
});
|
||||
|
||||
//获得文本框对象
|
||||
var $sotck = $('#text_box');
|
||||
var min = $('.stock-tips .stock').data('min-limit') || 1;
|
||||
var max = $('.stock-tips .stock').data('max-limit') || 0;
|
||||
var unit = $('.stock-tips .stock').data('unit') || '';
|
||||
var $input = $('#text_box');
|
||||
var $stock_tips = $('.stock-tips .stock');
|
||||
var min = parseInt($stock_tips.data('min-limit')) || 1;
|
||||
var max = parseInt($stock_tips.data('max-limit')) || 0;
|
||||
var unit = $stock_tips.data('unit') || '';
|
||||
|
||||
// 手动输入
|
||||
$sotck.on('blur', function()
|
||||
$input.on('blur', function()
|
||||
{
|
||||
var number = parseInt($(this).val());
|
||||
var inventory = parseInt($('.stock-tips .stock').text());
|
||||
if(number > inventory)
|
||||
var stock = parseInt($(this).val());
|
||||
var inventory = parseInt($stock_tips.text());
|
||||
if(isNaN(stock))
|
||||
{
|
||||
number = inventory;
|
||||
stock = min;
|
||||
}
|
||||
if(number <= 1 || isNaN(number))
|
||||
if(max > 0 && stock > max)
|
||||
{
|
||||
number = min;
|
||||
stock = max;
|
||||
}
|
||||
$sotck.val(number);
|
||||
if(stock < min)
|
||||
{
|
||||
stock = min;
|
||||
}
|
||||
if(stock > inventory)
|
||||
{
|
||||
stock = inventory;
|
||||
}
|
||||
$input.val(stock);
|
||||
|
||||
// 数量更新事件
|
||||
GoodsNumberChange();
|
||||
});
|
||||
|
||||
//数量增加操作
|
||||
$('#add').on('click', function()
|
||||
{
|
||||
var inventory = parseInt($('.stock-tips .stock').text());
|
||||
var number = parseInt($sotck.val())+1;
|
||||
if(max > 0 && number > max)
|
||||
var inventory = parseInt($stock_tips.text());
|
||||
var stock = parseInt($input.val())+1;
|
||||
if(max > 0 && stock > max)
|
||||
{
|
||||
$input.val(max);
|
||||
Prompt('最大限购数量'+max+unit);
|
||||
return false;
|
||||
}
|
||||
if(number > inventory)
|
||||
if(stock > inventory)
|
||||
{
|
||||
$input.val(min);
|
||||
Prompt('库存数量'+inventory+unit);
|
||||
return false;
|
||||
}
|
||||
$sotck.val(number);
|
||||
$input.val(stock);
|
||||
|
||||
// 数量更新事件
|
||||
GoodsNumberChange();
|
||||
});
|
||||
//数量减少操作
|
||||
$('#min').on('click', function()
|
||||
{
|
||||
var value = parseInt($sotck.val())-1 || 1;
|
||||
var value = parseInt($input.val())-1;
|
||||
if(value < min)
|
||||
{
|
||||
$input.val(min);
|
||||
Prompt('最低起购数量'+min+unit);
|
||||
return false;
|
||||
}
|
||||
$sotck.val(value);
|
||||
$input.val(value);
|
||||
|
||||
// 数量更新事件
|
||||
GoodsNumberChange();
|
||||
});
|
||||
|
||||
// 评论
|
||||
|
Loading…
Reference in New Issue
Block a user