From 579810103ed9cf8698535726d2fcf155a7ce0a3f Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 4 Sep 2020 14:08:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=B1=E6=95=88=E5=95=86=E5=93=81=20?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/Goods.php | 8 +++ app/Controller/v3/GoodsController.php | 7 --- app/Controller/v3/LocationController.php | 52 ++++--------------- app/Model/v3/Area.php | 15 ++++++ app/Model/v3/GoodsActivity.php | 12 ++++- app/Model/v3/User.php | 11 ++++ .../v3/Implementations/GoodsService.php | 32 ++++++++++-- .../v3/Implementations/LocationService.php | 31 +++++++++++ .../v3/Implementations/OrderListService.php | 22 ++++---- .../v3/Interfaces/GoodsServiceInterface.php | 2 +- .../Interfaces/LocationServiceInterface.php | 13 +++++ config/autoload/dependencies.php | 1 + 12 files changed, 140 insertions(+), 66 deletions(-) create mode 100644 app/Model/v3/Area.php create mode 100644 app/Service/v3/Implementations/LocationService.php create mode 100644 app/Service/v3/Interfaces/LocationServiceInterface.php diff --git a/app/Constants/v3/Goods.php b/app/Constants/v3/Goods.php index d594abe..79c0568 100644 --- a/app/Constants/v3/Goods.php +++ b/app/Constants/v3/Goods.php @@ -21,5 +21,13 @@ class Goods extends AbstractConstants */ const ON_SALE_NO = 2; + /** + * @Message("无限库存") + */ + const IS_INVENTORY = 1; + /** + * @Message("活动商品") + */ + const IS_ACTIVITY = 2; } \ No newline at end of file diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 68c0fc9..924f978 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -3,7 +3,6 @@ namespace App\Controller\v3; use App\Controller\BaseController; -use App\Service\v3\Interfaces\StoreServiceInterface; use Hyperf\Di\Annotation\Inject; use App\Service\v3\Interfaces\GoodsServiceInterface; class GoodsController extends BaseController @@ -13,12 +12,6 @@ class GoodsController extends BaseController * @var GoodsServiceInterface */ protected $goodsService; - - /** - * @Inject - * @var StoreServiceInterface - */ - protected $storeService; public function detail() { $params = $this->request->all(); diff --git a/app/Controller/v3/LocationController.php b/app/Controller/v3/LocationController.php index 6708fd6..b46ceac 100644 --- a/app/Controller/v3/LocationController.php +++ b/app/Controller/v3/LocationController.php @@ -3,6 +3,8 @@ namespace App\Controller\v3; use App\Controller\BaseController; +use App\Service\v3\Interfaces\LocationServiceInterface; +use Hyperf\Di\Annotation\Inject; /** * 定位相关 @@ -11,6 +13,11 @@ use App\Controller\BaseController; */ class LocationController extends BaseController { + /** + * @Inject + * @var LocationServiceInterface + */ + protected $locationService; /** * 获取当前用户定位最近的市场 @@ -39,48 +46,7 @@ class LocationController extends BaseController public function getMarketListByLocation() { - return $this->success([ - '南宁市' => [ - [ - 'id' => 1, - 'name' => '东沟岭菜市', - 'province_id' => 1, - 'province_name' => '广西', - 'city_id' => 2, - 'city_name' => '南宁市', - 'area_id' => 3, - 'area_name' => '良庆区', - 'address' => '青秀区竹塘路17号', - 'lng' => '108.383566', - 'lat' => '22.759946', - ], - [ - 'id' => 2, - 'name' => '铜鼓岭市场', - 'province_id' => 1, - 'province_name' => '广西', - 'city_id' => 2, - 'city_name' => '南宁市', - 'area_id' => 3, - 'area_name' => '良庆区', - 'address' => '青秀区竹塘路17号', - 'lng' => '108.383566', - 'lat' => '22.759946', - ], - [ - 'id' => 3, - 'name' => '华园菜市', - 'province_id' => 1, - 'province_name' => '广西', - 'city_id' => 2, - 'city_name' => '南宁市', - 'area_id' => 3, - 'area_name' => '良庆区', - 'address' => '青秀区竹塘路17号', - 'lng' => '108.383566', - 'lat' => '22.759946', - ], - ] - ]); + $cityIds = [2163,2189]; + return $this->success($this->locationService->getMarketListByLocation($cityIds)); } } \ No newline at end of file diff --git a/app/Model/v3/Area.php b/app/Model/v3/Area.php new file mode 100644 index 0000000..c77fa5b --- /dev/null +++ b/app/Model/v3/Area.php @@ -0,0 +1,15 @@ +hasMany(Market::class, 'city_id', 'id'); + } +} \ No newline at end of file diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index 5cf01f9..455458c 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/app/Model/v3/GoodsActivity.php @@ -5,11 +5,19 @@ namespace App\Model\v3; use App\Constants\v3\Goods as GoodsConstants; use App\Constants\v3\SsdbKeys; use App\Model\Model; +use App\Service\v3\Interfaces\ShopCartServiceInterface; use Hyperf\Database\Model\Builder; use Hyperf\Utils\ApplicationContext; - +use App\TaskWorker\SSDBTask; +use Hyperf\Di\Annotation\Inject; class GoodsActivity extends Model { + /** + * @Inject + * @var ShopCartServiceInterface + */ + protected $shopCartService; + protected $table = 'lanzu_goods_activity'; protected $casts = [ @@ -44,6 +52,6 @@ class GoodsActivity extends Model public function store() { - return $this->belongsTo(Store::class, 'store_id', 'goods_id'); + return $this->belongsTo(Store::class, 'store_id', 'id'); } } \ No newline at end of file diff --git a/app/Model/v3/User.php b/app/Model/v3/User.php index 7bcb3b8..8df0971 100644 --- a/app/Model/v3/User.php +++ b/app/Model/v3/User.php @@ -22,4 +22,15 @@ class User extends Model 'gender', 'language', ]; + protected $visible = [ + 'nick_name', + 'avatar', + 'openid', + 'unionid', + 'country', + 'province', + 'city', + 'gender', + 'language', + ]; } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 2fda35e..d8cc5f4 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -5,7 +5,9 @@ namespace App\Service\v3\Implementations; use App\Service\v3\Interfaces\GoodsServiceInterface; use Hyperf\DbConnection\Db; use App\Model\v3\Goods; - +use App\Constants\v3\Store; +use App\Constants\v3\goods as goodsConstants; +use App\Model\v3\GoodsActivity; class GoodsService implements GoodsServiceInterface { public function do($goodsId) @@ -15,9 +17,33 @@ class GoodsService implements GoodsServiceInterface } - public function check($goodsId) + public function check($goodsId,$num = 1,$activity_type = 1) { - // TODO: Implement check() method. + if($activity_type == goodsConstants::IS_ACTIVITY) { + $builder = GoodsActivity::query(); + }else{ + $builder = Goods::query(); + } + $data = $builder->with('store')->where('id', $goodsId)->first(); + //活动商品 校验 + if($activity_type == goodsConstants::IS_ACTIVITY) { + if($data->expire_time < time()){ + return '活动已结束'; + } + } + if($data->store->is_rest != Store::IS_OPEN_YES){ + return '店铺已休息'; + } + + if($data->on_sale == 0 || !is_null($data->deleted_at)){ + return '商品已下架'; + } + + if($data->is_infinite != 1 && $data->inventory < $num){ + return '库存不足'; + } + + return ''; } public function undo() diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php new file mode 100644 index 0000000..c828cf6 --- /dev/null +++ b/app/Service/v3/Implementations/LocationService.php @@ -0,0 +1,31 @@ +with('markets')->whereIn('id',$cityIds)->get(); + return $res; + } +} \ No newline at end of file diff --git a/app/Service/v3/Implementations/OrderListService.php b/app/Service/v3/Implementations/OrderListService.php index c16de9e..bcbc6ed 100644 --- a/app/Service/v3/Implementations/OrderListService.php +++ b/app/Service/v3/Implementations/OrderListService.php @@ -96,16 +96,18 @@ class OrderListService implements OrderListServiceInterface public function offlineByStore($storeId, $tab, $page=1, $pagesize=10) { - $builder = Order::query() - ->with(['orderMain' => function($query) { - $query->where('lanzu_order_main.type',4); - }]) - ->with(['user' => function($query) { - $query->select(['lanzu_user.id', 'lanzu_user.nick_name']); - }]) - ->where([ - 'store_id' => $storeId - ]); + $builder = Order::Join('lanzu_order_main','lanzu_order.order_main_id','lanzu_order_main.id') + ->where('store_id', $storeId) + ->where('lanzu_order_main.type',4) + ->with('user'); + + $sw = [ + 'all'=>'', + 'completed'=> OrderState::FINISH, + 'unpaid'=> OrderState::UNPAID, + 'receiving' => OrderState::RECEIVING, + 'refund' => OrderState::REFUND + ]; switch ($tab) { case 'all': break; diff --git a/app/Service/v3/Interfaces/GoodsServiceInterface.php b/app/Service/v3/Interfaces/GoodsServiceInterface.php index 8b6a31c..4b03471 100644 --- a/app/Service/v3/Interfaces/GoodsServiceInterface.php +++ b/app/Service/v3/Interfaces/GoodsServiceInterface.php @@ -5,7 +5,7 @@ namespace App\Service\v3\Interfaces; interface GoodsServiceInterface { public function do($goodsId); - public function check($goodsId); + public function check($goodsId,$num = 1,$activity_type = 1); public function undo(); public function getBanner(); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/LocationServiceInterface.php b/app/Service/v3/Interfaces/LocationServiceInterface.php new file mode 100644 index 0000000..95eb3af --- /dev/null +++ b/app/Service/v3/Interfaces/LocationServiceInterface.php @@ -0,0 +1,13 @@ + \App\Service\v3\Implementations\StoreLoginService::class, \App\Service\v3\Interfaces\StoreInfoServiceInterface::class => \App\Service\v3\Implementations\StoreInfoService::class, \App\Service\v3\Interfaces\BannerServiceInterface::class => \App\Service\v3\Implementations\BannerService::class, + \App\Service\v3\Interfaces\LocationServiceInterface::class => \App\Service\v3\Implementations\LocationService::class, ];