修复错误
This commit is contained in:
parent
c7de7e6339
commit
c3d2ed3244
@ -110,9 +110,9 @@ class StoreCartRepository extends BaseRepository
|
||||
* @param $uid
|
||||
* @author Qinii
|
||||
*/
|
||||
public function getCartByProductSku($sku,$uid)
|
||||
public function getCartByProductSku($sku,$uid,$product_type=0)
|
||||
{
|
||||
$where = ['is_del'=>0,'is_fail'=>0,'is_new'=>0,'is_pay'=>0,'is_dg' => 0,'uid' => $uid,'product_type' => 0,'product_attr_unique' => $sku];
|
||||
$where = ['is_del'=>0,'is_fail'=>0,'is_new'=>0,'is_pay'=>0,'is_dg' => 0,'uid' => $uid,'product_type' => $product_type,'product_attr_unique' => $sku];
|
||||
return ($this->dao->getWhere($where));
|
||||
}
|
||||
|
||||
|
@ -1791,13 +1791,13 @@ class ProductRepository extends BaseRepository
|
||||
} else {
|
||||
//加入购物车
|
||||
//购物车现有
|
||||
$_num = $this->productOnceCountCart($where['product_id'],$data['product_attr_unique'], $userInfo->uid);
|
||||
$_num = $this->productOnceCountCart($where['product_id'],$data['product_attr_unique'], $userInfo->uid,$data['product_type']);
|
||||
$cart_num = $_num + $data['cart_num'];
|
||||
}
|
||||
if ($sku['stock'] < $cart_num ) throw new ValidateException('库存不足');
|
||||
//添加购物车
|
||||
if (!$data['is_new']) {
|
||||
$cart = app()->make(StoreCartRepository::class)->getCartByProductSku($data['product_attr_unique'], $userInfo->uid);
|
||||
$cart = app()->make(StoreCartRepository::class)->getCartByProductSku($data['product_attr_unique'], $userInfo->uid,$data['product_type']);
|
||||
}
|
||||
return compact('product', 'sku', 'cart');
|
||||
}
|
||||
@ -1810,7 +1810,7 @@ class ProductRepository extends BaseRepository
|
||||
* @author Qinii
|
||||
* @day 5/26/21
|
||||
*/
|
||||
public function productOnceCountCart($productId,$product_attr_unique,$uid)
|
||||
public function productOnceCountCart($productId,$product_attr_unique,$uid,$product_type=0)
|
||||
{
|
||||
$make = app()->make(StoreCartRepository::class);
|
||||
$where = [
|
||||
@ -1819,7 +1819,7 @@ class ProductRepository extends BaseRepository
|
||||
'is_new' => 0,
|
||||
'is_fail' => 0,
|
||||
'is_dg' => 0,
|
||||
'product_type' => 0,
|
||||
'product_type' => $product_type,
|
||||
'product_id' => $productId,
|
||||
'uid' => $uid,
|
||||
'product_attr_unique' => $product_attr_unique,
|
||||
|
@ -67,15 +67,15 @@ class StoreCart extends BaseController
|
||||
public function create(validate $validate)
|
||||
{
|
||||
$data = $this->checkParams($validate);
|
||||
if(!in_array($data['product_type'],[0,1,2,3,4])) return app('json')->fail('商品类型错误');
|
||||
if(!in_array($data['product_type'],[0,1,2,3,4,98])) return app('json')->fail('商品类型错误');
|
||||
if ($data['cart_num'] <= 0) return app('json')->fail('购买数量有误');
|
||||
$user = $this->request->userInfo();
|
||||
event('user.cart.before',compact('user','data'));
|
||||
switch ($data['product_type'])
|
||||
{
|
||||
case 0: //普通商品
|
||||
case 98: //普通商品
|
||||
$result = app()->make(ProductRepository::class)->cartCheck($data,$this->request->userInfo());
|
||||
|
||||
[$source, $sourceId, $pid] = explode(':', $this->request->param('source', '0'), 3) + ['', '', ''];
|
||||
$data['source'] = (in_array($source, [0, 1]) && $pid == $data['product_id']) ? $source : 0;
|
||||
if ($data['source'] > 0) $data['source_id'] = intval($sourceId);
|
||||
@ -105,7 +105,6 @@ class StoreCart extends BaseController
|
||||
}
|
||||
|
||||
unset($data['group_buying_id']);
|
||||
|
||||
if ($cart = $result['cart']) {
|
||||
//更新购物车
|
||||
$cart_id = $cart['cart_id'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user