Browse Source

Merge branch 'bachelor'

master
Lemon 5 years ago
parent
commit
8b16318911
  1. 2
      app/Constants/v3/ErrorCode.php
  2. 14
      app/Controller/v3/GoodsController.php
  3. 12
      app/Controller/v3/ShopCartUpdateController.php
  4. 8
      app/Model/v3/Goods.php
  5. 6
      app/Model/v3/GoodsActivity.php
  6. 2
      app/Request/v3/ShopCartUpdateRequest.php
  7. 43
      app/Service/v3/Implementations/GoodsActivityService.php
  8. 13
      app/Service/v3/Implementations/ShopCartUpdateService.php
  9. 1
      app/Service/v3/Interfaces/GoodsActivityServiceInterface.php
  10. 1
      config/routes.php

2
app/Constants/v3/ErrorCode.php

@ -298,7 +298,7 @@ class ErrorCode extends AbstractConstants
/** /**
* 已卖光 * 已卖光
* @Message("商品已卖光")
* @Message("库存不足")
*/ */
const GOODS_ACTIVITY_INVENTORY_ERROR = 1153; const GOODS_ACTIVITY_INVENTORY_ERROR = 1153;

14
app/Controller/v3/GoodsController.php

@ -6,6 +6,7 @@ use App\Constants\v3\ErrorCode;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Model\v3\Category; use App\Model\v3\Category;
use App\Model\v3\GoodsActivity;
use App\Model\v3\GoodsCategory; use App\Model\v3\GoodsCategory;
use App\Request\v3\GoodsEditorRequest; use App\Request\v3\GoodsEditorRequest;
use App\Service\v3\Interfaces\CategoryServiceInterface; use App\Service\v3\Interfaces\CategoryServiceInterface;
@ -199,4 +200,17 @@ class GoodsController extends BaseController
$bannerId = $this->request->input('banner_id',0); $bannerId = $this->request->input('banner_id',0);
return $this->success($this->goodsService->bannerDelete($bannerId)); return $this->success($this->goodsService->bannerDelete($bannerId));
} }
public function getList()
{
$page = $this->request->input('page',0);
$pagesize = $this->request->input('pagesize',10);
$activity = $this->request->input('activity','');
$marketId = $this->request->input('market_id',-1);
$res = '';
if($activity == 'bachelor'){
$res = $this->goodsActivityService->getList($marketId,$page,$pagesize);
}
return $this->success($res);
}
} }

12
app/Controller/v3/ShopCartUpdateController.php

@ -5,6 +5,7 @@ namespace App\Controller\v3;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Model\v3\ShoppingCart;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface; use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
@ -28,7 +29,15 @@ class ShopCartUpdateController extends BaseController
$goodsId = $this->request->input('goods_id',0); $goodsId = $this->request->input('goods_id',0);
$num = $this->request->input('num',0); $num = $this->request->input('num',0);
$activityType = $this->request->input('activity_type',1); $activityType = $this->request->input('activity_type',1);
if($num <= 0){
$shopcartIds = ShoppingCart::query()->where([
'user_id' => $userId,
'goods_id' => $goodsId,
'activity_type' => $activityType
])
->value('id');
$res = $this->shopCarServiceUpdate->undo($shopcartIds);
}else{
if ($activityType == 2) { if ($activityType == 2) {
// TODO 校验当前用户今天是否超过了购买活动秒杀商品的(特定价格)的订单笔数 // TODO 校验当前用户今天是否超过了购买活动秒杀商品的(特定价格)的订单笔数
if (!$this->orderOnlineService->checkIfBuyFlashGoodsToday($userId)) { if (!$this->orderOnlineService->checkIfBuyFlashGoodsToday($userId)) {
@ -41,6 +50,7 @@ class ShopCartUpdateController extends BaseController
} }
$res = $this->shopCarServiceUpdate->do($userId,$goodsId,$num,$activityType); $res = $this->shopCarServiceUpdate->do($userId,$goodsId,$num,$activityType);
}
return $this->success($res); return $this->success($res);
} }

8
app/Model/v3/Goods.php

