Browse Source

商品上下架

master
Lemon 5 years ago
parent
commit
8be407f374
  1. 6
      app/Controller/v3/GoodsController.php
  2. 8
      app/Service/v3/Implementations/GoodsService.php
  3. 1
      app/Service/v3/Interfaces/GoodsServiceInterface.php
  4. 1
      config/routes.php

6
app/Controller/v3/GoodsController.php

@ -165,4 +165,10 @@ class GoodsController extends BaseController
$tags = $this->goodsService->getTags();
return $this->success(['tags' => $tags]);
}
public function updateOnSale()
{
$goodsId = $this->request->input('id',0);
return $this->success($this->goodsService->updateOnSale($goodsId));
}
}

8
app/Service/v3/Implementations/GoodsService.php

@ -196,4 +196,12 @@ class GoodsService implements GoodsServiceInterface
'新鲜'
];
}
public function updateOnSale($goodsId)
{
$goods = Goods::query()->withoutGlobalScope('normal')->find($goodsId);
$onSale = $goods->on_sale + 1;
$goods->on_sale = $onSale % 2;
return $goods->save();
}
}

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

@ -15,4 +15,5 @@ interface GoodsServiceInterface
public function update($params);
public function info($goodsId);
public function getTags();
public function updateOnSale($goodsId);
}

1
config/routes.php

@ -162,6 +162,7 @@ Router::addGroup('/v3/', function () {
Router::post('category/secend', 'App\Controller\v3\CategoryController@secend');
Router::post('category/third', 'App\Controller\v3\CategoryController@third');
Router::post('goods/create', 'App\Controller\v3\GoodsController@create');
Router::post('goods/updateOnSale', 'App\Controller\v3\GoodsController@updateOnSale');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]);
// 微信支付回调

Loading…
Cancel
Save