|
|
@ -2,17 +2,103 @@ |
|
|
|
|
|
|
|
|
namespace App\Service; |
|
|
namespace App\Service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Hyperf\Di\Annotation\Inject; |
|
|
|
|
|
use Hyperf\DbConnection\Db; |
|
|
|
|
|
use App\Model\Goods; |
|
|
|
|
|
use App\Model\Combination; |
|
|
|
|
|
use App\Model\ShopCar; |
|
|
|
|
|
|
|
|
class PurchaseLimitService implements PurchaseLimitServiceInterface |
|
|
class PurchaseLimitService implements PurchaseLimitServiceInterface |
|
|
{ |
|
|
{ |
|
|
public function addShopCar($params) |
|
|
public function addShopCar($params) |
|
|
{ |
|
|
{ |
|
|
if($params['good_id'] == 1561){ |
|
|
|
|
|
|
|
|
//获取主表商品表信息
|
|
|
|
|
|
$goods = Goods::where([ |
|
|
|
|
|
['id','=',$params['good_id']], |
|
|
|
|
|
]) |
|
|
|
|
|
->select('is_max','restrict_num','box_money','inventory','money') |
|
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
//获取购物车该商品购买数量
|
|
|
|
|
|
$num = ShopCar::where([ |
|
|
|
|
|
['user_id', $params['user_id']], |
|
|
|
|
|
['good_id', $params['good_id']], |
|
|
|
|
|
]) |
|
|
|
|
|
->sum('num'); |
|
|
|
|
|
//限购检验
|
|
|
|
|
|
if($goods->restrict_num > 0 && $goods->restrict_num <= $num){ |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
//获取规格表商品信息
|
|
|
|
|
|
if($params['combination_id'] > 0) { |
|
|
|
|
|
$combination = Combination::where([ |
|
|
|
|
|
['id', '=', $params['combination_id']], |
|
|
|
|
|
]) |
|
|
|
|
|
->select('wm_money', 'number') |
|
|
|
|
|
->first(); |
|
|
|
|
|
$inventory = $combination->number; |
|
|
|
|
|
$money = $combination->wm_money; |
|
|
}else{ |
|
|
}else{ |
|
|
return '加入购物车成功'; |
|
|
|
|
|
|
|
|
$inventory = $goods->inventory; |
|
|
|
|
|
$money = $goods->money; |
|
|
|
|
|
} |
|
|
|
|
|
//库存校验
|
|
|
|
|
|
if($goods->is_max == 2 && ($num + $params['num']) > $inventory) |
|
|
|
|
|
{ |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
//更新购物车
|
|
|
|
|
|
$exists = ShopCar::where([ |
|
|
|
|
|
['user_id', '=', $params['user_id']], |
|
|
|
|
|
['good_id', '=', $params['good_id']], |
|
|
|
|
|
['market_id','=',$params['market_id']], |
|
|
|
|
|
['combination_id','=', $params['combination_id']], |
|
|
|
|
|
]); |
|
|
|
|
|
if($params['combination_id'] > 0) { |
|
|
|
|
|
$exists->where('combination_id',$params['combination_id']); |
|
|
|
|
|
} |
|
|
|
|
|
$test = $exists->exists(); |
|
|
|
|
|
if($test) |
|
|
|
|
|
{ |
|
|
|
|
|
$update = ShopCar::where([ |
|
|
|
|
|
['user_id', '=', $params['user_id']], |
|
|
|
|
|
['good_id', '=', $params['good_id']], |
|
|
|
|
|
['market_id','=',$params['market_id']], |
|
|
|
|
|
]); |
|
|
|
|
|
if($params['combination_id'] > 0) { |
|
|
|
|
|
$update->where('combination_id',$params['combination_id']); |
|
|
|
|
|
} |
|
|
|
|
|
$update->increment('num', $params['num']); |
|
|
|
|
|
}else{ |
|
|
|
|
|
$son_id = empty($params['son_id']) ? 0 : $params['son_id']; |
|
|
|
|
|
$dr_id = empty($params['dr_id']) ? 0 : $params['dr_id']; |
|
|
|
|
|
$combination_id = empty($params['combination_id']) ? 0 : $params['combination_id']; |
|
|
|
|
|
$qg_name = empty($params['qg_name']) ? ' ' : $params['qg_name']; |
|
|
|
|
|
$qg_logo = empty($params['qg_logo']) ? ' ' :$params['qg_logo']; |
|
|
|
|
|
ShopCar::insert( |
|
|
|
|
|
[ |
|
|
|
|
|
'market_id' => $params['market_id'], |
|
|
|
|
|
'good_id' => $params['good_id'], |
|
|
|
|
|
'store_id' => $params['store_id'], |
|
|
|
|
|
'user_id' => $params['user_id'], |
|
|
|
|
|
'combination_id' => $combination_id, |
|
|
|
|
|
'num' => $params['num'], |
|
|
|
|
|
'spec' => $params['spec'], |
|
|
|
|
|
'son_id' => $son_id, |
|
|
|
|
|
'dr_id' => $dr_id, |
|
|
|
|
|
'qg_name' => $qg_name, |
|
|
|
|
|
'qg_logo' => $qg_logo, |
|
|
|
|
|
'money' => $money, |
|
|
|
|
|
'box_money' => $goods->box_money, |
|
|
|
|
|
] |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
return $test; |
|
|
|
|
|
// if($params['goods_id'] == 1561){
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
// }else{
|
|
|
|
|
|
// return '加入购物车成功';
|
|
|
|
|
|
// }
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function updateShopCar($params) |
|
|
public function updateShopCar($params) |
|
|
@ -23,4 +109,9 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface |
|
|
return '更新购物车成功'; |
|
|
return '更新购物车成功'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function test($params) |
|
|
|
|
|
{ |
|
|
|
|
|
return $params; |
|
|
|
|
|
} |
|
|
} |
|
|
} |