ThirdPartyGoodCacheController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\controller\api\thirdParty;
  3. use app\common\repositories\third\ThirdPartyGoodCacheRepository;
  4. use think\db\exception\DbException;
  5. use think\Request;
  6. class ThirdPartyGoodCacheController
  7. {
  8. protected $repository;
  9. public function __construct(ThirdPartyGoodCacheRepository $repository)
  10. {
  11. $this->repository = $repository;
  12. }
  13. /**
  14. * @param Request $request
  15. * @return void
  16. */
  17. public function saveGoodCacheByFit(Request $request)
  18. {
  19. try {
  20. $thirdPartyGoodCacheEntity = $this->repository->saveGoodCacheByFit($request->param());
  21. return app("json")->success($thirdPartyGoodCacheEntity->toArray());
  22. } catch (DbException $e) {
  23. return app('json')->fail($e->getMessage(), null, 401);
  24. }
  25. }
  26. public function getGoodCache(Request $request)
  27. {
  28. if (empty($request['productId'])) {
  29. return app('json')->fail('缺少必要参数', null, 401);
  30. }
  31. $thirdPartyGoodCacheEntity = $this->repository->getThirdPartyGoodCacheEntityByProductId($request['productId']);
  32. return app("json")->success($thirdPartyGoodCacheEntity->toArray());
  33. }
  34. }