Browse Source

购物车

master
Lemon 5 years ago
parent
commit
40b68b9517
  1. 2
      app/Constants/v3/ErrorCode.php
  2. 13
      app/Service/v3/Implementations/ShopCartService.php
  3. 498
      composer.lock

2
app/Constants/v3/ErrorCode.php

@ -252,7 +252,7 @@ class ErrorCode extends AbstractConstants
/** /**
* 已下架 * 已下架
* @Message("商品可能已下架")
* @Message("商品不存在")
*/ */
const GOODS_NOT_EXISTS = 1104; const GOODS_NOT_EXISTS = 1104;

13
app/Service/v3/Implementations/ShopCartService.php

@ -2,6 +2,8 @@
namespace App\Service\v3\Implementations; namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException;
use App\Model\v3\Goods; use App\Model\v3\Goods;
use App\Model\v3\GoodsActivity; use App\Model\v3\GoodsActivity;
use App\Model\v3\ShoppingCart; use App\Model\v3\ShoppingCart;
@ -166,8 +168,13 @@ class ShopCartService implements ShopCartServiceInterface
$cartList = []; $cartList = [];
$totalAmount = 0; $totalAmount = 0;
foreach ($carts as $key => &$cart) { foreach ($carts as $key => &$cart) {
if (empty($cart->store)) {
throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE);
continue;
}
if (empty($cart->store)||empty($cart->goods)) {
if (empty($cart->goods)) {
throw new ErrorCodeException(ErrorCode::GOODS_INVALID);
continue; continue;
} }
@ -191,7 +198,6 @@ class ShopCartService implements ShopCartServiceInterface
} }
if ($res === true) { if ($res === true) {
$cartList['store_lists'][$store['id']]['store'] = $store; $cartList['store_lists'][$store['id']]['store'] = $store;
$cartList['store_lists'][$store['id']]['shopping_cart'][] = $shoppingCart; $cartList['store_lists'][$store['id']]['shopping_cart'][] = $shoppingCart;
@ -205,6 +211,8 @@ class ShopCartService implements ShopCartServiceInterface
} }
$totalAmount = bcadd($totalAmount, bcmul($cart->goods->price, $cart->num)); $totalAmount = bcadd($totalAmount, bcmul($cart->goods->price, $cart->num));
}else{
throw new ErrorCodeException(ErrorCode::GOODS_INVALID);
} }
} }
@ -215,7 +223,6 @@ class ShopCartService implements ShopCartServiceInterface
} }
$cartList['total'] = bcadd($totalAmount, '0', 2); $cartList['total'] = bcadd($totalAmount, '0', 2);
return $cartList['store_lists']; return $cartList['store_lists'];
} }

498
composer.lock

