|
@@ -48,10 +48,19 @@ class Cart extends Controller
|
|
$cartTotal = (new CartModel)->getCartTotal();
|
|
$cartTotal = (new CartModel)->getCartTotal();
|
|
$user = $this->getCurrentLoginUser();
|
|
$user = $this->getCurrentLoginUser();
|
|
$cartMoney = '0.00';
|
|
$cartMoney = '0.00';
|
|
- foreach ($list as $item) {
|
|
|
|
|
|
+ foreach ($list as &$item) {
|
|
$temp = bcmul(strval($item['goods_num']), $item['goods']['goods_price_min'], 2);
|
|
$temp = bcmul(strval($item['goods_num']), $item['goods']['goods_price_min'], 2);
|
|
$cartMoney = bcadd($cartMoney, $temp, 2);
|
|
$cartMoney = bcadd($cartMoney, $temp, 2);
|
|
|
|
+ $goodsNum = $item['goods_num'];
|
|
|
|
+ $flavors = json_decode($item['remark_for_one'], true);
|
|
|
|
+ $flavorsAll = $flavors;
|
|
|
|
+ array_walk($flavorsAll, function (&$item, $key) use ($goodsNum) {
|
|
|
|
+ $item = bcmul(strval($item), strval($goodsNum), 0);
|
|
|
|
+ });
|
|
|
|
+ $item['flavors_arr'] = $flavorsAll;
|
|
}
|
|
}
|
|
|
|
+// pre($list->toArray());
|
|
|
|
+// die;
|
|
|
|
|
|
$payPoints = intval(bcmul($cartMoney, '100', 0));//订单所需积分
|
|
$payPoints = intval(bcmul($cartMoney, '100', 0));//订单所需积分
|
|
$payByPoints = false;
|
|
$payByPoints = false;
|
|
@@ -140,7 +149,10 @@ class Cart extends Controller
|
|
*/
|
|
*/
|
|
public function add(int $goodsId, string $goodsSkuId, int $goodsNum): Json
|
|
public function add(int $goodsId, string $goodsSkuId, int $goodsNum): Json
|
|
{
|
|
{
|
|
|
|
+ //pre($this->request->param());
|
|
$key = $this->request->param('key', '');
|
|
$key = $this->request->param('key', '');
|
|
|
|
+ //每一包的口味配比
|
|
|
|
+ $flavors = $this->request->param('flavors', []);
|
|
$userId = Session::get('user_id');
|
|
$userId = Session::get('user_id');
|
|
if (empty($userId)) {
|
|
if (empty($userId)) {
|
|
Session::set('returnuri', '/index/index/productDetails.html?goodsId=' . $goodsId . '&key=' . $key, 300);
|
|
Session::set('returnuri', '/index/index/productDetails.html?goodsId=' . $goodsId . '&key=' . $key, 300);
|
|
@@ -151,7 +163,7 @@ class Cart extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
$model = new CartModel;
|
|
$model = new CartModel;
|
|
- if (!$model->add($goodsId, $goodsSkuId, $goodsNum)) {
|
|
|
|
|
|
+ if (!$model->add($goodsId, $goodsSkuId, $goodsNum, $flavors)) {
|
|
return $this->renderError($model->getError() ?: 'Added to shopping cart failed');
|
|
return $this->renderError($model->getError() ?: 'Added to shopping cart failed');
|
|
}
|
|
}
|
|
// 购物车商品总数量
|
|
// 购物车商品总数量
|