|
@@ -49,7 +49,7 @@ class ShoppingCartServer
|
|
|
function getShoppingList($m_id,$shop_id)
|
|
function getShoppingList($m_id,$shop_id)
|
|
|
{
|
|
{
|
|
|
//获取购物车商品数据
|
|
//获取购物车商品数据
|
|
|
- $where = [['p.m_id',$m_id], ['p.shop_id',$shop_id], ['p.type',1], ['g.is_del',0], ['g.status',1]];
|
|
|
|
|
|
|
+ $where = [['p.m_id',$m_id], ['p.shop_id',$shop_id], ['g.is_del',0], ['g.status',1]];
|
|
|
$shopping = Shopping::from('shopping as p')
|
|
$shopping = Shopping::from('shopping as p')
|
|
|
->leftJoin('goods as g','g.id','=','p.goods_id')
|
|
->leftJoin('goods as g','g.id','=','p.goods_id')
|
|
|
->where($where)
|
|
->where($where)
|
|
@@ -78,15 +78,16 @@ class ShoppingCartServer
|
|
|
->where('d.shopping_id',$value->{'shopping_id'})
|
|
->where('d.shopping_id',$value->{'shopping_id'})
|
|
|
->where('d.goods_id',$value->{'goods_id'})
|
|
->where('d.goods_id',$value->{'goods_id'})
|
|
|
->where('s.is_del',0)
|
|
->where('s.is_del',0)
|
|
|
- ->select(['d.*','s.spec_name','s.spec_price'])
|
|
|
|
|
|
|
+ ->select(['d.id','d.goods_id','d.goods_spec_id','d.number','s.spec_name','s.spec_price'])
|
|
|
->get();
|
|
->get();
|
|
|
- $spec_total_price = 0;//规则总价置为0
|
|
|
|
|
foreach ($details as $detail){
|
|
foreach ($details as $detail){
|
|
|
-
|
|
|
|
|
- $goods_attr .= $detail['spec_name'] . ',';
|
|
|
|
|
- $spec_total_price = bcmul($detail['number'],$detail['spec_price'],2);//规格数量乘以价格等于 规格总价
|
|
|
|
|
|
|
+ if ($detail->{'number'} > 1){
|
|
|
|
|
+ $goods_attr .= $detail['spec_name'].'x'.$detail->{'number'} . ',';
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $goods_attr .= $detail['spec_name'] . ',';
|
|
|
|
|
+ }
|
|
|
|
|
+ $goods_spec_price = bcadd($goods_spec_price,bcmul($detail['number'],$detail['spec_price'],2),2);//规格数量乘以价格等于 规格总价
|
|
|
}
|
|
}
|
|
|
- $goods_spec_price = bcmul($goods_spec_price,$spec_total_price,2);
|
|
|
|
|
$goods_spec_list = $details;
|
|
$goods_spec_list = $details;
|
|
|
}
|
|
}
|
|
|
//计算价格
|
|
//计算价格
|
|
@@ -150,14 +151,10 @@ class ShoppingCartServer
|
|
|
->where('id',$goods_id)
|
|
->where('id',$goods_id)
|
|
|
->where('shop_id',$shop_id)
|
|
->where('shop_id',$shop_id)
|
|
|
->where('category_id',$category_id)
|
|
->where('category_id',$category_id)
|
|
|
- ->select(['id as goods_id','is_infinite','stock','status','spec_type'])
|
|
|
|
|
|
|
+ ->select(['id as goods_id','status','spec_type'])
|
|
|
->first();
|
|
->first();
|
|
|
if (empty($goods)) return ['code' => 0, 'msg' => '当前商品不存在'];
|
|
if (empty($goods)) return ['code' => 0, 'msg' => '当前商品不存在'];
|
|
|
if ($goods->{'status'} != 1) return ['code' => 0, 'msg' => '当前商品已下架'];
|
|
if ($goods->{'status'} != 1) return ['code' => 0, 'msg' => '当前商品已下架'];
|
|
|
- //如果商品是多规格但是没选规格
|
|
|
|
|
- if ($goods->{'spec_type'} == 2 && empty($goods_spec_id)){
|
|
|
|
|
- return ['code' => 0, 'msg' => '请选择商品规格'];
|
|
|
|
|
- }
|
|
|
|
|
//如果是单规格但是选择了规格
|
|
//如果是单规格但是选择了规格
|
|
|
if ($goods->{'spec_type'} == 1 && !empty($goods_spec_id)){
|
|
if ($goods->{'spec_type'} == 1 && !empty($goods_spec_id)){
|
|
|
return ['code' => 0, 'msg' => '该商品没有规格'];
|
|
return ['code' => 0, 'msg' => '该商品没有规格'];
|
|
@@ -180,6 +177,10 @@ class ShoppingCartServer
|
|
|
$shopping_info = Shopping::where($where)->select(['id', 'goods_id', 'number'])->first();
|
|
$shopping_info = Shopping::where($where)->select(['id', 'goods_id', 'number'])->first();
|
|
|
|
|
|
|
|
if (empty($shopping_info)) {//没用购物车信息
|
|
if (empty($shopping_info)) {//没用购物车信息
|
|
|
|
|
+ //如果商品是多规格但是没选规格
|
|
|
|
|
+ if ($goods->{'spec_type'} == 2 && empty($goods_spec_id)){
|
|
|
|
|
+ return ['code' => 0, 'msg' => '请选择商品规格'];
|
|
|
|
|
+ }
|
|
|
if ($number <= 0){
|
|
if ($number <= 0){
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
|
return ['code' => 0, 'msg' => '请选择数量'];
|
|
return ['code' => 0, 'msg' => '请选择数量'];
|
|
@@ -212,11 +213,28 @@ class ShoppingCartServer
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
}else{//有购物车信息,更新
|
|
}else{//有购物车信息,更新
|
|
|
|
|
+ $shopping_id = $shopping_info->{'id'};
|
|
|
|
|
+
|
|
|
if (!empty($goods_spec_id)){//选择了规则就是更新购物车详情表
|
|
if (!empty($goods_spec_id)){//选择了规则就是更新购物车详情表
|
|
|
if ($number <= 0){//数量为0直接删除
|
|
if ($number <= 0){//数量为0直接删除
|
|
|
ShoppingDetail::where('shopping_id',$shopping_info->{'id'})->where('goods_id',$goods_id)->where('goods_spec_id',$goods_spec_id)->delete();//删除详情表
|
|
ShoppingDetail::where('shopping_id',$shopping_info->{'id'})->where('goods_id',$goods_id)->where('goods_spec_id',$goods_spec_id)->delete();//删除详情表
|
|
|
}else{
|
|
}else{
|
|
|
- if ($skuInfo->{'sku_type'} == 2 && $skuInfo->{'affect_quantity'} == 1){//可多选规格并且能多添加购物车数量
|
|
|
|
|
|
|
+ //检查该规格信息是否讯息
|
|
|
|
|
+ $details = ShoppingDetail::where('shopping_id',$shopping_info->{'id'})->where('goods_id',$goods_id)->where('goods_spec_id',$goods_spec_id)->select(['id'])->first();
|
|
|
|
|
+
|
|
|
|
|
+ if ($skuInfo->{'sku_type'} == 1){//商品只能单选
|
|
|
|
|
+ $number = 1;//单选购物数量只能为1
|
|
|
|
|
+ }elseif ($skuInfo->{'sku_type'} == 2 && $skuInfo->{'affect_quantity'} == 0){//可多选规格但是不能多添加购物车数量
|
|
|
|
|
+ $number = 1;//数量只能为1
|
|
|
|
|
+ }
|
|
|
|
|
+ if (empty($details)){
|
|
|
|
|
+ ShoppingDetail::create([
|
|
|
|
|
+ 'shopping_id' => $shopping_id,
|
|
|
|
|
+ 'goods_id' => $goods_id,
|
|
|
|
|
+ 'goods_spec_id' => $goods_spec_id,
|
|
|
|
|
+ 'number' => $number,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }elseif ($skuInfo->{'sku_type'} == 2 && $skuInfo->{'affect_quantity'} == 1){//可多选规格并且能多添加购物车数量
|
|
|
ShoppingDetail::where('shopping_id',$shopping_info->{'id'})->where('goods_id',$goods_id)->where('goods_spec_id',$goods_spec_id)->update(['number' => $number]);//跟新购物车
|
|
ShoppingDetail::where('shopping_id',$shopping_info->{'id'})->where('goods_id',$goods_id)->where('goods_spec_id',$goods_spec_id)->update(['number' => $number]);//跟新购物车
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -255,10 +273,11 @@ class ShoppingCartServer
|
|
|
try {
|
|
try {
|
|
|
$where = [['m_id',$m_id], ['shop_id',$shop_id]];
|
|
$where = [['m_id',$m_id], ['shop_id',$shop_id]];
|
|
|
|
|
|
|
|
- $shopping_info = Shopping::where($where)->select(['id', 'goods_id', 'number'])->first();
|
|
|
|
|
-
|
|
|
|
|
- Shopping::where('id',$shopping_info->{'id'})->delete();//删除主表
|
|
|
|
|
- ShoppingDetail::where('shopping_id',$shopping_info->{'id'})->delete();//删除详情表
|
|
|
|
|
|
|
+ $shopping_info = Shopping::where($where)->select(['id', 'goods_id', 'number'])->get();
|
|
|
|
|
+ foreach ($shopping_info as $v){
|
|
|
|
|
+ Shopping::where('id',$v->{'id'})->delete();//删除主表
|
|
|
|
|
+ ShoppingDetail::where('shopping_id',$v->{'id'})->delete();//删除详情表
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
return ['code' => 1, 'msg' => '删除成功'];
|
|
return ['code' => 1, 'msg' => '删除成功'];
|