Browse Source

商品区分普通特价商品

master
Lemon 5 years ago
parent
commit
cf4a1e1c31
  1. 5
      app/Constants/v3/Goods.php
  2. 1
      app/Model/v3/User.php
  3. 63
      app/Service/v3/Implementations/GoodsActivityService.php
  4. 15
      app/Service/v3/Implementations/GoodsService.php
  5. 11
      app/Service/v3/Interfaces/GoodsActivityServiceInterface.php
  6. 2
      app/Service/v3/Interfaces/GoodsServiceInterface.php

5
app/Constants/v3/Goods.php

@ -25,9 +25,4 @@ class Goods extends AbstractConstants
* @Message("无限库存") * @Message("无限库存")
*/ */
const IS_INVENTORY = 1; const IS_INVENTORY = 1;
/**
* @Message("活动商品")
*/
const IS_ACTIVITY = 2;
} }

1
app/Model/v3/User.php

@ -23,6 +23,7 @@ class User extends Model
'language', 'language',
]; ];
protected $visible = [ protected $visible = [
'id',
'nick_name', 'nick_name',
'avatar', 'avatar',
'openid', 'openid',

63
app/Service/v3/Implementations/GoodsActivityService.php

@ -0,0 +1,63 @@
<?php
namespace App\Service\v3\Implementations;
use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
use Hyperf\DbConnection\Db;
use App\Constants\v3\Store;
use App\Constants\v3\goods as goodsConstants;
use App\Model\v3\GoodsActivity;
class GoodsActivityService implements GoodsActivityServiceInterface
{
public function do($goodsId)
{
$res = GoodsActivity::query()->with('store')->where('id',$goodsId)->first();
return $res;
}
public function check($goodsId,$num = 1)
{
$data = GoodsActivity::query()->with('store')->where('id', $goodsId)->first();
//活动商品 校验
if($data->expire_time < time()){
return '活动已结束';
}
if($data->store->is_rest != Store::IS_OPEN_YES){
return '店铺已休息';
}
if($data->on_sale == 0 || !is_null($data->deleted_at)){
return '商品已下架';
}
if($data->is_infinite != 1 && $data->inventory < $num){
return '库存不足';
}
return '';
}
public function undo()
{
// TODO: Implement undo() method.
}
public function getBanner()
{
$banner = [
[
'id' => 1,
'type' => 1,
'path' => 'https://img.lanzu.vip/static/img/dic_banners/dic_banner_0.jpg'
],
[
'id' => 2,
'type' => 1,
'path' => 'https://img.lanzu.vip/static/img/dic_banners/dic_banner_1.jpg'
]
];
return $banner;
}
}

15
app/Service/v3/Implementations/GoodsService.php

@ -17,20 +17,9 @@ class GoodsService implements GoodsServiceInterface
} }
public function check($goodsId,$num = 1,$activity_type = 1)
public function check($goodsId,$num = 1)
{ {
if($activity_type == goodsConstants::IS_ACTIVITY) {
$builder = GoodsActivity::query();
}else{
$builder = Goods::query();
}
$data = $builder->with('store')->where('id', $goodsId)->first();
//活动商品 校验
if($activity_type == goodsConstants::IS_ACTIVITY) {
if($data->expire_time < time()){
return '活动已结束';
}
}
$data = Goods::query()->with('store')->where('id', $goodsId)->first();
if($data->store->is_rest != Store::IS_OPEN_YES){ if($data->store->is_rest != Store::IS_OPEN_YES){
return '店铺已休息'; return '店铺已休息';
} }

11
app/Service/v3/Interfaces/GoodsActivityServiceInterface.php

@ -0,0 +1,11 @@
<?php
namespace App\Service\v3\Interfaces;
interface GoodsActivityServiceInterface
{
public function do($goodsId);
public function check($goodsId,$num = 1);
public function undo();
public function getBanner();
}

2
app/Service/v3/Interfaces/GoodsServiceInterface.php

@ -5,7 +5,7 @@ namespace App\Service\v3\Interfaces;
interface GoodsServiceInterface interface GoodsServiceInterface
{ {
public function do($goodsId); public function do($goodsId);
public function check($goodsId,$num = 1,$activity_type = 1);
public function check($goodsId,$num = 1);
public function undo(); public function undo();
public function getBanner(); public function getBanner();
} }
Loading…
Cancel
Save