@ -82,7 +82,8 @@ class Goods extends Model
'is_effective', 'is_effective',
'noneffective_note', 'noneffective_note',
'details_imgs_url', 'details_imgs_url',
'goods_name'
'goods_name',
'activity_type'
]; ];
protected function boot(): void protected function boot(): void
@ -93,6 +94,11 @@ class Goods extends Model
}); });
} }
public function getActivityTypeAttribute()
{
return 1;
}
public function scopeOrderByDefault($query, $sort) public function scopeOrderByDefault($query, $sort)
{ {
return $query->orderBy($this->getTable().'.sort', $sort)->orderBy($this->getTable().'.id', $sort); return $query->orderBy($this->getTable().'.sort', $sort)->orderBy($this->getTable().'.id', $sort);

6
app/Model/v3/GoodsActivity.php

@ -53,6 +53,7 @@ class GoodsActivity extends Model
'noneffective_note', 'noneffective_note',
'total_seconds', 'total_seconds',
'details_imgs_url', 'details_imgs_url',
'activity_type'
]; ];
// protected $visible = [ // protected $visible = [
@ -68,6 +69,11 @@ class GoodsActivity extends Model
}); });
} }
public function getActivityTypeAttribute()
{
return 2;
}
public function getMonthSalesAttribute() public function getMonthSalesAttribute()
{ {
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);

2
app/Request/v3/ShopCartUpdateRequest.php

@ -16,7 +16,7 @@ class ShopCartUpdateRequest extends BaseFormRequest
{ {
return [ return [
'goods_id' => 'required|nonempty|integer', 'goods_id' => 'required|nonempty|integer',
'num' => 'required|nonempty|integer',
'num' => 'required|integer',
'user_id' => 'required|nonempty|integer|exists:lanzu_user,id', 'user_id' => 'required|nonempty|integer|exists:lanzu_user,id',
]; ];
} }

43
app/Service/v3/Implementations/GoodsActivityService.php

@ -5,8 +5,10 @@ namespace App\Service\v3\Implementations;
use App\Commons\Log; use App\Commons\Log;
use App\Constants\v3\ActivityType; use App\Constants\v3\ActivityType;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Constants\v3\Goods as GoodsConstants;
use App\Constants\v3\LogLabel; use App\Constants\v3\LogLabel;
use App\Constants\v3\SsdbKeys; use App\Constants\v3\SsdbKeys;
use App\Model\v3\Store;
use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
use App\Service\v3\Interfaces\GoodsInventoryServiceInterface; use App\Service\v3\Interfaces\GoodsInventoryServiceInterface;
use App\TaskWorker\SSDBTask; use App\TaskWorker\SSDBTask;
@ -191,4 +193,45 @@ class GoodsActivityService implements GoodsActivityServiceInterface
return true; return true;
} }
public function getList($marketId,$page,$pagesize)
{
$storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable();
$goodsTable = ApplicationContext::getContainer()->get(GoodsActivity::class)->getTable();
$builder = GoodsActivity::query()
->join($storeTable, ''.$storeTable.'.id', '=', ''.$goodsTable.'.store_id')
->with(['store'])
//->where([''.$goodsTable.'.type' => $type])
->where(function ($query) use ($marketId, $goodsTable) {
$query->whereJsonContains(''.$goodsTable.'.market_ids', [(string)$marketId])
->orWhereJsonLength(''.$goodsTable.'.market_ids', '=', 0);
})
->where([''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES])
// ->where(function ($query) use ($goodsTable) {
// $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1);
// })
->whereRaw(''.$goodsTable.'.deleted_at IS NULL')
->where([''.$storeTable.'.market_id' => $marketId])
->where([''.$storeTable.'.is_open' => \App\Constants\v3\Store::IS_OPEN_YES])
->where([''.$storeTable.'.is_rest' => \App\Constants\v3\Store::IS_REST_NO])
->where('time1', '<=', date('H:i'))
->where(function ($query) {
$query->where('time2', '>=', date('H:i'))
->orWhere('time4', '>=', date('H:i'));
})
->where(''.$goodsTable.'.expire_time', '>', time());
$paginate = $builder->select(''.$goodsTable.'.*')->addSelect(''.$goodsTable.'.sales as total_sales')
->orderBy(''.$goodsTable.'.sort', 'DESC')
->orderBy(''.$goodsTable.'.expire_time', 'ASC')
->orderBy(''.$goodsTable.'.created_at', 'DESC')
->paginate($pagesize);
$goodsArr = $paginate->toArray();
$goods = collect($goodsArr['data']);
$goods = $goods->sortBy(function ($product, $key) {
return $product['noneffective_note'];
});
$goods = $goods->values()->all();
return ['has_more_pages' => $paginate->hasMorePages(), 'goods' => $goods];
}
} }

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

@ -69,8 +69,21 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface
if($goodsCheck !== true) if($goodsCheck !== true)
{ {
if($goodsCheck === ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR){
$shopcartNum = ShoppingCart::query()
->where([
'user_id' => $userId,
'goods_id' => $goodsId,
'activity_type' => $activityType
])
->value('num');
if($num > $shopcartNum){
throw new ErrorCodeException($goodsCheck); throw new ErrorCodeException($goodsCheck);
} }
}else{
throw new ErrorCodeException($goodsCheck);
}
}
$shoppingCart = ShoppingCart::query()->lockForUpdate()->updateOrCreate( $shoppingCart = ShoppingCart::query()->lockForUpdate()->updateOrCreate(
[ [

1
app/Service/v3/Interfaces/GoodsActivityServiceInterface.php

@ -14,4 +14,5 @@ interface GoodsActivityServiceInterface
public function cacheRecord($goodsId, $num, $userId); public function cacheRecord($goodsId, $num, $userId);
public function clearCacheRecord($goodsId, $num, $userId); public function clearCacheRecord($goodsId, $num, $userId);
public function checkOrderActivityCount($goodsIds, $limitNum=1); public function checkOrderActivityCount($goodsIds, $limitNum=1);
public function getList($marketId,$page,$pagesize);
} }

1
config/routes.php

@ -100,6 +100,7 @@ Router::addGroup('/v3/', function () {
Router::post('home/market', 'App\Controller\v3\HomeController@marketInfo'); Router::post('home/market', 'App\Controller\v3\HomeController@marketInfo');
Router::post('location/addrSuggestion', 'App\Controller\v3\LocationController@addrSuggestion'); Router::post('location/addrSuggestion', 'App\Controller\v3\LocationController@addrSuggestion');
Router::post('userAddress/deliveryDistance', 'App\Controller\v3\UserAddressController@deliveryDistance'); Router::post('userAddress/deliveryDistance', 'App\Controller\v3\UserAddressController@deliveryDistance');
Router::post('goods/getList', 'App\Controller\v3\GoodsController@getList');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]);
// 需要登录的路由 // 需要登录的路由

Loading…
Cancel
Save