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.

54 lines
1.4 KiB

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($goodsId,$num = 1)
  16. {
  17. $data = Goods::query()->with('store')->where('id', $goodsId)->first();
  18. // 商户歇业
  19. if($data->store->is_rest == 1){
  20. return ErrorCode::GOODS_ON_SALE_NO;
  21. }
  22. // 商品下架或已删除
  23. if($data->on_sale == 0 || !is_null($data->deleted_at)){
  24. return ErrorCode::GOODS_ON_SALE_NO;
  25. }
  26. // 商品库存不足
  27. if($data->is_infinite != 1 && $data->inventory < $num){
  28. return ErrorCode::GOODS_INVENTORY_ERROR;
  29. }
  30. return true;
  31. }
  32. public function undo()
  33. {
  34. // TODO: Implement undo() method.
  35. }
  36. public function getBanner($goodsId)
  37. {
  38. $banner = GoodsBanner::query()->where('goods_id',$goodsId)->orderByDesc('type')->get();
  39. return $banner;
  40. }
  41. public function detail($goodsId)
  42. {
  43. $res = Goods::query()->with('store')->where('id',$goodsId)->first();
  44. return $res;
  45. }
  46. }