@ -522,20 +522,6 @@
"uppercase", "uppercase",
"words" "words"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Finflector",
"type": "tidelift"
}
],
"time": "2020-05-29T07:19:59+00:00" "time": "2020-05-29T07:19:59+00:00"
}, },
{ {
@ -598,20 +584,6 @@
"constructor", "constructor",
"instantiate" "instantiate"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator",
"type": "tidelift"
}
],
"time": "2020-05-29T17:27:14+00:00" "time": "2020-05-29T17:27:14+00:00"
}, },
{ {
@ -680,20 +652,6 @@
"parser", "parser",
"php" "php"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer",
"type": "tidelift"
}
],
"time": "2020-05-25T17:44:05+00:00" "time": "2020-05-25T17:44:05+00:00"
}, },
{ {
@ -3872,12 +3830,6 @@
"laminas", "laminas",
"zf" "zf"
], ],
"funding": [
{
"url": "https://funding.communitybridge.org/projects/laminas-project",
"type": "community_bridge"
}
],
"time": "2020-05-20T16:45:56+00:00" "time": "2020-05-20T16:45:56+00:00"
}, },
{ {
@ -4135,16 +4087,6 @@
"logging", "logging",
"psr-3" "psr-3"
], ],
"funding": [
{
"url": "https://github.com/Seldaek",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/monolog/monolog",
"type": "tidelift"
}
],
"time": "2020-05-22T08:12:19+00:00" "time": "2020-05-22T08:12:19+00:00"
}, },
{ {
@ -4293,16 +4235,6 @@
"datetime", "datetime",
"time" "time"
], ],
"funding": [
{
"url": "https://opencollective.com/Carbon",
"type": "open_collective"
},
{
"url": "https://tidelift.com/funding/github/packagist/nesbot/carbon",
"type": "tidelift"
}
],
"time": "2020-07-04T12:29:56+00:00" "time": "2020-07-04T12:29:56+00:00"
}, },
{ {
@ -4969,16 +4901,6 @@
"php", "php",
"type" "type"
], ],
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption",
"type": "tidelift"
}
],
"time": "2020-06-07T10:40:07+00:00" "time": "2020-06-07T10:40:07+00:00"
}, },
{ {
@ -6017,20 +5939,6 @@
], ],
"description": "Symfony Console Component", "description": "Symfony Console Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-06-15T12:59:21+00:00" "time": "2020-06-15T12:59:21+00:00"
}, },
{ {
@ -6087,20 +5995,6 @@
], ],
"description": "A generic function and convention to trigger deprecation notices", "description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-06-06T08:49:21+00:00" "time": "2020-06-06T08:49:21+00:00"
}, },
{ {
@ -6179,20 +6073,6 @@
], ],
"description": "Symfony EventDispatcher Component", "description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-05-20T17:43:50+00:00" "time": "2020-05-20T17:43:50+00:00"
}, },
{ {
@ -6261,20 +6141,6 @@
"interoperability", "interoperability",
"standards" "standards"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-06T13:23:11+00:00" "time": "2020-07-06T13:23:11+00:00"
}, },
{ {
@ -6330,20 +6196,6 @@
], ],
"description": "Symfony Finder Component", "description": "Symfony Finder Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-05-20T17:43:50+00:00" "time": "2020-05-20T17:43:50+00:00"
}, },
{ {
@ -6493,20 +6345,6 @@
"polyfill", "polyfill",
"portable" "portable"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-07-14T12:35:20+00:00"
}, },
{ {
@ -6577,20 +6415,6 @@
"portable", "portable",
"shim" "shim"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-07-14T12:35:20+00:00"
}, },
{ {
@ -6668,20 +6492,6 @@
"portable", "portable",
"shim" "shim"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-07-14T12:35:20+00:00"
}, },
{ {
@ -6755,20 +6565,6 @@
"portable", "portable",
"shim" "shim"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-07-14T12:35:20+00:00"
}, },
{ {
@ -6838,20 +6634,6 @@
"portable", "portable",
"shim" "shim"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-07-14T12:35:20+00:00"
}, },
{ {
@ -6921,20 +6703,6 @@
"portable", "portable",
"shim" "shim"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-07-14T12:35:20+00:00"
}, },
{ {
@ -7000,20 +6768,6 @@
"portable", "portable",
"shim" "shim"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-07-14T12:35:20+00:00"
}, },
{ {
@ -7082,20 +6836,6 @@
"portable", "portable",
"shim" "shim"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-07-14T12:35:20+00:00"
}, },
{ {
@ -7168,20 +6908,6 @@
"portable", "portable",
"shim" "shim"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-07-14T12:35:20+00:00"
}, },
{ {
@ -7622,20 +7348,6 @@
"interoperability", "interoperability",
"standards" "standards"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-06T13:23:11+00:00" "time": "2020-07-06T13:23:11+00:00"
}, },
{ {
@ -7713,20 +7425,6 @@
"utf-8", "utf-8",
"utf8" "utf8"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-06-11T12:16:36+00:00" "time": "2020-06-11T12:16:36+00:00"
}, },
{ {
@ -7811,20 +7509,6 @@
], ],
"description": "Symfony Translation Component", "description": "Symfony Translation Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-05-30T20:35:19+00:00" "time": "2020-05-30T20:35:19+00:00"
}, },
{ {
@ -7892,20 +7576,6 @@
"interoperability", "interoperability",
"standards" "standards"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-07-06T13:23:11+00:00" "time": "2020-07-06T13:23:11+00:00"
}, },
{ {
@ -8057,16 +7727,6 @@
"env", "env",
"environment" "environment"
], ],
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv",
"type": "tidelift"
}
],
"time": "2020-07-14T19:22:52+00:00" "time": "2020-07-14T19:22:52+00:00"
}, },
{ {
@ -8293,20 +7953,6 @@
"Xdebug", "Xdebug",
"performance" "performance"
], ],
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://github.com/composer",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
"type": "tidelift"
}
],
"time": "2020-06-04T11:16:35+00:00" "time": "2020-06-04T11:16:35+00:00"
}, },
{ {
@ -8395,20 +8041,6 @@
"redis", "redis",
"xcache" "xcache"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcache",
"type": "tidelift"
}
],
"time": "2020-07-07T18:54:01+00:00" "time": "2020-07-07T18:54:01+00:00"
}, },
{ {
@ -8480,20 +8112,6 @@
"iterators", "iterators",
"php" "php"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcollections",
"type": "tidelift"
}
],
"time": "2020-06-22T19:14:02+00:00" "time": "2020-06-22T19:14:02+00:00"
}, },
{ {
@ -8583,20 +8201,6 @@
"doctrine", "doctrine",
"php" "php"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcommon",
"type": "tidelift"
}
],
"time": "2020-06-05T16:46:05+00:00" "time": "2020-06-05T16:46:05+00:00"
}, },
{ {
@ -8768,20 +8372,6 @@
"orm", "orm",
"persistence" "persistence"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fpersistence",
"type": "tidelift"
}
],
"time": "2020-03-21T15:13:52+00:00" "time": "2020-03-21T15:13:52+00:00"
}, },
{ {
@ -8963,12 +8553,6 @@
} }
], ],
"description": "A tool to automatically fix PHP code style", "description": "A tool to automatically fix PHP code style",
"funding": [
{
"url": "https://github.com/keradus",
"type": "github"
}
],
"time": "2020-06-27T23:57:46+00:00" "time": "2020-06-27T23:57:46+00:00"
}, },
{ {
@ -9207,12 +8791,6 @@
"object", "object",
"object graph" "object graph"
], ],
"funding": [
{
"url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy",
"type": "tidelift"
}
],
"time": "2020-06-29T13:22:24+00:00" "time": "2020-06-29T13:22:24+00:00"
}, },
{ {
@ -9501,20 +9079,6 @@
"MIT" "MIT"
], ],
"description": "PHPStan - PHP Static Analysis Tool", "description": "PHPStan - PHP Static Analysis Tool",
"funding": [
{
"url": "https://github.com/ondrejmirtes",
"type": "github"
},
{
"url": "https://www.patreon.com/phpstan",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
"type": "tidelift"
}
],
"time": "2020-07-01T11:57:52+00:00" "time": "2020-07-01T11:57:52+00:00"
}, },
{ {
@ -10616,20 +10180,6 @@
], ],
"description": "Symfony Filesystem Component", "description": "Symfony Filesystem Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-05-30T20:35:19+00:00" "time": "2020-05-30T20:35:19+00:00"
}, },
{ {
@ -10692,20 +10242,6 @@
"configuration", "configuration",
"options" "options"
], ],
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-05-23T13:08:13+00:00" "time": "2020-05-23T13:08:13+00:00"
}, },
{ {
@ -10762,20 +10298,6 @@
], ],
"description": "Symfony Process Component", "description": "Symfony Process Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-05-30T20:35:19+00:00" "time": "2020-05-30T20:35:19+00:00"
}, },
{ {
@ -10832,20 +10354,6 @@
], ],
"description": "Symfony Stopwatch Component", "description": "Symfony Stopwatch Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2020-05-20T17:43:50+00:00" "time": "2020-05-20T17:43:50+00:00"
}, },
{ {
@ -10892,12 +10400,6 @@
} }
], ],
"description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "description": "A small library for converting tokenized PHP source code into XML and potentially other formats",
"funding": [
{
"url": "https://github.com/theseer",
"type": "github"
}
],
"time": "2020-07-12T23:59:07+00:00" "time": "2020-07-12T23:59:07+00:00"
} }
], ],

Loading…
Cancel
Save