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.

69 lines
1.8 KiB

5 years ago
5 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Service\v3\Interfaces\GoodsServiceInterface;
  4. use Hyperf\DbConnection\Db;
  5. use App\Model\v3\Goods;
  6. use App\Constants\v3\Store;
  7. use App\Constants\v3\goods as goodsConstants;
  8. use App\Model\v3\GoodsActivity;
  9. class GoodsService implements GoodsServiceInterface
  10. {
  11. public function do($goodsId)
  12. {
  13. $res = Goods::query()->with('store')->where('id',$goodsId)->first();
  14. return $res;
  15. }
  16. public function check($goodsId,$num = 1,$activity_type = 1)
  17. {
  18. if($activity_type == goodsConstants::IS_ACTIVITY) {
  19. $builder = GoodsActivity::query();
  20. }else{
  21. $builder = Goods::query();
  22. }
  23. $data = $builder->with('store')->where('id', $goodsId)->first();
  24. //活动商品 校验
  25. if($activity_type == goodsConstants::IS_ACTIVITY) {
  26. if($data->expire_time < time()){
  27. return '活动已结束';
  28. }
  29. }
  30. if($data->store->is_rest != Store::IS_OPEN_YES){
  31. return '店铺已休息';
  32. }
  33. if($data->on_sale == 0 || !is_null($data->deleted_at)){
  34. return '商品已下架';
  35. }
  36. if($data->is_infinite != 1 && $data->inventory < $num){
  37. return '库存不足';
  38. }
  39. return '';
  40. }
  41. public function undo()
  42. {
  43. // TODO: Implement undo() method.
  44. }
  45. public function getBanner()
  46. {
  47. $banner = [
  48. [
  49. 'id' => 1,
  50. 'type' => 1,
  51. 'path' => 'https://img.lanzu.vip/static/img/dic_banners/dic_banner_0.jpg'
  52. ],
  53. [
  54. 'id' => 2,
  55. 'type' => 1,
  56. 'path' => 'https://img.lanzu.vip/static/img/dic_banners/dic_banner_1.jpg'
  57. ]
  58. ];
  59. return $banner;
  60. }
  61. }