From f0d1625680597fb0ccb20e34fccd749d52966535 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 17 Sep 2020 21:54:04 +0800 Subject: [PATCH 01/38] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=B8=82=E5=9C=BA?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/LocationService.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php index ad32232..df22dc0 100644 --- a/app/Service/v3/Implementations/LocationService.php +++ b/app/Service/v3/Implementations/LocationService.php @@ -74,14 +74,27 @@ class LocationService implements LocationServiceInterface ['city_id','=',$cityId] ]) ->get(); - foreach ($res as &$v){ + foreach ($res as &$m){ if(!empty($lng) && !empty($lat)){ - $v->distance = ($this->getDistance($v->lng,$v->lat,$lng,$lat)).' km'; + $m->distance_num = $this->getDistance($m->lng, $m->lat, $lng, $lat); + $m->distance = $m->distance_num.' km'; }else{ - $v->distance = ''; + $m->distance_num = 0; + $m->distance = ''; } } - return $res; + + $res = collect($res->toArray())->sortBy(function ($area, $key) { + return $area['distance_num']; + }); + + $res = collect($res->all())->map(function ($area, $key) { + $markets = collect($area['markets'])->sortBy('distance_num'); + $area['markets'] = $markets->values()->all(); + return $area; + }); + + return $res->all(); } public function getNearestMarket($lng,$lat) From 164b2790b78fcb70bba41fb08465d48d8141bc58 Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 17 Sep 2020 22:01:10 +0800 Subject: [PATCH 02/38] =?UTF-8?q?=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/GoodsActivityService.php | 4 ++-- app/Service/v3/Implementations/GoodsService.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index 97ce98c..c60a231 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -49,8 +49,8 @@ class GoodsActivityService implements GoodsActivityServiceInterface // 商品库存不足 // 获取冻结的库存 - //$inventoryFrozen = (int)$redis->get($inventoryKey); - $inventoryFrozen = 0; + $inventoryFrozen = (int)$redis->get($inventoryKey); + // $inventoryFrozen = 0; if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR; } diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 996248f..a00ca11 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -40,8 +40,8 @@ class GoodsService implements GoodsServiceInterface } // 商品库存不足 // 获取冻结的库存 - //$inventoryFrozen = (int)$redis->get($inventoryKey); - $inventoryFrozen = 0; + $inventoryFrozen = (int)$redis->get($inventoryKey); + // $inventoryFrozen = 0; if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ return ErrorCode::GOODS_INVENTORY_ERROR; } From 5d52e41dfc4e58786962da3c7975cb4d4bff9784 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 17 Sep 2020 22:07:45 +0800 Subject: [PATCH 03/38] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/Feprint.php | 13 +++++++++++++ app/Service/v3/Implementations/FeiePrintService.php | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 app/Model/v3/Feprint.php diff --git a/app/Model/v3/Feprint.php b/app/Model/v3/Feprint.php new file mode 100644 index 0000000..4a8bf22 --- /dev/null +++ b/app/Model/v3/Feprint.php @@ -0,0 +1,13 @@ + &$item) { // $item = (array)$item; // } - + $printSn = Feprint::query()->where('market_id',$data->market_id)->value('sn'); $content = $this->printFormat($data, 4, 14, 7, 7); - $res = $this->printMsg('920527381', $content, 1); + $res = $this->printMsg($printSn, $content, 1); return $res; } From ad209efd781decaf6242ca70b814c2b8f934c76d Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 09:39:54 +0800 Subject: [PATCH 04/38] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E8=B7=9D=E7=A6=BB=20?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/UserAddressService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index eef1807..cc2b283 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -89,7 +89,7 @@ class UserAddressService implements UserAddressServiceInterface throw new ErrorCodeException(ErrorCode::LOCATION_USER_ADDRESS); } - $distance = $this->locationService->getDistanceByTencent($address['address']->lng,$address['address']->lat,$market->lng,$market->lat); + $distance = $this->locationService->getDistanceByTencent($market->lng,$market->lat,$address['address']->lng,$address['address']->lat); $distributionPrice = $this->distributionPriceService->do($distance); $res['address'] = $address; $res['delivery_distance'] = $distance; From ebb81513761746f5da8eb5e10715f2afde60ba55 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 10:04:25 +0800 Subject: [PATCH 05/38] =?UTF-8?q?=E5=BA=93=E5=AD=98=E3=80=81=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/OrderOnlineController.php | 5 +- app/Crontab/AutoCancelOrder.php | 25 + .../Implementations/GoodsActivityService.php | 12 +- .../v3/Implementations/GoodsService.php | 11 +- .../v3/Implementations/LocationService.php | 4 +- .../v3/Implementations/OrderListService.php | 20 +- .../v3/Implementations/OrderOnlineService.php | 65 +- .../OrderOnlineServiceInterface.php | 6 + composer.json | 3 +- composer.lock | 559 +++++++++++++++++- config/autoload/crontab.php | 5 + config/autoload/dependencies.php | 1 + config/autoload/processes.php | 1 + 13 files changed, 677 insertions(+), 40 deletions(-) create mode 100644 app/Crontab/AutoCancelOrder.php create mode 100644 config/autoload/crontab.php diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 9da4214..99a0045 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -129,7 +129,10 @@ class OrderOnlineController extends BaseController $res['store_list'] = $this->shopCartService->getGoodsByShopcartId($shopcartIds); //获取用户优惠券 $coupons = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId); - $res['coupon'] = []; + $res['coupon'] = [ + 'available' => [], + 'not_available' => [], + ]; foreach ($coupons as $key => &$item) { foreach ($item as $k => &$rec) { for ($i=0; $i<$rec->number_remain; $i++) { diff --git a/app/Crontab/AutoCancelOrder.php b/app/Crontab/AutoCancelOrder.php new file mode 100644 index 0000000..dda86f7 --- /dev/null +++ b/app/Crontab/AutoCancelOrder.php @@ -0,0 +1,25 @@ +orderOnlineService->autoCancel(); + } + +} \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index c60a231..b838e88 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -49,20 +49,12 @@ class GoodsActivityService implements GoodsActivityServiceInterface // 商品库存不足 // 获取冻结的库存 - $inventoryFrozen = (int)$redis->get($inventoryKey); - // $inventoryFrozen = 0; + // $inventoryFrozen = (int)$redis->get($inventoryKey); + $inventoryFrozen = 0; if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR; } - // 压redis库存 - // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 - if (!$redis->exists($inventoryKey)) { - $redis->set($inventoryKey, $num); - } else { - $redis->incrBy($inventoryKey, intval($num)); - } - // 是否超过限购数量 if ($goods->restrict_num != 0 && $goods->restrict_num < $num) { return ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT; diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index a00ca11..9dc9776 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -40,18 +40,11 @@ class GoodsService implements GoodsServiceInterface } // 商品库存不足 // 获取冻结的库存 - $inventoryFrozen = (int)$redis->get($inventoryKey); - // $inventoryFrozen = 0; + // $inventoryFrozen = (int)$redis->get($inventoryKey); + $inventoryFrozen = 0; if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ return ErrorCode::GOODS_INVENTORY_ERROR; } - // 压redis库存 - // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 - if (!$redis->exists($inventoryKey)) { - $redis->set($inventoryKey, $num); - } else { - $redis->incrBy($inventoryKey, intval($num)); - } // 是否超过限购数量 if ($goods->restrict_num != 0 && $goods->restrict_num < $num) { diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php index df22dc0..cb5265d 100644 --- a/app/Service/v3/Implementations/LocationService.php +++ b/app/Service/v3/Implementations/LocationService.php @@ -30,7 +30,7 @@ class LocationService implements LocationServiceInterface public function getMarketListByLocation($lng,$lat) { - $cityIds = Market::query()->pluck('city_id'); + $cityIds = Market::query()->where(['status' => 1])->pluck('city_id'); $res = Area::query()->with('markets')->whereIn('id',$cityIds)->get(); foreach ($res as &$v){ @@ -99,7 +99,7 @@ class LocationService implements LocationServiceInterface public function getNearestMarket($lng,$lat) { - $markets = Market::query()->get()->toArray(); + $markets = Market::query()->where(['status' => 1])->get()->toArray(); $result = []; $distinctMin = 0; foreach ($markets as &$market){ diff --git a/app/Service/v3/Implementations/OrderListService.php b/app/Service/v3/Implementations/OrderListService.php index d6988ca..9c99119 100644 --- a/app/Service/v3/Implementations/OrderListService.php +++ b/app/Service/v3/Implementations/OrderListService.php @@ -8,6 +8,7 @@ use App\Model\v3\OrderMain; use App\Model\v3\Order; use App\Service\v3\Interfaces\BadgeServiceInterface; use App\Service\v3\Interfaces\OrderListServiceInterface; +use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use Hyperf\Di\Annotation\Inject; use Hyperf\Utils\ApplicationContext; @@ -20,6 +21,12 @@ class OrderListService implements OrderListServiceInterface */ protected $badgeService; + /** + * @Inject + * @var OrderOnlineServiceInterface + */ + protected $orderOnlineService; + public function do() { // TODO: Implement do() method. @@ -61,11 +68,6 @@ class OrderListService implements OrderListServiceInterface // 清除badge $this->badgeService->clearUserOrder($userId, $tab); - co(function () use ($userId) { - // 自动取消超时订单 - $this->autoCancel($userId); - }); - $paginate = $builder->orderBy('created_at', 'desc')->paginate($pagesize); $orders = $paginate->toArray(); return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data'], 'note' => '待付款订单15分钟后将自动取消,请尽快支付!']; @@ -193,12 +195,4 @@ class OrderListService implements OrderListServiceInterface $orders = $paginate->toArray(); return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']]; } - - public function autoCancel($userId) - { - return OrderMain::query() - ->where(['user_id' => $userId, 'state' => OrderState::UNPAID]) - ->where('created_at', '<', time()-900) - ->update(['state' => OrderState::CANCELED]); - } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index babe919..01362b8 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -203,6 +203,15 @@ class OrderOnlineService implements OrderOnlineServiceInterface } + // 压redis库存 + // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 + $inventoryKey = 'goods_inventory_sold_'.$cart->activity_type.'_'.$cart->goods_id; // 拼接activity_type和goods_id + if (!$redis->exists($inventoryKey)) { + $redis->set($inventoryKey, $cart->num); + } else { + $redis->incrBy($inventoryKey, intval($cart->num)); + } + // 算金额 $goodsAmount = bcmul((string)$goods->price, (string)$cart->num); # 当前商品的金额 $subAmount = bcadd((string)$subAmount, (string)$goodsAmount); # 当前店铺子订单的金额 @@ -358,7 +367,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface if (!$redis->exists($inventoryKey)) { $redis->set($inventoryKey, 0); } else { - $redis->decrBy($inventoryKey, $cart->num); + $redis->decrBy($inventoryKey, intval($cart->num)); } } $this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => $e->getMessage()]); @@ -425,7 +434,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface if (!$redis->exists($inventoryKey)) { $redis->set($inventoryKey, 0); } else { - $redis->decrBy($inventoryKey, $goodsItem['number']); + $redis->decrBy($inventoryKey, intval($goodsItem['number'])); } } @@ -520,7 +529,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface if (!$redis->exists($inventoryKey)) { $redis->set($inventoryKey, 0); } else { - $redis->decrBy($inventoryKey, $goodsItem['number']); + $redis->decrBy($inventoryKey, intval($goodsItem['number'])); } } @@ -635,4 +644,54 @@ class OrderOnlineService implements OrderOnlineServiceInterface return $this->paymentService->undo($orderMain->global_order_id, $userId); } } + + public function autoCancel() + { + $orderMains = OrderMain::query() + ->select(['global_order_id', 'user_id']) + ->where(['state' => OrderState::UNPAID]) + ->where('created_at', '<', time()-900) + ->get(); + + foreach ($orderMains as $key => &$orderMain) { + + // 订单待支付 + $orderMain->state = OrderState::CANCELED; + if (!$orderMain->save()) { + throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE); + } + + // 退还优惠券 + $this->couponService->orderRefundCoupons($orderMain->global_order_id); + + // 撤销活动商品购买记录 + $orders = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->get()->toArray(); + $orderGoods = OrderGoods::query() + ->whereIn('order_id', array_values(array_column($orders, 'id'))) + ->get() + ->toArray(); + foreach ($orderGoods as $key => &$goods) { + if ($goods['activity_type'] == 2) { + $this->goodsActivityService->clearCacheRecord($goods['goods_id'], $goods['number'], $orderMain->user_id); + } + } + + // 释redis库存 + $redis = ApplicationContext::getContainer()->get(Redis::class); + foreach ($orderGoods as $k => &$goodsItem) { + // 拼接activity_type和goods_id + $inventoryKey = 'goods_inventory_sold_'.$goodsItem['activity_type'].'_'.$goodsItem['goods_id']; + // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 + if (!$redis->exists($inventoryKey)) { + $redis->set($inventoryKey, 0); + } else { + $redis->decrBy($inventoryKey, intval($goodsItem['number'])); + } + } + + // 记录badge + $orderChildIds = array_values(array_column($orders, 'store_id')); + $this->badgeService->doByOrder($orderMain->user_id, $orderChildIds, $orderMain->global_order_id, OrderState::CANCELED); + } + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php b/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php index d396b1a..5c53302 100644 --- a/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php +++ b/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php @@ -70,4 +70,10 @@ interface OrderOnlineServiceInterface * @return mixed */ public function doRefund($globalOrderId, $userId); + + /** + * 自动取消订单 + * @return mixed + */ + public function autoCancel(); } \ No newline at end of file diff --git a/composer.json b/composer.json index 54781ed..647241f 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,8 @@ "hyperf/rpc-client": "^2.0", "hyperf/consul": "^2.0", "alibabacloud/client": "^1.5", - "hashids/hashids": "^4.0" + "hashids/hashids": "^4.0", + "hyperf/crontab": "^2.0" }, "require-dev": { "swoole/ide-helper": "^4.5", diff --git a/composer.lock b/composer.lock index 06537cf..87fd21c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9f238a6a5e556f4061e56600f28bacfd", + "content-hash": "7ab1eb814ce8a0d34cfec6c2c0725022", "packages": [ { "name": "adbario/php-dot-notation", @@ -522,6 +522,20 @@ "uppercase", "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" }, { @@ -584,6 +598,20 @@ "constructor", "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" }, { @@ -652,6 +680,20 @@ "parser", "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" }, { @@ -1551,6 +1593,65 @@ ], "time": "2020-06-24T23:15:36+00:00" }, + { + "name": "hyperf/crontab", + "version": "v2.0.9", + "source": { + "type": "git", + "url": "https://github.com/hyperf/crontab.git", + "reference": "3167a34acdb53d19a12bce4a29139c6e51ed62a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hyperf/crontab/zipball/3167a34acdb53d19a12bce4a29139c6e51ed62a4", + "reference": "3167a34acdb53d19a12bce4a29139c6e51ed62a4", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "hyperf/utils": "~2.0.0", + "nesbot/carbon": "^2.0", + "php": ">=7.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.9", + "malukenho/docheader": "^0.1.6", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^7.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + }, + "hyperf": { + "config": "Hyperf\\Crontab\\ConfigProvider" + } + }, + "autoload": { + "psr-4": { + "Hyperf\\Crontab\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A crontab component for Hyperf.", + "homepage": "https://hyperf.io", + "keywords": [ + "crontab", + "hyperf", + "php", + "swoole" + ], + "time": "2020-08-24T08:37:21+00:00" + }, { "name": "hyperf/database", "version": "v2.0.1", @@ -3771,6 +3872,12 @@ "laminas", "zf" ], + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], "time": "2020-05-20T16:45:56+00:00" }, { @@ -4028,6 +4135,16 @@ "logging", "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" }, { @@ -4176,6 +4293,16 @@ "datetime", "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" }, { @@ -4842,6 +4969,16 @@ "php", "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" }, { @@ -5880,6 +6017,20 @@ ], "description": "Symfony Console Component", "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" }, { @@ -5936,6 +6087,20 @@ ], "description": "A generic function and convention to trigger deprecation notices", "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" }, { @@ -6014,6 +6179,20 @@ ], "description": "Symfony EventDispatcher Component", "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" }, { @@ -6082,6 +6261,20 @@ "interoperability", "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" }, { @@ -6137,6 +6330,20 @@ ], "description": "Symfony Finder Component", "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" }, { @@ -6286,6 +6493,20 @@ "polyfill", "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" }, { @@ -6356,6 +6577,20 @@ "portable", "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" }, { @@ -6433,6 +6668,20 @@ "portable", "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" }, { @@ -6506,6 +6755,20 @@ "portable", "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" }, { @@ -6575,6 +6838,20 @@ "portable", "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" }, { @@ -6644,6 +6921,20 @@ "portable", "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" }, { @@ -6709,6 +7000,20 @@ "portable", "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" }, { @@ -6777,6 +7082,20 @@ "portable", "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" }, { @@ -6849,6 +7168,20 @@ "portable", "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" }, { @@ -7289,6 +7622,20 @@ "interoperability", "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" }, { @@ -7366,6 +7713,20 @@ "utf-8", "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" }, { @@ -7450,6 +7811,20 @@ ], "description": "Symfony Translation Component", "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" }, { @@ -7517,6 +7892,20 @@ "interoperability", "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" }, { @@ -7668,6 +8057,16 @@ "env", "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" }, { @@ -7894,6 +8293,20 @@ "Xdebug", "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" }, { @@ -7982,6 +8395,20 @@ "redis", "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" }, { @@ -8053,6 +8480,20 @@ "iterators", "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" }, { @@ -8142,6 +8583,20 @@ "doctrine", "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" }, { @@ -8313,6 +8768,20 @@ "orm", "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" }, { @@ -8494,6 +8963,12 @@ } ], "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" }, { @@ -8732,6 +9207,12 @@ "object", "object graph" ], + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], "time": "2020-06-29T13:22:24+00:00" }, { @@ -9020,6 +9501,20 @@ "MIT" ], "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" }, { @@ -10121,6 +10616,20 @@ ], "description": "Symfony Filesystem Component", "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" }, { @@ -10183,6 +10692,20 @@ "configuration", "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" }, { @@ -10239,6 +10762,20 @@ ], "description": "Symfony Process Component", "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" }, { @@ -10295,6 +10832,20 @@ ], "description": "Symfony Stopwatch Component", "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" }, { @@ -10341,6 +10892,12 @@ } ], "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" } ], diff --git a/config/autoload/crontab.php b/config/autoload/crontab.php new file mode 100644 index 0000000..a01c58d --- /dev/null +++ b/config/autoload/crontab.php @@ -0,0 +1,5 @@ + true, +]; \ No newline at end of file diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 1a5a573..e13cc6b 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -89,4 +89,5 @@ return [ \App\Service\v3\Interfaces\BadgeServiceInterface::class => \App\Service\v3\Implementations\BadgeService::class, \App\Service\v3\Interfaces\InitialDeliveryServiceInterface::class => \App\Service\v3\Implementations\InitialDeliveryService::class, \App\Service\v3\Interfaces\ServiceEvaluateServiceInterface::class => \App\Service\v3\Implementations\ServiceEvaluateService::class, + // \Hyperf\Crontab\Strategy\StrategyInterface::class => \Hyperf\Crontab\Strategy\TaskWorkerStrategy::class, ]; diff --git a/config/autoload/processes.php b/config/autoload/processes.php index 55b80d5..f0bd110 100644 --- a/config/autoload/processes.php +++ b/config/autoload/processes.php @@ -10,4 +10,5 @@ declare(strict_types=1); * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ return [ + Hyperf\Crontab\Process\CrontabDispatcherProcess::class, ]; From 927a7e7a293e10404ec938abc21616f52de4fab2 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 10:34:38 +0800 Subject: [PATCH 06/38] =?UTF-8?q?=E5=8D=95=E7=AC=94=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/JsonRpc/OrdersService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/JsonRpc/OrdersService.php b/app/JsonRpc/OrdersService.php index bc36bdc..51b746a 100644 --- a/app/JsonRpc/OrdersService.php +++ b/app/JsonRpc/OrdersService.php @@ -302,7 +302,7 @@ class OrdersService implements OrdersServiceInterface $this->financialRecordService->storeRefundDirect($order->store->user_id, $order->id, $refundStoreAmount); } - } elseif ($refundType == 'sub') { # 退子订单或者退单品的话,商户只有一个 + } elseif ($refundType == 'sub'||$refundType == 'goods') { # 退子订单或者退单品的话,商户只有一个 $this->financialRecordService->storeRefundDirect($orderChild->store->user_id, $orderChild->id, $refundAmount); } From 40a65297b21062e42e9f8638b3da8b8d5d22b3c7 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 10:39:27 +0800 Subject: [PATCH 07/38] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/LogLabel.php | 5 ++ .../v3/Implementations/OrderOnlineService.php | 81 ++++++++++--------- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/app/Constants/v3/LogLabel.php b/app/Constants/v3/LogLabel.php index 48ce8d5..a5c5bf0 100644 --- a/app/Constants/v3/LogLabel.php +++ b/app/Constants/v3/LogLabel.php @@ -102,4 +102,9 @@ class LogLabel extends AbstractConstants */ const PAY_TO_WX_FAIL_LOG = 'pay_to_wx_fail_log'; + /** + * @Message("自动取消订单失败") + */ + const ORDER_AUTO_CANCEL_FAIL_LOG = 'order_auto_cancel_fail_log'; + } diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 01362b8..177459a 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -647,51 +647,56 @@ class OrderOnlineService implements OrderOnlineServiceInterface public function autoCancel() { - $orderMains = OrderMain::query() - ->select(['global_order_id', 'user_id']) - ->where(['state' => OrderState::UNPAID]) - ->where('created_at', '<', time()-900) - ->get(); - foreach ($orderMains as $key => &$orderMain) { - - // 订单待支付 - $orderMain->state = OrderState::CANCELED; - if (!$orderMain->save()) { - throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE); - } - - // 退还优惠券 - $this->couponService->orderRefundCoupons($orderMain->global_order_id); + try { - // 撤销活动商品购买记录 - $orders = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->get()->toArray(); - $orderGoods = OrderGoods::query() - ->whereIn('order_id', array_values(array_column($orders, 'id'))) - ->get() - ->toArray(); - foreach ($orderGoods as $key => &$goods) { - if ($goods['activity_type'] == 2) { - $this->goodsActivityService->clearCacheRecord($goods['goods_id'], $goods['number'], $orderMain->user_id); + $orderMains = OrderMain::query() + ->select(['global_order_id', 'user_id']) + ->where(['state' => OrderState::UNPAID]) + ->where('created_at', '<', time()-900) + ->get(); + + foreach ($orderMains as $key => &$orderMain) { + + // 订单取消 + OrderMain::query()->where(['id' => $orderMain->id])->update(['state' => OrderState::CANCELED]); + + // 退还优惠券 + $this->couponService->orderRefundCoupons($orderMain->global_order_id); + + // 撤销活动商品购买记录 + $orders = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->get()->toArray(); + $orderGoods = OrderGoods::query() + ->whereIn('order_id', array_values(array_column($orders, 'id'))) + ->get() + ->toArray(); + foreach ($orderGoods as $key => &$goods) { + if ($goods['activity_type'] == 2) { + $this->goodsActivityService->clearCacheRecord($goods['goods_id'], $goods['number'], $orderMain->user_id); + } } - } - // 释redis库存 - $redis = ApplicationContext::getContainer()->get(Redis::class); - foreach ($orderGoods as $k => &$goodsItem) { - // 拼接activity_type和goods_id - $inventoryKey = 'goods_inventory_sold_'.$goodsItem['activity_type'].'_'.$goodsItem['goods_id']; - // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 - if (!$redis->exists($inventoryKey)) { - $redis->set($inventoryKey, 0); - } else { - $redis->decrBy($inventoryKey, intval($goodsItem['number'])); + // 释redis库存 + $redis = ApplicationContext::getContainer()->get(Redis::class); + foreach ($orderGoods as $k => &$goodsItem) { + // 拼接activity_type和goods_id + $inventoryKey = 'goods_inventory_sold_'.$goodsItem['activity_type'].'_'.$goodsItem['goods_id']; + // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 + if (!$redis->exists($inventoryKey)) { + $redis->set($inventoryKey, 0); + } else { + $redis->decrBy($inventoryKey, intval($goodsItem['number'])); + } } + + // 记录badge + $orderChildIds = array_values(array_column($orders, 'store_id')); + $this->badgeService->doByOrder($orderMain->user_id, $orderChildIds, $orderMain->global_order_id, OrderState::CANCELED); } - // 记录badge - $orderChildIds = array_values(array_column($orders, 'store_id')); - $this->badgeService->doByOrder($orderMain->user_id, $orderChildIds, $orderMain->global_order_id, OrderState::CANCELED); + } catch (Exception $e) { + $this->log->event(LogLabel::ORDER_AUTO_CANCEL_FAIL_LOG, ['message' => $e->getMessage()]); } + } } \ No newline at end of file From 1f193747bcc50f869bc80a8aa1608ce8d840fa27 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 11:38:01 +0800 Subject: [PATCH 08/38] =?UTF-8?q?=E9=80=80=E6=AC=BE=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/NotifyController.php | 4 ++-- app/Crontab/AutoCancelOrder.php | 2 +- app/JsonRpc/OrdersService.php | 2 +- app/Service/v3/Implementations/OrderOnlineService.php | 1 - 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/Controller/v3/NotifyController.php b/app/Controller/v3/NotifyController.php index 16d0bc3..fb6cc66 100644 --- a/app/Controller/v3/NotifyController.php +++ b/app/Controller/v3/NotifyController.php @@ -322,8 +322,8 @@ class NotifyController extends BaseController // 查询订单 $orderMain = OrderMain::query() - ->whereIn('state', [OrderState::PAID, OrderState::DELIVERY, OrderState::COMPLETED, OrderState::EVALUATED, OrderState::REFUNDING]) - ->where(['global_order_id' => $reqInfo['out_trade_no'], 'pay_type' => Payment::WECHAT, 'refund_time' => 0]) + ->whereNotIn('state', [OrderState::UNPAID]) + ->where(['global_order_id' => $reqInfo['out_trade_no'], 'pay_type' => Payment::WECHAT]) ->first(); // 订单不存在 diff --git a/app/Crontab/AutoCancelOrder.php b/app/Crontab/AutoCancelOrder.php index dda86f7..24edc16 100644 --- a/app/Crontab/AutoCancelOrder.php +++ b/app/Crontab/AutoCancelOrder.php @@ -7,7 +7,7 @@ use Hyperf\Crontab\Annotation\Crontab; use Hyperf\Di\Annotation\Inject; /** - * @Crontab(name="autocancelorder", rule="*\/5 * * * * *", callback="execute", memo="自定取消15分钟过期订单") + * @Crontab(name="autocancelorder", rule="*\/1 * * * *", callback="execute", memo="自定取消15分钟过期订单") */ class AutoCancelOrder { diff --git a/app/JsonRpc/OrdersService.php b/app/JsonRpc/OrdersService.php index 51b746a..e12d9d5 100644 --- a/app/JsonRpc/OrdersService.php +++ b/app/JsonRpc/OrdersService.php @@ -154,7 +154,7 @@ class OrdersService implements OrdersServiceInterface // 主订单 $orderMain = OrderMain::query() ->where(['global_order_id' => $global_order_id, 'user_id' => $user_id]) - ->whereIn('state', OrderState::CAN_REFUND_DIRECT) + ->whereIn('state', array_merge(OrderState::CAN_REFUND_DIRECT, [OrderState::REFUNDED])) ->first(); if (is_null($orderMain)) { diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 177459a..bf6c5f6 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -651,7 +651,6 @@ class OrderOnlineService implements OrderOnlineServiceInterface try { $orderMains = OrderMain::query() - ->select(['global_order_id', 'user_id']) ->where(['state' => OrderState::UNPAID]) ->where('created_at', '<', time()-900) ->get(); From b50ec7991ed8c68ebe80a5398764fa6a6b8982da Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 11:59:41 +0800 Subject: [PATCH 09/38] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E7=9A=84=E9=80=80=E6=AC=BE=E9=87=8A=E6=94=BE=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/OrderOnlineService.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index bf6c5f6..88963d5 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -639,6 +639,22 @@ class OrderOnlineService implements OrderOnlineServiceInterface $orderMain = $this->check($globalOrderId, $userId, OrderState::REFUNDING); + $orderIds = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->pluck('id'); + $orderGoods = OrderGoods::query()->whereIn('order_id', $orderIds)->get()->toArray(); + + // 释redis库存 + $redis = ApplicationContext::getContainer()->get(Redis::class); + foreach ($orderGoods as $k => &$goodsItem) { + // 拼接activity_type和goods_id + $inventoryKey = 'goods_inventory_sold_'.$goodsItem['activity_type'].'_'.$goodsItem['goods_id']; + // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 + if (!$redis->exists($inventoryKey)) { + $redis->set($inventoryKey, 0); + } else { + $redis->decrBy($inventoryKey, intval($goodsItem['number'])); + } + } + // 微信退款 if ($orderMain->pay_type == Payment::WECHAT) { return $this->paymentService->undo($orderMain->global_order_id, $userId); From 40b68b95176afcdb1c5d629de8524ee4de0f3594 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 13:02:28 +0800 Subject: [PATCH 10/38] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/ErrorCode.php | 2 +- .../Implementations/GoodsActivityService.php | 2 +- .../v3/Implementations/GoodsService.php | 2 +- .../v3/Implementations/ShopCartService.php | 13 +- composer.lock | 498 ------------------ 5 files changed, 13 insertions(+), 504 deletions(-) diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index 1798098..ad53e63 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -252,7 +252,7 @@ class ErrorCode extends AbstractConstants /** * 已下架 - * @Message("商品可能已下架") + * @Message("商品不存在") */ const GOODS_NOT_EXISTS = 1104; diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index b838e88..bfe149e 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -49,7 +49,7 @@ class GoodsActivityService implements GoodsActivityServiceInterface // 商品库存不足 // 获取冻结的库存 - // $inventoryFrozen = (int)$redis->get($inventoryKey); + //$inventoryFrozen = (int)$redis->get($inventoryKey); $inventoryFrozen = 0; if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR; diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 9dc9776..6740d92 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -40,7 +40,7 @@ class GoodsService implements GoodsServiceInterface } // 商品库存不足 // 获取冻结的库存 - // $inventoryFrozen = (int)$redis->get($inventoryKey); + //$inventoryFrozen = (int)$redis->get($inventoryKey); $inventoryFrozen = 0; if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ return ErrorCode::GOODS_INVENTORY_ERROR; diff --git a/app/Service/v3/Implementations/ShopCartService.php b/app/Service/v3/Implementations/ShopCartService.php index 1915ab1..be65d33 100644 --- a/app/Service/v3/Implementations/ShopCartService.php +++ b/app/Service/v3/Implementations/ShopCartService.php @@ -2,6 +2,8 @@ namespace App\Service\v3\Implementations; +use App\Constants\v3\ErrorCode; +use App\Exception\ErrorCodeException; use App\Model\v3\Goods; use App\Model\v3\GoodsActivity; use App\Model\v3\ShoppingCart; @@ -166,8 +168,13 @@ class ShopCartService implements ShopCartServiceInterface $cartList = []; $totalAmount = 0; 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; } @@ -191,7 +198,6 @@ class ShopCartService implements ShopCartServiceInterface } if ($res === true) { - $cartList['store_lists'][$store['id']]['store'] = $store; $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)); + }else{ + throw new ErrorCodeException(ErrorCode::GOODS_INVALID); } } @@ -215,7 +223,6 @@ class ShopCartService implements ShopCartServiceInterface } $cartList['total'] = bcadd($totalAmount, '0', 2); - return $cartList['store_lists']; } diff --git a/composer.lock b/composer.lock index 87fd21c..6910638 100644 --- a/composer.lock +++ b/composer.lock @@ -522,20 +522,6 @@ "uppercase", "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" }, { @@ -598,20 +584,6 @@ "constructor", "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" }, { @@ -680,20 +652,6 @@ "parser", "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" }, { @@ -3872,12 +3830,6 @@ "laminas", "zf" ], - "funding": [ - { - "url": "https://funding.communitybridge.org/projects/laminas-project", - "type": "community_bridge" - } - ], "time": "2020-05-20T16:45:56+00:00" }, { @@ -4135,16 +4087,6 @@ "logging", "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" }, { @@ -4293,16 +4235,6 @@ "datetime", "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" }, { @@ -4969,16 +4901,6 @@ "php", "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" }, { @@ -6017,20 +5939,6 @@ ], "description": "Symfony Console Component", "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" }, { @@ -6087,20 +5995,6 @@ ], "description": "A generic function and convention to trigger deprecation notices", "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" }, { @@ -6179,20 +6073,6 @@ ], "description": "Symfony EventDispatcher Component", "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" }, { @@ -6261,20 +6141,6 @@ "interoperability", "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" }, { @@ -6330,20 +6196,6 @@ ], "description": "Symfony Finder Component", "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" }, { @@ -6493,20 +6345,6 @@ "polyfill", "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" }, { @@ -6577,20 +6415,6 @@ "portable", "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" }, { @@ -6668,20 +6492,6 @@ "portable", "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" }, { @@ -6755,20 +6565,6 @@ "portable", "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" }, { @@ -6838,20 +6634,6 @@ "portable", "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" }, { @@ -6921,20 +6703,6 @@ "portable", "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" }, { @@ -7000,20 +6768,6 @@ "portable", "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" }, { @@ -7082,20 +6836,6 @@ "portable", "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" }, { @@ -7168,20 +6908,6 @@ "portable", "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" }, { @@ -7622,20 +7348,6 @@ "interoperability", "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" }, { @@ -7713,20 +7425,6 @@ "utf-8", "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" }, { @@ -7811,20 +7509,6 @@ ], "description": "Symfony Translation Component", "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" }, { @@ -7892,20 +7576,6 @@ "interoperability", "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" }, { @@ -8057,16 +7727,6 @@ "env", "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" }, { @@ -8293,20 +7953,6 @@ "Xdebug", "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" }, { @@ -8395,20 +8041,6 @@ "redis", "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" }, { @@ -8480,20 +8112,6 @@ "iterators", "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" }, { @@ -8583,20 +8201,6 @@ "doctrine", "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" }, { @@ -8768,20 +8372,6 @@ "orm", "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" }, { @@ -8963,12 +8553,6 @@ } ], "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" }, { @@ -9207,12 +8791,6 @@ "object", "object graph" ], - "funding": [ - { - "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", - "type": "tidelift" - } - ], "time": "2020-06-29T13:22:24+00:00" }, { @@ -9501,20 +9079,6 @@ "MIT" ], "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" }, { @@ -10616,20 +10180,6 @@ ], "description": "Symfony Filesystem Component", "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" }, { @@ -10692,20 +10242,6 @@ "configuration", "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" }, { @@ -10762,20 +10298,6 @@ ], "description": "Symfony Process Component", "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" }, { @@ -10832,20 +10354,6 @@ ], "description": "Symfony Stopwatch Component", "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" }, { @@ -10892,12 +10400,6 @@ } ], "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" } ], From ae1cd23c83ee36f8f93ca52bbdb57d5681ab5acf Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 13:18:48 +0800 Subject: [PATCH 11/38] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/Coupon.php | 8 +++++- .../v3/Implementations/CouponRecService.php | 25 ++----------------- .../v3/Implementations/ShopCartService.php | 5 ++-- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/app/Model/v3/Coupon.php b/app/Model/v3/Coupon.php index f3df3bf..2af1594 100644 --- a/app/Model/v3/Coupon.php +++ b/app/Model/v3/Coupon.php @@ -13,7 +13,8 @@ class Coupon extends Model protected $appends = [ 'full_amount_text', - 'discounts_text' + 'discounts_text', + 'time_text' ]; protected $casts = [ @@ -35,4 +36,9 @@ class Coupon extends Model } } + public function getTimeTextAttribute() + { + return date("Y-m-d H:i:s",$this->attributes['usable_start_time']). ' - ' .date("Y-m-d H:i:s",$this->attributes['usable_end_time']); + } + } diff --git a/app/Service/v3/Implementations/CouponRecService.php b/app/Service/v3/Implementations/CouponRecService.php index fe48062..7fe58e6 100644 --- a/app/Service/v3/Implementations/CouponRecService.php +++ b/app/Service/v3/Implementations/CouponRecService.php @@ -103,7 +103,7 @@ class CouponRecService implements CouponRecServiceInterface public function getListByUser($userId,$type,$page = 1,$pagesize = 5) { //查询优惠券 - $builder = CouponRec::query()->join('lanzu_coupon', 'lanzu_coupon.id', '=', 'lanzu_coupon_receive.coupon_id') + $builder = CouponRec::query()->join('lanzu_coupon', 'lanzu_coupon.id', '=', 'lanzu_coupon_receive.coupon_id')->with('coupon') ->where([ ['lanzu_coupon_receive.user_id' ,'=', $userId], ]); @@ -130,32 +130,11 @@ class CouponRecService implements CouponRecServiceInterface break; } $builder = $builder->select( - 'lanzu_coupon.title', - 'lanzu_coupon.discounts', - 'lanzu_coupon.full_amount', - 'lanzu_coupon.discount_type', - 'lanzu_coupon.introduce', - 'lanzu_coupon.tags', - 'lanzu_coupon.usable_start_time', - 'lanzu_coupon.usable_end_time', - 'lanzu_coupon_receive.number', - 'lanzu_coupon_receive.number_remain' + 'lanzu_coupon_receive.*' ) ->orderBy('lanzu_coupon.weigh','desc'); $paginate = $builder->paginate($pagesize); $couponList = $paginate->toArray(); - foreach ($couponList['data'] as $key => &$coupon) { - //拼接满减文字提示 - $coupon['full_amount_text'] = '满' . $coupon['full_amount'] . "可用"; - //判断是折扣优惠券还是满减优惠券 - if($coupon['discount_type'] == 1){ - $coupon['discounts_text'] = '¥'.$coupon['discounts']; - }elseif($coupon['discount_type'] == 2){ - $coupon['discounts_text'] = floatval($coupon['discounts'])."折"; - } - //拼接时间文字提示 - $coupon['time_text'] = date("Y-m-d H:i:s",$coupon['usable_start_time']). ' - ' .date("Y-m-d H:i:s",$coupon['usable_end_time']); - } return ['has_more_pages' => $paginate->hasMorePages(), 'list' => $couponList['data']]; } diff --git a/app/Service/v3/Implementations/ShopCartService.php b/app/Service/v3/Implementations/ShopCartService.php index be65d33..6a02069 100644 --- a/app/Service/v3/Implementations/ShopCartService.php +++ b/app/Service/v3/Implementations/ShopCartService.php @@ -174,7 +174,7 @@ class ShopCartService implements ShopCartServiceInterface } if (empty($cart->goods)) { - throw new ErrorCodeException(ErrorCode::GOODS_INVALID); + throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS); continue; } @@ -185,6 +185,7 @@ class ShopCartService implements ShopCartServiceInterface // 商户是否歇业 $checkStore = $this->storeService->check($store['id']); if (!$checkStore) { + throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE); continue; } @@ -212,7 +213,7 @@ class ShopCartService implements ShopCartServiceInterface $totalAmount = bcadd($totalAmount, bcmul($cart->goods->price, $cart->num)); }else{ - throw new ErrorCodeException(ErrorCode::GOODS_INVALID); + throw new ErrorCodeException($res); } } From 65bbacbaadf694f32460c2da2ab49c5bbb602e47 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 14:02:39 +0800 Subject: [PATCH 12/38] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=B8=82=E5=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/LocationService.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php index cb5265d..0151b69 100644 --- a/app/Service/v3/Implementations/LocationService.php +++ b/app/Service/v3/Implementations/LocationService.php @@ -84,17 +84,11 @@ class LocationService implements LocationServiceInterface } } - $res = collect($res->toArray())->sortBy(function ($area, $key) { - return $area['distance_num']; + $res = collect($res->toArray())->sortBy(function ($res, $key) { + return $res['distance_num']; }); - $res = collect($res->all())->map(function ($area, $key) { - $markets = collect($area['markets'])->sortBy('distance_num'); - $area['markets'] = $markets->values()->all(); - return $area; - }); - - return $res->all(); + return $res; } public function getNearestMarket($lng,$lat) From 7dda3fbda8129ddbe3573fe8b3e57d0aeb9e23cd Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 14:08:48 +0800 Subject: [PATCH 13/38] =?UTF-8?q?=E5=B8=82=E5=9C=BA=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/LocationService.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php index 0151b69..8db6f55 100644 --- a/app/Service/v3/Implementations/LocationService.php +++ b/app/Service/v3/Implementations/LocationService.php @@ -84,8 +84,9 @@ class LocationService implements LocationServiceInterface } } - $res = collect($res->toArray())->sortBy(function ($res, $key) { - return $res['distance_num']; + $res = collect($res->toArray())->map(function ($res, $key) { + $markets = collect($res)->sortBy('distance_num'); + return $markets; }); return $res; From 1a9daf20249342a9a508f13dc5e3db7b9ebf989b Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 14:12:36 +0800 Subject: [PATCH 14/38] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/GoodsActivityService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index bfe149e..9e0bc45 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -49,8 +49,8 @@ class GoodsActivityService implements GoodsActivityServiceInterface // 商品库存不足 // 获取冻结的库存 - //$inventoryFrozen = (int)$redis->get($inventoryKey); - $inventoryFrozen = 0; + $inventoryFrozen = (int)$redis->get($inventoryKey); + // $inventoryFrozen = 0; if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR; } From f541149c75aff134e7a6466b15c16200a02d8223 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 14:40:43 +0800 Subject: [PATCH 15/38] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/ErrorCode.php | 8 ++--- .../v3/Implementations/OrderOnlineService.php | 34 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index ad53e63..b3aa83c 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -25,7 +25,7 @@ class ErrorCode extends AbstractConstants /** * 线上下单失败 - * @Message("线上下单失败") + * @Message("下单失败") */ const ORDER_ONLINE_FAIL = 601; @@ -234,7 +234,7 @@ class ErrorCode extends AbstractConstants /************************************/ /** * 已卖光 - * @Message("该商品已卖光") + * @Message("有商品已卖光") */ const GOODS_INVENTORY_ERROR = 1101; @@ -262,7 +262,7 @@ class ErrorCode extends AbstractConstants /** * 当前特价商品已被购买过 - * @Message("该活动商品您已买过") + * @Message("有活动商品您已买过") */ const GOODS_ACTIVITY_BUY = 1151; @@ -274,7 +274,7 @@ class ErrorCode extends AbstractConstants /** * 已卖光 - * @Message("该商品已卖光") + * @Message("有商品已卖光") */ const GOODS_ACTIVITY_INVENTORY_ERROR = 1153; diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 88963d5..862cec6 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -117,6 +117,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface public function do($marketId, $userId, $userAddrId, $storeList, $totalMoney, $deliveryTimeNote='尽快送达', $serviceMoney=0, $receiveCouponIds=null, $plat=''){ $redis = ApplicationContext::getContainer()->get(Redis::class); + $isCacheInventory = false; $carts = []; Db::beginTransaction(); try { @@ -189,7 +190,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface } $check = $this->goodsService->check($goods, $cart->num); if (true !== $check) { - throw new ErrorCodeException($check, '['.$goods->name.'/'.$goods->goods_unit.']'); + throw new ErrorCodeException($check, '['.$goods->name.']'); } } elseif ($cart->activity_type == 2) { $goods = GoodsActivity::query()->lockForUpdate()->with('store')->find($cart->goods_id); @@ -198,7 +199,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface } $check = $this->goodsActivityService->check($goods, $cart->num, $userId); if (true !== $check) { - throw new ErrorCodeException($check, '['.$goods->name.'/'.$goods->goods_unit.']'); + throw new ErrorCodeException($check, '['.$goods->name.']'); } } @@ -211,6 +212,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface } else { $redis->incrBy($inventoryKey, intval($cart->num)); } + $isCacheInventory = true; // 算金额 $goodsAmount = bcmul((string)$goods->price, (string)$cart->num); # 当前商品的金额 @@ -359,19 +361,27 @@ class OrderOnlineService implements OrderOnlineServiceInterface return $this->paymentService->do($globalOrderId, $totalAmount, $userId, config('wechat.notify_url.online')); } catch (Exception $e) { Db::rollBack(); - // 释redis库存 - foreach ($carts as $k => &$cart) { - // 拼接activity_type和goods_id - $inventoryKey = 'goods_inventory_sold_'.$cart->activity_type.'_'.$cart->goods_id; - // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 - if (!$redis->exists($inventoryKey)) { - $redis->set($inventoryKey, 0); - } else { - $redis->decrBy($inventoryKey, intval($cart->num)); + + if ($isCacheInventory) { + // 释redis库存 + foreach ($carts as $k => &$cart) { + // 拼接activity_type和goods_id + $inventoryKey = 'goods_inventory_sold_'.$cart->activity_type.'_'.$cart->goods_id; + // redis记录当前商品的购买数量,压库存,下单失败、下单成功扣库存成功、订单取消的时候释放 + if (!$redis->exists($inventoryKey)) { + $redis->set($inventoryKey, 0); + } else { + $redis->decrBy($inventoryKey, intval($cart->num)); + } } } $this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => $e->getMessage()]); - throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_FAIL); + + $message = ''; + if ($e instanceof ErrorCodeException) { + $message = $e->getMessage(); + } + throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_FAIL, $message); } } From bc33820d47a97bec7207fbf686ba8967797d5004 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 14:55:19 +0800 Subject: [PATCH 16/38] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/ShopCartUpdateService.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Service/v3/Implementations/ShopCartUpdateService.php b/app/Service/v3/Implementations/ShopCartUpdateService.php index 8ec7769..3a40bde 100644 --- a/app/Service/v3/Implementations/ShopCartUpdateService.php +++ b/app/Service/v3/Implementations/ShopCartUpdateService.php @@ -11,6 +11,7 @@ use App\Model\v3\ShoppingCart; use App\Model\v3\Goods; use App\Model\v3\GoodsActivity; use App\Constants\v3\Goods as GoodsConstants; +use App\Service\v3\Interfaces\StoreServiceInterface; use Hyperf\Di\Annotation\Inject; class ShopCartUpdateService implements ShopCartUpdateServiceInterface { @@ -26,6 +27,12 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface */ protected $goodsActivityService; + /** + * @Inject + * @var StoreServiceInterface + */ + protected $storeService; + public function do($userId,$goodsId,$num,$activityType) { $goodsType = ''; @@ -56,7 +63,7 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface throw new ErrorCodeException($goodsCheck); } - return ShoppingCart::query()->lockForUpdate()->updateOrCreate( + $shoppingCart = ShoppingCart::query()->lockForUpdate()->updateOrCreate( [ 'user_id' => $userId, 'goods_id' => $goodsId, @@ -69,6 +76,9 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface 'goods_type' => $goodsType ] ); + $storeCheck = $this->storeService->check($goods->store_id); + $shoppingCart->check = $storeCheck; + return $shoppingCart; } public function check() From 8815e419b2aa306840e7ee71f503df1ac9c9539b Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 15:08:38 +0800 Subject: [PATCH 17/38] =?UTF-8?q?=E5=95=86=E5=93=81=E5=94=AE=E5=85=89=20?= =?UTF-8?q?=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/ErrorCode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index b3aa83c..2a6f7c6 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -233,8 +233,8 @@ class ErrorCode extends AbstractConstants /* 商品相关 1101-1150 */ /************************************/ /** - * 已卖光 - * @Message("有商品已卖光") + * 库存不足 + * @Message("库存不足") */ const GOODS_INVENTORY_ERROR = 1101; From 7d0a735e8d4495b77efd98d7cb7d31d7223db895 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 15:15:04 +0800 Subject: [PATCH 18/38] =?UTF-8?q?=E5=95=86=E5=93=81=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E6=B2=A1=E6=9C=89=E4=B8=89=E7=BA=A7=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E6=97=B6=E4=B9=9F=E6=90=9C=E5=87=BA=E6=9D=A5=20?= =?UTF-8?q?=E5=B8=82=E5=9C=BA=E5=88=97=E8=A1=A8=E7=A6=81=E7=94=A8=E5=B8=82?= =?UTF-8?q?=E5=9C=BA=E4=B8=8D=E5=B1=95=E5=87=BA=20=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=BD=AF=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/GoodsCategory.php | 2 ++ app/Model/v3/Market.php | 9 +++++++++ app/Service/v3/Implementations/OrderOnlineService.php | 1 + app/Service/v3/Implementations/SearchService.php | 5 ++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Model/v3/GoodsCategory.php b/app/Model/v3/GoodsCategory.php index e60c54a..462ebbd 100644 --- a/app/Model/v3/GoodsCategory.php +++ b/app/Model/v3/GoodsCategory.php @@ -3,8 +3,10 @@ namespace App\Model\v3; use App\Model\Model; +use Hyperf\Database\Model\SoftDeletes; class GoodsCategory extends Model { + use SoftDeletes; protected $table = 'lanzu_goods_category'; } \ No newline at end of file diff --git a/app/Model/v3/Market.php b/app/Model/v3/Market.php index c151487..a78e15c 100644 --- a/app/Model/v3/Market.php +++ b/app/Model/v3/Market.php @@ -3,6 +3,7 @@ namespace App\Model\v3; use App\Model\Model; +use Hyperf\Database\Model\Builder; class Market extends Model { @@ -14,6 +15,14 @@ class Market extends Model 'region_name' ]; + protected function boot(): void + { + parent::boot(); + self::addGlobalScope('normal', function (Builder $builder) { + $builder->where([$this->getTable().'.status' => 1]); + }); + } + public function getProvinceNameAttribute() { $area = Area::query()->find($this->attributes['province_id']); diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 862cec6..3900cd8 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -679,6 +679,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface $orderMains = OrderMain::query() ->where(['state' => OrderState::UNPAID]) ->where('created_at', '<', time()-900) + ->limit(100) ->get(); foreach ($orderMains as $key => &$orderMain) { diff --git a/app/Service/v3/Implementations/SearchService.php b/app/Service/v3/Implementations/SearchService.php index d726e4e..f605109 100644 --- a/app/Service/v3/Implementations/SearchService.php +++ b/app/Service/v3/Implementations/SearchService.php @@ -56,7 +56,10 @@ class SearchService implements SearchServiceInterface if (isset($params['goods_category_ids']) && $params['goods_category_ids']) { $typeIds = explode(',', $params['goods_category_ids']); - $builder->whereIn(''.$goodsTable.'.goods_category_id', $typeIds); + $builder->where(function ($query) use ($goodsTable, $typeIds) { + $query->whereIn(''.$goodsTable.'.goods_category_id', $typeIds) + ->orWhere(''.$goodsTable.'.goods_category_id', 0); + }); } if (isset($params['keyword']) && $params['keyword']) { From 3f0f5f3ab97bd8da337ce7d5c218f36dbd798653 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 15:20:57 +0800 Subject: [PATCH 19/38] =?UTF-8?q?=E6=8F=90=E7=8E=B0=E9=A1=BB=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/WithdrawController.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Controller/v3/WithdrawController.php b/app/Controller/v3/WithdrawController.php index fb5b2b9..3e30968 100644 --- a/app/Controller/v3/WithdrawController.php +++ b/app/Controller/v3/WithdrawController.php @@ -82,15 +82,16 @@ class WithdrawController extends BaseController ); $data['notice'] = [ - [ - 'title' => '用户须知', - 'content' => '

