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.
 
 

55 lines
1.4 KiB

<?php
namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode;
use App\Service\v3\Interfaces\GoodsServiceInterface;
use Hyperf\DbConnection\Db;
use App\Model\v3\Goods;
use App\Model\v3\GoodsBanner;
use App\Constants\v3\Store;
use App\Constants\v3\goods as goodsConstants;
class GoodsService implements GoodsServiceInterface
{
public function do($goodsId)
{
}
public function check($goodsId,$num = 1)
{
$data = Goods::query()->with('store')->where('id', $goodsId)->first();
// 商户歇业
if($data->store->is_rest == 1){
return ErrorCode::GOODS_ON_SALE_NO;
}
// 商品下架或已删除
if($data->on_sale == 0 || !is_null($data->deleted_at)){
return ErrorCode::GOODS_ON_SALE_NO;
}
// 商品库存不足
if($data->is_infinite != 1 && $data->inventory < $num){
return ErrorCode::GOODS_INVENTORY_ERROR;
}
return true;
}
public function undo()
{
// TODO: Implement undo() method.
}
public function getBanner($goodsId)
{
$banner = GoodsBanner::query()->where('goods_id',$goodsId)->orderByDesc('type')->get();
return $banner;
}
public function detail($goodsId)
{
$res = Goods::query()->with('store')->where('id',$goodsId)->first();
return $res;
}
}