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.

72 lines
1.8 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\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. //服务站最晚营业时间
  38. if (env('APP_ENV') === 'prod') {
  39. $closedTime = strtotime(config('market_rest_time'));
  40. if(time() > $closedTime){
  41. throw new ErrorCodeException(ErrorCode::MARKET_REST);
  42. }
  43. }
  44. return true;
  45. }
  46. public function undo()
  47. {
  48. // TODO: Implement undo() method.
  49. }
  50. public function getBanner($goodsId)
  51. {
  52. $banner = GoodsBanner::query()->where('goods_id',$goodsId)->orderByDesc('type')->get();
  53. return $banner;
  54. }
  55. public function detail($goodsId)
  56. {
  57. $res = Goods::query()->with('store')->where('id',$goodsId)->first();
  58. return $res;
  59. }
  60. }