请仔细填写相关信息,如果由于您填写的信息有误导致资金流失,平台概不负责。

注意:因微信限制当前用户账户余额满1元后才可提现

' - ], + // [ + // 'title' => '用户须知', + // 'content' => '

请仔细填写相关信息,如果由于您填写的信息有误导致资金流失,平台概不负责。

注意:因微信限制当前用户账户余额满1元后才可提现

' + // ], [ 'title' => '提现须知', - 'content' => '

一次提现金额最低为1

' - .'

一次提现金额最高为5000

' - .'

每天可提现10

' + 'content' => '

1、提金额最低为1元,最高为5000元,一天最多可提现10次。

' + .'

2、提现到账时间为一个工作日内。

' + .'

3、提现成功后,提现款会自动转入您当前登录的微信账号

' + .'

4、如果您在提现方面遇到问题,请致电联系我们的服务站。

' ], ]; From 296f76508aef5f8d8de79ef5ee52f49559670162 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 15:35:45 +0800 Subject: [PATCH 20/38] =?UTF-8?q?=E5=B8=82=E5=9C=BA=E8=B7=9D=E7=A6=BB?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/LocationService.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php index 8db6f55..561536f 100644 --- a/app/Service/v3/Implementations/LocationService.php +++ b/app/Service/v3/Implementations/LocationService.php @@ -83,13 +83,8 @@ class LocationService implements LocationServiceInterface $m->distance = ''; } } - - $res = collect($res->toArray())->map(function ($res, $key) { - $markets = collect($res)->sortBy('distance_num'); - return $markets; - }); - - return $res; + $res = collect($res)->sortBy('distance_num'); + return $res->values()->all(); } public function getNearestMarket($lng,$lat) From 17967c92e0791b2705a0cdeb4dc337dbb5e4bade Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 15:49:52 +0800 Subject: [PATCH 21/38] =?UTF-8?q?=E9=85=8D=E9=80=81=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/DistributionPriceService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Service/v3/Implementations/DistributionPriceService.php b/app/Service/v3/Implementations/DistributionPriceService.php index 8b84ab9..83edd1a 100644 --- a/app/Service/v3/Implementations/DistributionPriceService.php +++ b/app/Service/v3/Implementations/DistributionPriceService.php @@ -21,10 +21,10 @@ class DistributionPriceService implements DistributionPriceServiceInterface case ($km >= 5 && $km < 7) : $distributionRrice = bcmul(1.00,($km-3),2); break; - case ($km >= 7 && $km < $deliveryDistance) : + case ($km >= 7 && $km <= $deliveryDistance) : $distributionRrice = bcmul(1.50,($km-3),2); break; - case ($km >= $deliveryDistance) : + case ($km > $deliveryDistance) : throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE); break; default: From b3f78a77b1462e1a9dbe067ef9a1af4e36f7ee47 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 16:01:47 +0800 Subject: [PATCH 22/38] =?UTF-8?q?=E5=95=86=E5=93=81=20banner=20=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E8=A7=86=E9=A2=91=20=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/GoodsActivityBanner.php | 10 +++++----- app/Model/v3/GoodsBanner.php | 13 +++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/Model/v3/GoodsActivityBanner.php b/app/Model/v3/GoodsActivityBanner.php index 8555f3e..223005f 100644 --- a/app/Model/v3/GoodsActivityBanner.php +++ b/app/Model/v3/GoodsActivityBanner.php @@ -2,6 +2,7 @@ namespace App\Model\v3; +use App\Constants\v3\OssThumbnail; use App\Model\Model; use Hyperf\Database\Model\Builder; use Hyperf\Database\Model\SoftDeletes; @@ -18,11 +19,10 @@ class GoodsActivityBanner extends Model public function getBannerUrlAttribute() { - $url = $this->attributes['path']; - if(strripos($url,"http") === false){ - return config('alioss.img_host').'/'.$url; - }else{ - return $url; + if ($this->attributes['type'] == 1) { + return $this->attachmentService->switchImgToAliOss($this->attributes['path'], OssThumbnail::THUMBNAIL_600_Q90); + } elseif ($this->attributes['type'] == 2) { + return $this->attachmentService->switchImgToAliOss($this->attributes['path']); } } } \ No newline at end of file diff --git a/app/Model/v3/GoodsBanner.php b/app/Model/v3/GoodsBanner.php index 8ca3a22..d0cfa69 100644 --- a/app/Model/v3/GoodsBanner.php +++ b/app/Model/v3/GoodsBanner.php @@ -27,13 +27,10 @@ class GoodsBanner extends Model public function getBannerUrlAttribute() { - // $url = $this->attributes['path']; - // if(strripos($url,"http") === false){ - // return config('alioss.img_host').'/'.$url; - // }else{ - // return $url; - // } - - return $this->attachmentService->switchImgToAliOss($this->attributes['path'], OssThumbnail::THUMBNAIL_600_Q90); + if($this->attributes['type'] == 1){ + return $this->attachmentService->switchImgToAliOss($this->attributes['path'], OssThumbnail::THUMBNAIL_600_Q90); + }elseif ($this->attributes['type'] == 2){ + return $this->attachmentService->switchImgToAliOss($this->attributes['path']); + } } } \ No newline at end of file From e78c2fd4a44061e3a753b29a6c98c6c348c2a1e8 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 17:00:27 +0800 Subject: [PATCH 23/38] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81banne?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/GoodsActivityBanner.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Model/v3/GoodsActivityBanner.php b/app/Model/v3/GoodsActivityBanner.php index 223005f..8ca4d06 100644 --- a/app/Model/v3/GoodsActivityBanner.php +++ b/app/Model/v3/GoodsActivityBanner.php @@ -6,9 +6,15 @@ use App\Constants\v3\OssThumbnail; use App\Model\Model; use Hyperf\Database\Model\Builder; use Hyperf\Database\Model\SoftDeletes; - +use App\Service\v3\Interfaces\AttachmentServiceInterface; +use Hyperf\Di\Annotation\Inject; class GoodsActivityBanner extends Model { + /** + * @Inject + * @var AttachmentServiceInterface + */ + protected $attachmentService; use SoftDeletes; protected $table = 'lanzu_goods_activity_banners'; From d4c03b91a3956f8c6bdc0b26b832af6da9f68d08 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 17:08:23 +0800 Subject: [PATCH 24/38] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E4=B8=93=E5=91=98?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=90=8E=20=E4=B8=AA=E4=BA=BA=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E8=BF=98=E6=98=AF=E6=AD=A3=E5=B8=B8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/ServicePersonnel.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Model/v3/ServicePersonnel.php b/app/Model/v3/ServicePersonnel.php index f862bb3..ad1aeaf 100644 --- a/app/Model/v3/ServicePersonnel.php +++ b/app/Model/v3/ServicePersonnel.php @@ -4,9 +4,11 @@ declare (strict_types=1); namespace App\Model\v3; use App\Model\Model; +use Hyperf\Database\Model\SoftDeletes; class ServicePersonnel extends Model { + use SoftDeletes; /** * The table associated with the model. * From 211f199067e613e0ee728b9d175da9c91756e586 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 17:27:22 +0800 Subject: [PATCH 25/38] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E4=B8=93=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/ServicePersonnel.php | 15 ++++++++++++++- .../v3/Implementations/ServiceEvaluateService.php | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Model/v3/ServicePersonnel.php b/app/Model/v3/ServicePersonnel.php index ad1aeaf..807f273 100644 --- a/app/Model/v3/ServicePersonnel.php +++ b/app/Model/v3/ServicePersonnel.php @@ -3,12 +3,20 @@ declare (strict_types=1); namespace App\Model\v3; +use App\Constants\v3\OssThumbnail; use App\Model\Model; +use App\Service\v3\Interfaces\AttachmentServiceInterface; use Hyperf\Database\Model\SoftDeletes; - +use Hyperf\Di\Annotation\Inject; class ServicePersonnel extends Model { use SoftDeletes; + + /** + * @Inject + * @var AttachmentServiceInterface + */ + protected $attachmentService; /** * The table associated with the model. * @@ -21,6 +29,7 @@ class ServicePersonnel extends Model * @var array */ protected $fillable = []; + /** * The attributes that should be cast to native types. * @@ -29,4 +38,8 @@ class ServicePersonnel extends Model // protected $casts = [ // 'set_reward' => 'array' // ]; + public function getHeadUrlAttribute($value) + { + return $this->attachmentService->switchImgToAliOss($value, OssThumbnail::THUMBNAIL_600_Q90); + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/ServiceEvaluateService.php b/app/Service/v3/Implementations/ServiceEvaluateService.php index d7c7724..ec0c41f 100644 --- a/app/Service/v3/Implementations/ServiceEvaluateService.php +++ b/app/Service/v3/Implementations/ServiceEvaluateService.php @@ -3,6 +3,7 @@ namespace App\Service\v3\Implementations; use App\Model\v3\ServiceEvaluate; +use App\Model\v3\ServicePersonnel; use App\Model\v3\User; use App\Service\v3\Interfaces\ServiceEvaluateServiceInterface; use Hyperf\DbConnection\Db; @@ -47,7 +48,7 @@ class ServiceEvaluateService implements ServiceEvaluateServiceInterface public function getPersonnelInfo($service_personnel_id) { - $res = Db::table('lanzu_service_personnel') + $res = ServicePersonnel::query() ->where([ ['id','=',$service_personnel_id], ['status','=',1] From 649b9adbb28a1a72436decf37f9c5d73f3b58caf Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 17:34:10 +0800 Subject: [PATCH 26/38] =?UTF-8?q?=E5=8F=96=E6=B6=88=E9=99=90=E5=88=B6?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Middleware/Auth/ApiMiddleware.php | 16 ++++++++++++++++ .../v3/Implementations/PaymentService.php | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/Middleware/Auth/ApiMiddleware.php b/app/Middleware/Auth/ApiMiddleware.php index 271d20c..f419fa6 100644 --- a/app/Middleware/Auth/ApiMiddleware.php +++ b/app/Middleware/Auth/ApiMiddleware.php @@ -9,6 +9,7 @@ use App\TaskWorker\SSDBTask; use Hashids\Hashids; use Hyperf\HttpServer\Contract\RequestInterface as HttpRequest; use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse; +use Hyperf\HttpServer\Router\Router; use Hyperf\Utils\ApplicationContext; use Psr\Container\ContainerInterface; use Psr\Http\Message\ResponseInterface; @@ -42,6 +43,21 @@ class ApiMiddleware implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { + + // 拦截v1路由 + // $routePath = $this->request->getPathInfo(); + // $routePath = explode('/', $routePath); + // if ($routePath[1] == 'v1') { + // $content = [ + // "status" => 'ok', + // "code" => 99999, + // "result" => [], + // "message" => '服务已停止升级,稍后请升级更新小程序(如不能自动更新,请删除小程序后重新进入小程序)' + // ]; + // + // return $this->response->json($content); + // } + // 签名校验 # 获取参数 diff --git a/app/Service/v3/Implementations/PaymentService.php b/app/Service/v3/Implementations/PaymentService.php index b94e236..68b33a7 100644 --- a/app/Service/v3/Implementations/PaymentService.php +++ b/app/Service/v3/Implementations/PaymentService.php @@ -60,7 +60,7 @@ class PaymentService implements PaymentServiceInterface $payMoney = bcmul((string)$orderMain->money, 100, 0); if (env('APP_ENV') != 'prod' && $orderMain->type == OrderType::ONLINE) { - $payMoney = 1; + // $payMoney = 1; } $user = User::select('openid')->find($userId); From 3a38d045e10f56eaa8e50bc825895f12506e456b Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 17:36:23 +0800 Subject: [PATCH 27/38] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/DistributionPriceService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Service/v3/Implementations/DistributionPriceService.php b/app/Service/v3/Implementations/DistributionPriceService.php index 83edd1a..d175935 100644 --- a/app/Service/v3/Implementations/DistributionPriceService.php +++ b/app/Service/v3/Implementations/DistributionPriceService.php @@ -11,6 +11,7 @@ class DistributionPriceService implements DistributionPriceServiceInterface { public function do($distance) { + return 0; $deliveryDistance = config('distance.delivery_distance'); $deliveryDistance = ceil($deliveryDistance/1000); $km = ceil($distance/1000); From 5971299980e80157cded0edc4e9f65675ca41ed4 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 18:04:06 +0800 Subject: [PATCH 28/38] =?UTF-8?q?RPC=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/JsonRpc/OrdersService.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/JsonRpc/OrdersService.php b/app/JsonRpc/OrdersService.php index e12d9d5..68cc52e 100644 --- a/app/JsonRpc/OrdersService.php +++ b/app/JsonRpc/OrdersService.php @@ -129,7 +129,7 @@ class OrdersService implements OrdersServiceInterface * @param $note * @return array */ - public function onlineSingleRefund($user_id, $note, $global_order_id, $order_child_id=null, $order_goods_id=null) + public function onlineSingleRefund($user_id, $note, $global_order_id, $order_child_id='', $order_goods_id='') { Db::beginTransaction(); @@ -168,7 +168,7 @@ class OrdersService implements OrdersServiceInterface // 子订单 $orderChild = null; if ($order_child_id) { - $orderChild = Order::query()->with('store:user_id')->where(['order_main_id' => $orderMain->global_order_id, 'id' => $order_child_id])->first(); + $orderChild = Order::query()->with('store')->where(['order_main_id' => $orderMain->global_order_id, 'id' => $order_child_id])->first(); } // 订单商品 @@ -222,13 +222,14 @@ class OrdersService implements OrdersServiceInterface ]); throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL); } + // 开始退款 $config = config('wxpay'); $app = Factory::payment($config); $app['guzzle_handler'] = CoroutineHandler::class; $result = $app->refund->byOutTradeNumber( $orderMain->global_order_id, - $orderMain->global_order_id, + $orderMain->global_order_id.$order_child_id.$order_goods_id, bcmul($orderMain->money, 100, 0), bcmul($refundAmount, 100, 0), [ From 90b20a26ddd36de4e68a2a2834fe6088560f6b26 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 19:07:18 +0800 Subject: [PATCH 29/38] =?UTF-8?q?=E8=AE=A2=E5=8D=95=20=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/CouponRecService.php | 2 +- app/Service/v3/Implementations/OrderListService.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Service/v3/Implementations/CouponRecService.php b/app/Service/v3/Implementations/CouponRecService.php index 7fe58e6..7f74743 100644 --- a/app/Service/v3/Implementations/CouponRecService.php +++ b/app/Service/v3/Implementations/CouponRecService.php @@ -281,7 +281,7 @@ class CouponRecService implements CouponRecServiceInterface ->where('user_id',$userId) ->get(); foreach ($coupons as $coupon){ - if($coupon->coupon->usable_end_time < time() || $coupon->coupon->status != 1){ + if($coupon->coupon->usable_end_time < time()){ $res['expired'] += $coupon->number_remain; }else{ $res['unused'] += $coupon->number_remain; diff --git a/app/Service/v3/Implementations/OrderListService.php b/app/Service/v3/Implementations/OrderListService.php index 9c99119..5d23bce 100644 --- a/app/Service/v3/Implementations/OrderListService.php +++ b/app/Service/v3/Implementations/OrderListService.php @@ -97,8 +97,8 @@ class OrderListService implements OrderListServiceInterface ->select(''.$childTable.'.*') ->join($mainTable, ''.$childTable.'.order_main_id', '=', ''.$mainTable.'.global_order_id') ->with(['orderMain', 'orderGoods']) - ->where(['store_id' => $storeId, ''.$mainTable.'.type' => OrderType::ONLINE]); - + ->where(['store_id' => $storeId, ''.$mainTable.'.type' => OrderType::ONLINE]) + ->whereNull($mainTable.'.deleted_at'); switch ($tab) { case 'all': break; @@ -163,6 +163,7 @@ class OrderListService implements OrderListServiceInterface ->select(''.$mainTable.'.*', ''.$childTable.'.order_num') ->join($childTable, ''.$childTable.'.order_main_id', '=', ''.$mainTable.'.global_order_id') ->where([''.$childTable.'.store_id' => $storeId, ''.$mainTable.'.type' => OrderType::OFFLINE]) + ->whereNull($mainTable.'.deleted_at') ->with('user'); // if(!empty($start_time) && !empty($end_time)){ From 887f7fc84566f872a081042ea5fa4f02c8c5a610 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 20:07:50 +0800 Subject: [PATCH 30/38] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=95=86=E5=93=81?= =?UTF-8?q?=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/ErrorCode.php | 4 ++-- app/Service/v3/Implementations/GoodsActivityService.php | 7 ++++++- app/Service/v3/Implementations/OrderOnlineService.php | 7 ++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index 2a6f7c6..9fa3de0 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -262,7 +262,7 @@ class ErrorCode extends AbstractConstants /** * 当前特价商品已被购买过 - * @Message("有活动商品您已买过") + * @Message("活动商品您已买过") */ const GOODS_ACTIVITY_BUY = 1151; @@ -286,7 +286,7 @@ class ErrorCode extends AbstractConstants /** * 商品超过限购数量 - * @Message("有活动商品超过限购数量") + * @Message("同类活动商品超过限购数量") */ const GOODS_ACTIVITY_RESTRICT_LIMIT = 1155; diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index 9e0bc45..e15ad50 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -140,8 +140,13 @@ class GoodsActivityService implements GoodsActivityServiceInterface public function checkOrderActivityCount($orderGoods, $limitNum=1) { + $goodsIds = []; + foreach ($orderGoods as $key => &$storeGoods) { + $goodsIds = array_merge($goodsIds, array_column(array_values($storeGoods), 'goods_id')); + } + $sourceGoods = GoodsActivity::query() - ->whereIn('id', array_values(array_column($orderGoods, 'goods_id'))) + ->whereIn('id', $goodsIds) ->get()->toArray(); $limitNums = [ diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 3900cd8..6208a23 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -339,9 +339,10 @@ class OrderOnlineService implements OrderOnlineServiceInterface // 订单成功,做一些处理 // 活动商品购买记录 foreach ($dataOrderGoods as $key => &$goods) { - foreach ($goods as $k => &$goodsItem) - if ($goodsItem['activity_type'] == 2) { - $this->goodsActivityService->cacheRecord($goodsItem['goods_id'], $goodsItem['number'], $userId); + foreach ($goods as $k => &$goodsItem) { + if ($goodsItem['activity_type'] == 2) { + $this->goodsActivityService->cacheRecord($goodsItem['goods_id'], $goodsItem['number'], $userId); + } } } From c490d7d6a1562ad275045a7758069e5b4823e6d3 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 20:33:20 +0800 Subject: [PATCH 31/38] =?UTF-8?q?=E5=95=86=E5=93=81=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E9=99=90=E8=B4=AD=E5=90=8C=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/GoodsActivityService.php | 9 ++------- app/Service/v3/Implementations/OrderOnlineService.php | 7 ++++++- .../v3/Interfaces/GoodsActivityServiceInterface.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index e15ad50..691b46f 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -133,18 +133,13 @@ class GoodsActivityService implements GoodsActivityServiceInterface /** * 统计订单中活动商品的数量,并校验 - * @param $orderGoods + * @param $goodsIds * @param int $limitNum * @return bool */ - public function checkOrderActivityCount($orderGoods, $limitNum=1) + public function checkOrderActivityCount($goodsIds, $limitNum=1) { - $goodsIds = []; - foreach ($orderGoods as $key => &$storeGoods) { - $goodsIds = array_merge($goodsIds, array_column(array_values($storeGoods), 'goods_id')); - } - $sourceGoods = GoodsActivity::query() ->whereIn('id', $goodsIds) ->get()->toArray(); diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 6208a23..2679efb 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -158,6 +158,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface $dataChildren = []; # 子订单 $dataOrderGoods = []; # 订单商品 $storeTypeIds = []; # 订单中的商户类型,用于校验红包 + $activityGoodsIds = []; # 活动商品IDs foreach ($storeList as $key => &$storeItem) { @@ -214,6 +215,10 @@ class OrderOnlineService implements OrderOnlineServiceInterface } $isCacheInventory = true; + if ($cart->activity_type == 2) { + $activityGoodsIds[] = $cart->goods_id; + } + // 算金额 $goodsAmount = bcmul((string)$goods->price, (string)$cart->num); # 当前商品的金额 $subAmount = bcadd((string)$subAmount, (string)$goodsAmount); # 当前店铺子订单的金额 @@ -330,7 +335,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface } // 判断是否有购买多个特价商品 - $check = $this->goodsActivityService->checkOrderActivityCount($dataOrderGoods); + $check = $this->goodsActivityService->checkOrderActivityCount($activityGoodsIds); if(!$check){ $this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => '订单中有活动商品超过限购数量', 'data' => json_encode($dataOrderGoods)]); throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT); diff --git a/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php b/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php index 64ab163..cac9c86 100644 --- a/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php +++ b/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php @@ -13,5 +13,5 @@ interface GoodsActivityServiceInterface public function detail($goodsId); public function cacheRecord($goodsId, $num, $userId); public function clearCacheRecord($goodsId, $num, $userId); - public function checkOrderActivityCount($orderGoods, $limitNum=1); + public function checkOrderActivityCount($goodsIds, $limitNum=1); } \ No newline at end of file From 1017773f73714ea254f77782d3530d319803f50d Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 20:58:18 +0800 Subject: [PATCH 32/38] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A6=96=E9=A1=B5tabs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/TabsService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Service/v3/Implementations/TabsService.php b/app/Service/v3/Implementations/TabsService.php index b861672..ad6a645 100644 --- a/app/Service/v3/Implementations/TabsService.php +++ b/app/Service/v3/Implementations/TabsService.php @@ -26,10 +26,10 @@ class TabsService implements TabsServiceInterface public function allForAppletIndex() { return [ - ['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '推荐', 'subtitle' => '猜你喜欢', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], - ['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '懒族上新', 'subtitle' => '买点不一样', 'badge' => '限时', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], - ['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '实时鲜货', 'subtitle' => '今天辛苦了', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], - ['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '上班带餐', 'subtitle' => '轻奢快手菜', 'badge' => '不慌', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], + ['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '猜你喜欢', 'subtitle' => '你的菜我知道', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], + ['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '每日上新', 'subtitle' => '新鲜当日达', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], + ['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '懒族优选', 'subtitle' => '买点不一样的', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], + ['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '白领餐食', 'subtitle' => '轻奢快手菜', 'badge' => '手到食来', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], ]; } } \ No newline at end of file From c021e20ee1afa9590d7750286ffe752f257568c5 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 18 Sep 2020 21:05:57 +0800 Subject: [PATCH 33/38] tabs --- app/Service/v3/Implementations/TabsService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Service/v3/Implementations/TabsService.php b/app/Service/v3/Implementations/TabsService.php index ad6a645..1c58f98 100644 --- a/app/Service/v3/Implementations/TabsService.php +++ b/app/Service/v3/Implementations/TabsService.php @@ -26,9 +26,9 @@ class TabsService implements TabsServiceInterface public function allForAppletIndex() { return [ - ['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '猜你喜欢', 'subtitle' => '你的菜我知道', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], + ['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '猜你喜欢', 'subtitle' => '我是你的菜', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], ['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '每日上新', 'subtitle' => '新鲜当日达', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], - ['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '懒族优选', 'subtitle' => '买点不一样的', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], + ['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '懒族优选', 'subtitle' => '发现不一样', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], ['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '白领餐食', 'subtitle' => '轻奢快手菜', 'badge' => '手到食来', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], ]; } From 04fc6b7ae9f27ba559efbd0789c8251d0345d58a Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 21:28:25 +0800 Subject: [PATCH 34/38] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E9=99=90=E8=B4=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/ShopCartUpdateService.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Service/v3/Implementations/ShopCartUpdateService.php b/app/Service/v3/Implementations/ShopCartUpdateService.php index 3a40bde..2e7f1a7 100644 --- a/app/Service/v3/Implementations/ShopCartUpdateService.php +++ b/app/Service/v3/Implementations/ShopCartUpdateService.php @@ -44,6 +44,15 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface if(empty($goods)){ throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS); } + //特价商品限购 + $goodsArr = ShoppingCart::query() + ->where(['user_id' => $userId,'market_id' => $goods->market_id,'activity_type' => GoodsConstants::IS_ACTIVITY]) + ->pluck('goods_id')->toArray(); + array_push($goodsArr,$goodsId); + $checkGoodsActivity = $this->goodsActivityService->checkOrderActivityCount($goodsArr); + if(!$checkGoodsActivity){ + throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_BUY); + } $goodsCheck = $this->goodsActivityService->check($goods,$num,$userId); }else{ $builder = Goods::query(); From 0f44031473cc6dd7751a6ffd0d78d0a3dcd58eb8 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 21:39:44 +0800 Subject: [PATCH 35/38] =?UTF-8?q?=E6=94=B6=E8=B4=A7=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/UserAddressService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index cc2b283..4d761f8 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -39,6 +39,10 @@ class UserAddressService implements UserAddressServiceInterface 'tel' => $tel, 'tags' => $tags ]); + if(empty($userAddressId)){ + UserAddress::query()->where(['user_id'=> $user_id,'is_default'=> 1])->update(['is_default' => 0]); + UserAddress::query()->where('id',$userAddressId)->update(['is_default' => 1]); + } return $userAddress; } From 6a6e57d9c60cedb3da1d6e3bbb8a2fb5d1784f4d Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 21:41:48 +0800 Subject: [PATCH 36/38] =?UTF-8?q?=E6=94=B6=E8=B4=A7=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/UserAddressService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index 4d761f8..90993f7 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -41,7 +41,7 @@ class UserAddressService implements UserAddressServiceInterface ]); if(empty($userAddressId)){ UserAddress::query()->where(['user_id'=> $user_id,'is_default'=> 1])->update(['is_default' => 0]); - UserAddress::query()->where('id',$userAddressId)->update(['is_default' => 1]); + UserAddress::query()->where('id',$userAddress->id)->update(['is_default' => 1]); } return $userAddress; } From d7f02c5c9c2f65b55642b40eee746a7bc77928a5 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 23:34:40 +0800 Subject: [PATCH 37/38] =?UTF-8?q?=E6=94=B6=E8=B4=A7=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/UserAddressService.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index 90993f7..ca76458 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -10,7 +10,7 @@ use App\Service\v3\Interfaces\DistributionPriceServiceInterface; use App\Service\v3\Interfaces\LocationServiceInterface; use App\Service\v3\Interfaces\UserAddressServiceInterface; use Hyperf\Di\Annotation\Inject; - +use Hyperf\DbConnection\Db; class UserAddressService implements UserAddressServiceInterface { /** @@ -40,8 +40,10 @@ class UserAddressService implements UserAddressServiceInterface 'tags' => $tags ]); if(empty($userAddressId)){ - UserAddress::query()->where(['user_id'=> $user_id,'is_default'=> 1])->update(['is_default' => 0]); - UserAddress::query()->where('id',$userAddress->id)->update(['is_default' => 1]); + Db::transaction(function ($user_id,$userAddress) { + UserAddress::query()->where(['user_id'=> $user_id,'is_default'=> 1])->update(['is_default' => 0]); + UserAddress::query()->where('id',$userAddress->id)->update(['is_default' => 1]); + }); } return $userAddress; } From 01f866fe53cf8d5de18a481e84595383de1af622 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 18 Sep 2020 23:37:43 +0800 Subject: [PATCH 38/38] =?UTF-8?q?=E6=94=B6=E8=B4=A7=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/UserAddressService.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index ca76458..646d95f 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -40,9 +40,10 @@ class UserAddressService implements UserAddressServiceInterface 'tags' => $tags ]); if(empty($userAddressId)){ - Db::transaction(function ($user_id,$userAddress) { + $userAddressId = $userAddress->id; + Db::transaction(function () use ($user_id,$userAddressId) { UserAddress::query()->where(['user_id'=> $user_id,'is_default'=> 1])->update(['is_default' => 0]); - UserAddress::query()->where('id',$userAddress->id)->update(['is_default' => 1]); + UserAddress::query()->where('id',$userAddressId)->update(['is_default' => 1]); }); } return $userAddress;