|
@@ -31,21 +31,23 @@ class StoreCart extends Model
|
|
|
/**
|
|
/**
|
|
|
* 添加购物车
|
|
* 添加购物车
|
|
|
* @param array $data
|
|
* @param array $data
|
|
|
- * @return bool
|
|
|
|
|
|
|
+ * @return int|false 成功返回购物车ID,失败返回false
|
|
|
*/
|
|
*/
|
|
|
public function addToCart($data)
|
|
public function addToCart($data)
|
|
|
{
|
|
{
|
|
|
// 检查是否已存在
|
|
// 检查是否已存在
|
|
|
$exist = $this->where('uid', $data['uid'])
|
|
$exist = $this->where('uid', $data['uid'])
|
|
|
->where('product_id', $data['product_id'])
|
|
->where('product_id', $data['product_id'])
|
|
|
- ->where('cart_num', $data['cart_num'])
|
|
|
|
|
|
|
+ ->where('product_attr_unique', $data['product_attr_unique'] ?? '')
|
|
|
->find();
|
|
->find();
|
|
|
if ($exist) {
|
|
if ($exist) {
|
|
|
// 更新数量
|
|
// 更新数量
|
|
|
- return $this->where('id', $exist['id'])->inc('cart_num', $data['cart_num'])->update();
|
|
|
|
|
|
|
+ $result = $this->where('id', $exist['id'])->inc('cart_num', $data['cart_num'])->update();
|
|
|
|
|
+ return $result ? $exist['id'] : false;
|
|
|
} else {
|
|
} else {
|
|
|
// 新增
|
|
// 新增
|
|
|
- return $this->insert($data);
|
|
|
|
|
|
|
+ $result = $this->insert($data);
|
|
|
|
|
+ return $result ? $this->getLastInsID() : false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|