|
|
@@ -217,6 +217,7 @@ class GoodsService extends BaseService
|
|
|
{
|
|
|
$skuId = isset($params['sku_id'])? $params['sku_id'] : 0;
|
|
|
$status = isset($params['status'])? $params['status'] : 0;
|
|
|
+ $merchId = isset($params['merch_id'])? $params['merch_id'] : 0;
|
|
|
$num = isset($params['num'])? $params['num'] : 1;
|
|
|
if($skuId<=0 || $goodsId<=0 || $userId<=0 || $num<=0){
|
|
|
$this->error = 2014;
|
|
|
@@ -230,16 +231,14 @@ class GoodsService extends BaseService
|
|
|
|
|
|
$cartId = CartsModel::where(['user_id'=> $userId,'goods_id'=> $goodsId,'sku_id'=>$skuId])->value('id');
|
|
|
if($cartId){
|
|
|
- CartsModel::where(['id'=> $cartId])->update(['num'=> $num,'status'=> $status,'mark'=>1,'update_time'=>time()]);
|
|
|
+ CartsModel::where(['id'=> $cartId])->update(['num'=> $num,'merch_id'=>$merchId,'status'=> $status,'mark'=>1,'update_time'=>time()]);
|
|
|
RedisService::clear("caches:members:cartList:{$userId}");
|
|
|
- RedisService::clear("caches:members:cartCount:{$userId}");
|
|
|
- $count = $this->getCartCount($userId);
|
|
|
+ $count = $this->getCartCount($userId,true);
|
|
|
return ['id'=> $cartId,'count'=> $count];
|
|
|
}else{
|
|
|
- $cartId = CartsModel::insertGetId(['user_id'=> $userId,'goods_id'=>$goodsId,'sku_id'=>$skuId,'num'=> $num,'status'=> $status,'mark'=>1,'create_time'=>time()]);
|
|
|
+ $cartId = CartsModel::insertGetId(['user_id'=> $userId,'goods_id'=>$goodsId,'merch_id'=>$merchId,'sku_id'=>$skuId,'num'=> $num,'status'=> $status,'mark'=>1,'create_time'=>time()]);
|
|
|
RedisService::clear("caches:members:cartList:{$userId}");
|
|
|
- RedisService::clear("caches:members:cartCount:{$userId}");
|
|
|
- $count = $this->getCartCount($userId);
|
|
|
+ $count = $this->getCartCount($userId, true);
|
|
|
return ['id'=> $cartId,'count'=>$count];
|
|
|
}
|
|
|
}
|
|
|
@@ -307,11 +306,11 @@ class GoodsService extends BaseService
|
|
|
* @param $userId
|
|
|
* @return array|mixed
|
|
|
*/
|
|
|
- public function getCartCount($userId)
|
|
|
+ public function getCartCount($userId, $refresh = false)
|
|
|
{
|
|
|
$cacheKey = "caches:member:cartCount:{$userId}";
|
|
|
$data = RedisService::get($cacheKey);
|
|
|
- if($data>0){
|
|
|
+ if($data>0 && !$refresh){
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
@@ -327,7 +326,6 @@ class GoodsService extends BaseService
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public function getFreight($userId, $addressId,$skuList)
|
|
|
{
|
|
|
$cacheKey = "caches:goods:freight:{$userId}_{$addressId}_".md5(json_encode($skuList,256));
|