Browse Source

撒大苏打撒

master
Lemon 5 years ago
parent
commit
37c76e85f6
  1. 10
      app/Controller/v3/ShopCartUpdateController.php
  2. 2
      app/Service/v3/Implementations/ActivityService.php
  3. 36
      app/Service/v3/Implementations/ShopCartUpdateService.php
  4. 2
      app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php

10
app/Controller/v3/ShopCartUpdateController.php

@ -15,11 +15,11 @@ class ShopCartUpdateController extends BaseController
protected $shopCarServiceUpdate; protected $shopCarServiceUpdate;
public function update(ShopCartUpdateRequest $request) public function update(ShopCartUpdateRequest $request)
{ {
$user_id = $this->request->input('user_id',0);
$goods_id = $this->request->input('goods_id',0);
$num = $this->request->input('num','');
$activity_type = $this->request->input('activity_type',1);
$res = $this->shopCarServiceUpdate->do($user_id,$goods_id,$num,$activity_type);
$userId = $this->request->input('user_id',0);
$goodsId = $this->request->input('goods_id',0);
$num = $this->request->input('num',0);
$activityType = $this->request->input('activity_type',1);
$res = $this->shopCarServiceUpdate->do($userId,$goodsId,$num,$activityType);
return $this->success($res); return $this->success($res);
} }

2
app/Service/v3/Implementations/ActivityService.php

@ -31,7 +31,7 @@ class ActivityService implements ActivityServiceInterface
->where(['type' => $type]); ->where(['type' => $type]);
if ($marketId != -1) { if ($marketId != -1) {
$builder = $builder->whereJsonContains('market_ids', [(string)$marketId]);
$builder = $builder->where('market_id', $marketId);
} }
return $builder->get()->toArray(); return $builder->get()->toArray();

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

@ -4,33 +4,57 @@ namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
use App\Service\v3\Interfaces\GoodsServiceInterface;
use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface; use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
use App\Model\v3\ShoppingCart; use App\Model\v3\ShoppingCart;
use App\Model\v3\Goods; use App\Model\v3\Goods;
use App\Model\v3\GoodsActivity; use App\Model\v3\GoodsActivity;
use App\Constants\v3\Goods as GoodsConstants; use App\Constants\v3\Goods as GoodsConstants;
use Hyperf\Di\Annotation\Inject;
class ShopCartUpdateService implements ShopCartUpdateServiceInterface class ShopCartUpdateService implements ShopCartUpdateServiceInterface
{ {
public function do($user_id,$goods_id,$num,$activity_type)
/**
* @Inject
* @var GoodsServiceInterface
*/
protected $goodsService;
/**
* @Inject
* @var GoodsActivityServiceInterface
*/
protected $goodsActivityService;
public function do($userId,$goodsId,$num,$activityType)
{ {
$goodsType = ''; $goodsType = '';
//判断是普通商品还是特价商品 //判断是普通商品还是特价商品
if($activity_type == GoodsConstants::IS_ACTIVITY){
if($activityType == GoodsConstants::IS_ACTIVITY){
$builder = GoodsActivity::query(); $builder = GoodsActivity::query();
$goodsType = GoodsActivity::class; $goodsType = GoodsActivity::class;
$goodsModel = $builder->find($goodsId);
$goodsCheck = $this->goodsActivityService->check($goodsModel,$num,$userId);
}else{ }else{
$builder = Goods::query(); $builder = Goods::query();
$goodsType = Goods::class; $goodsType = Goods::class;
$goodsModel = $builder->find($goodsId);
$goodsCheck = $this->goodsService->check($goodsModel,$num);
} }
$goods = $builder->select('market_id','store_id')->find($goods_id);
if(empty($goods)){ if(empty($goods)){
throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS); throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS);
} }
if($goodsCheck !== true)
{
throw new ErrorCodeException($goodsCheck);
}
return ShoppingCart::query()->updateOrCreate( return ShoppingCart::query()->updateOrCreate(
[ [
'user_id' => $user_id,
'goods_id' => $goods_id,
'activity_type' => $activity_type
'user_id' => $userId,
'goods_id' => $goodsId,
'activity_type' => $activityType
], ],
[ [
'market_id' => $goods->market_id, 'market_id' => $goods->market_id,

2
app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php

@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces;
interface ShopCartUpdateServiceInterface interface ShopCartUpdateServiceInterface
{ {
public function do($user_id,$goods_id,$num,$activity_type);
public function do($userId,$goodsId,$num,$activityType);
public function check(); public function check();

Loading…
Cancel
Save