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.

63 lines
1.5 KiB

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