You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Constants\v3\ErrorCode;
  4. use App\Exception\ErrorCodeException;
  5. use App\Service\v3\Interfaces\GoodsServiceInterface;
  6. use Hyperf\DbConnection\Db;
  7. use App\Model\v3\Goods;
  8. use App\Model\v3\GoodsBanner;
  9. use App\Constants\v3\Store;
  10. use App\Constants\v3\goods as goodsConstants;
  11. class GoodsService implements GoodsServiceInterface
  12. {
  13. public function do($goodsId)
  14. {
  15. }
  16. public function check(Goods $goods,$num = 1)
  17. {
  18. if (empty($goods)) {
  19. return ErrorCode::GOODS_NOT_EXISTS;
  20. }
  21. // 商户歇业
  22. if($goods->store->is_rest == 1){
  23. return ErrorCode::STORE_REST;
  24. }
  25. // 商品下架或已删除
  26. if($goods->on_sale == 0 || !is_null($goods->deleted_at)){
  27. return ErrorCode::GOODS_ON_SALE_NO;
  28. }
  29. // 商品库存不足
  30. if($goods->is_infinite != 1 && $goods->inventory < $num){
  31. return ErrorCode::GOODS_INVENTORY_ERROR;
  32. }
  33. // 是否超过限购数量
  34. if ($goods->restrict_num != 0 && $goods->restrict_num < $num) {
  35. return ErrorCode::GOODS_RESTRICT_LIMIT;
  36. }
  37. return true;
  38. }
  39. public function undo()
  40. {
  41. // TODO: Implement undo() method.
  42. }
  43. public function getBanner($goodsId)
  44. {
  45. $banner = GoodsBanner::query()->where('goods_id',$goodsId)->orderByDesc('type')->get();
  46. return $banner;
  47. }
  48. public function detail($goodsId)
  49. {
  50. $res = Goods::query()->with('store')->where('id',$goodsId)->first();
  51. return $res;
  52. }
  53. }