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

修改加入购物车

@@ -85,7 +85,7 @@ @@ -85,7 +85,7 @@
85 <div class="form-group"> 85 <div class="form-group">
86 <label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label> 86 <label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label>
87 <div class="col-xs-12 col-sm-8"> 87 <div class="col-xs-12 col-sm-8">
88 - <input id="c-stock" data-rule="required range(0~)" class="form-control" name="row[stock]" type="number" value="0"> 88 + <input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="text" placeholder="请输入商品库存(多个以'|'隔开)">
89 </div> 89 </div>
90 </div> 90 </div>
91 <div class="form-group"> 91 <div class="form-group">
@@ -85,7 +85,7 @@ @@ -85,7 +85,7 @@
85 <div class="form-group"> 85 <div class="form-group">
86 <label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label> 86 <label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label>
87 <div class="col-xs-12 col-sm-8"> 87 <div class="col-xs-12 col-sm-8">
88 - <input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="number" value="{$row.stock|htmlentities}"> 88 + <input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="text" value="{$row.stock|htmlentities}" placeholder="请输入商品库存(多个以'|'隔开)">
89 </div> 89 </div>
90 </div> 90 </div>
91 <div class="form-group"> 91 <div class="form-group">
@@ -85,7 +85,7 @@ @@ -85,7 +85,7 @@
85 <div class="form-group"> 85 <div class="form-group">
86 <label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label> 86 <label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label>
87 <div class="col-xs-12 col-sm-8"> 87 <div class="col-xs-12 col-sm-8">
88 - <input id="c-stock" data-rule="required range(0~)" class="form-control" name="row[stock]" type="number" value="0"> 88 + <input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="text" placeholder="请输入商品库存(多个以'|'隔开)">
89 </div> 89 </div>
90 </div> 90 </div>
91 <div class="form-group"> 91 <div class="form-group">
@@ -85,7 +85,7 @@ @@ -85,7 +85,7 @@
85 <div class="form-group"> 85 <div class="form-group">
86 <label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label> 86 <label class="control-label col-xs-12 col-sm-2">{:__('Stock')}:</label>
87 <div class="col-xs-12 col-sm-8"> 87 <div class="col-xs-12 col-sm-8">
88 - <input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="number" value="{$row.stock|htmlentities}"> 88 + <input id="c-stock" data-rule="required" class="form-control" name="row[stock]" type="text" value="{$row.stock|htmlentities}" placeholder="请输入商品库存(多个以'|'隔开)">
89 </div> 89 </div>
90 </div> 90 </div>
91 <div class="form-group"> 91 <div class="form-group">
@@ -49,11 +49,18 @@ class Cars extends Api @@ -49,11 +49,18 @@ class Cars extends Api
49 } 49 }
50 50
51 //检测库存 51 //检测库存
52 - $stock = Common::findSoftWhereData('goods',['id'=>$data['goods_id']],'id,stock');  
53 - if($stock){  
54 - if(($stock['stock'] <=> $data['goods_number']) == -1){ 52 + $stock_res = Common::findSoftWhereData('goods',['id'=>$data['goods_id']],'id,stock,style g_style');
  53 + if($stock_res){
  54 + //查看规格所属索引
  55 + $s_index = array_search($data['style'],Common::salePrice($stock_res['g_style']));
  56 + if($s_index){
  57 + $stock = Common::salePrice($stock_res['stock'])[$s_index];
  58 + if(($stock <=> $data['goods_number']) == -1){
55 $this->error('库存不足'); 59 $this->error('库存不足');
56 } 60 }
  61 + }else{
  62 + $this->error('出错了');
  63 + }
57 } 64 }
58 //查询有无记录 65 //查询有无记录
59 $where = [ 66 $where = [
@@ -129,12 +136,14 @@ class Cars extends Api @@ -129,12 +136,14 @@ class Cars extends Api
129 $total_price += $value['price'] * $value['goods_number']; 136 $total_price += $value['price'] * $value['goods_number'];
130 //查看规格所属索引 137 //查看规格所属索引
131 $s_index = array_search($value['style'],Common::salePrice($value['g_style'])); 138 $s_index = array_search($value['style'],Common::salePrice($value['g_style']));
132 - $value['stock'] = Common::salePrice($value['stock'][$s_index]); 139 + if($s_index){
  140 + $value['stock'] = Common::salePrice($value['stock'])[$s_index];
133 if(($value['stock'] <=> $value['goods_number']) == -1){ 141 if(($value['stock'] <=> $value['goods_number']) == -1){
134 //购物车数量大于库存 142 //购物车数量大于库存
135 $value['goods_number'] = $value['stock']; 143 $value['goods_number'] = $value['stock'];
136 } 144 }
137 } 145 }
  146 + }
138 // $total_price = array_sum(array_map(function ($product_row) { 147 // $total_price = array_sum(array_map(function ($product_row) {
139 // return $product_row['price'] * $product_row['goods_number']; 148 // return $product_row['price'] * $product_row['goods_number'];
140 // }, $res)); 149 // }, $res));