作者 何书鹏
1 个管道 的构建 通过 耗费 2 秒

购物车选中

@@ -217,19 +217,21 @@ class Cart extends Api @@ -217,19 +217,21 @@ class Cart extends Api
217 */ 217 */
218 public function select($cart_ids) 218 public function select($cart_ids)
219 { 219 {
220 - $list = $this->model  
221 - ->where('user_id',$this->user['id']) 220 + $where = [
  221 + 'user_id' => $this->user['id'],
  222 + 'isbuynow' => '0'
  223 + ];
  224 + // 传过来的选中
  225 + $this->model
  226 + ->where($where)
222 ->where('id','in',$cart_ids) 227 ->where('id','in',$cart_ids)
223 - ->select();  
224 - $total_num = 0;  
225 - $total_price = 0;  
226 - foreach ($list as $key => $cart) {  
227 - // 商品总数  
228 - $total_num += $cart['goods_num'];  
229 - // 商品总价  
230 - $total_price += bcmul($cart['goods_price'], $cart['goods_num'], 2);  
231 - }  
232 - $this->success(__('成功'),compact('total_num','total_price')); 228 + ->update(['isselected'=>'1']);
  229 + // 未传过来的取消选中
  230 + $this->model
  231 + ->where($where)
  232 + ->where('id','notin',$cart_ids)
  233 + ->update(['isselected'=>'0']);
  234 + $this->success(__('成功'));
233 } 235 }
234 236
235 /** 237 /**
@@ -194,12 +194,16 @@ class Cart extends Model @@ -194,12 +194,16 @@ class Cart extends Model
194 if ($goods['ismake'] == '0' && $cart['goods_num'] > $cart['goods_sku']['stock_num']) { 194 if ($goods['ismake'] == '0' && $cart['goods_num'] > $cart['goods_sku']['stock_num']) {
195 $this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足'); 195 $this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足');
196 } 196 }
  197 + $cart['goods_total_price'] = bcmul($cart['goods_price'], $cart['goods_num'], 2);
  198 + // 只计算选中商品
  199 + if($cart['isselected'] == '1'){
197 // 商品总数 200 // 商品总数
198 $total_num += $cart['goods_num']; 201 $total_num += $cart['goods_num'];
199 // 商品总价 202 // 商品总价
200 - $total_price += $cart['goods_total_price'] = bcmul($cart['goods_price'], $cart['goods_num'], 2); 203 + $total_price += $cart['goods_total_price'];
201 // 商品总重量 204 // 商品总重量
202 $total_goods_weight += bcmul($cart['goods_sku']['goods_weight'], $cart['goods_num'], 2); 205 $total_goods_weight += bcmul($cart['goods_sku']['goods_weight'], $cart['goods_num'], 2);
  206 + }
203 // 显示商品信息 207 // 显示商品信息
204 $cart->goods->visible(['goods_name','goods_image','category_ids','spec_type']); 208 $cart->goods->visible(['goods_name','goods_image','category_ids','spec_type']);
205 // 显示用户尺寸信息 209 // 显示用户尺寸信息
@@ -218,7 +222,8 @@ class Cart extends Model @@ -218,7 +222,8 @@ class Cart extends Model
218 'goods_num', 222 'goods_num',
219 'make_type', 223 'make_type',
220 'goods', 224 'goods',
221 - 'user_size' 225 + 'user_size',
  226 + 'isselected'
222 ])->append([ 227 ])->append([
223 'goods_total_price', 228 'goods_total_price',
224 'goods_sku' 229 'goods_sku'
@@ -236,7 +241,7 @@ class Cart extends Model @@ -236,7 +241,7 @@ class Cart extends Model
236 krsort($express); 241 krsort($express);
237 $express_price = 0; 242 $express_price = 0;
238 foreach($express as $k => $v){ 243 foreach($express as $k => $v){
239 - if($total_goods_weight >= $k){ 244 + if($total_goods_weight > $k){
240 $express_price = $v; 245 $express_price = $v;
241 break; 246 break;
242 } 247 }
@@ -305,8 +310,10 @@ class Cart extends Model @@ -305,8 +310,10 @@ class Cart extends Model
305 public function orderCouponList($user,$cart_list){ 310 public function orderCouponList($user,$cart_list){
306 $new_cart_list = []; 311 $new_cart_list = [];
307 foreach ($cart_list as $key => $value) { 312 foreach ($cart_list as $key => $value) {
  313 + if($value['isselected'] == '1'){
308 $new_cart_list[$value['goods_id']][] = $value; 314 $new_cart_list[$value['goods_id']][] = $value;
309 } 315 }
  316 + }
310 $coupon_id_arr = []; 317 $coupon_id_arr = [];
311 $tree = Tree::instance()->init(collection(Category::order('weigh desc,id desc')->select())->toArray(), 'pid'); 318 $tree = Tree::instance()->init(collection(Category::order('weigh desc,id desc')->select())->toArray(), 'pid');
312 foreach($new_cart_list as $goods_id => $v){ 319 foreach($new_cart_list as $goods_id => $v){