first
This commit is contained in:
62
modules/Mall/Models/GoodsSku.php
Normal file
62
modules/Mall/Models/GoodsSku.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Mall\Models;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\HasCovers;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Modules\Mall\Models\Traits\GoodsAttribute;
|
||||
use Overtrue\LaravelVersionable\Versionable;
|
||||
|
||||
class GoodsSku extends Model
|
||||
{
|
||||
|
||||
use HasCovers,
|
||||
Versionable,
|
||||
GoodsAttribute,
|
||||
SoftDeletes;
|
||||
|
||||
protected $table = 'mall_goods_skus';
|
||||
|
||||
/**
|
||||
* 不参与版本记录的字段
|
||||
*
|
||||
* @var array|string[]
|
||||
*/
|
||||
protected array $dontVersionable = ['updated_at'];
|
||||
|
||||
/**
|
||||
* Notes : 所属品牌
|
||||
*
|
||||
* @Date : 2021/5/11 11:00 上午
|
||||
* @Author : < Jason.C >
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function goods(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Goods::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 当前规格是否可购买
|
||||
*
|
||||
* @Date : 2021/5/14 10:08
|
||||
* @Author : Mr.wang
|
||||
* @param int $qty
|
||||
* @return bool
|
||||
*/
|
||||
public function canBuy(int $qty = 1): bool
|
||||
{
|
||||
if ($this->goods->channel == Goods::CHANNEL_FREE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->goods->status == Goods::STATUS_UP && $this->stock >= $qty) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user