作者 jinglong
1 个管道 的构建 通过 耗费 1 秒

修改加入购物车

... ... @@ -85,7 +85,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-stock" data-rule="required range(0~)" class="form-control" name="row[stock]" type="number" value="0">
<input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="text" placeholder="请输入商品库存(多个以'|'隔开)">
</div>
</div>
<div class="form-group">
... ...
... ... @@ -85,7 +85,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="number" value="{$row.stock|htmlentities}">
<input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="text" value="{$row.stock|htmlentities}" placeholder="请输入商品库存(多个以'|'隔开)">
</div>
</div>
<div class="form-group">
... ...
... ... @@ -85,7 +85,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-stock" data-rule="required range(0~)" class="form-control" name="row[stock]" type="number" value="0">
<input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="text" placeholder="请输入商品库存(多个以'|'隔开)">
</div>
</div>
<div class="form-group">
... ...
... ... @@ -85,7 +85,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="number" value="{$row.stock|htmlentities}">
<input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="text" value="{$row.stock|htmlentities}" placeholder="请输入商品库存(多个以'|'隔开)">
</div>
</div>
<div class="form-group">
... ...
... ... @@ -49,10 +49,17 @@ class Cars extends Api
}
//检测库存
$stock = Common::findSoftWhereData('goods',['id'=>$data['goods_id']],'id,stock');
if($stock){
if(($stock['stock'] <=> $data['goods_number']) == -1){
$this->error('库存不足');
$stock_res = Common::findSoftWhereData('goods',['id'=>$data['goods_id']],'id,stock,style g_style');
if($stock_res){
//查看规格所属索引
$s_index = array_search($data['style'],Common::salePrice($stock_res['g_style']));
if($s_index){
$stock = Common::salePrice($stock_res['stock'])[$s_index];
if(($stock <=> $data['goods_number']) == -1){
$this->error('库存不足');
}
}else{
$this->error('出错了');
}
}
//查询有无记录
... ... @@ -129,10 +136,12 @@ class Cars extends Api
$total_price += $value['price'] * $value['goods_number'];
//查看规格所属索引
$s_index = array_search($value['style'],Common::salePrice($value['g_style']));
$value['stock'] = Common::salePrice($value['stock'][$s_index]);
if(($value['stock'] <=> $value['goods_number']) == -1){
//购物车数量大于库存
$value['goods_number'] = $value['stock'];
if($s_index){
$value['stock'] = Common::salePrice($value['stock'])[$s_index];
if(($value['stock'] <=> $value['goods_number']) == -1){
//购物车数量大于库存
$value['goods_number'] = $value['stock'];
}
}
}
// $total_price = array_sum(array_map(function ($product_row) {
... ...