127 lines
2.8 KiB
PHP
Executable File
127 lines
2.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\model;
|
|
|
|
use think\model\relation\HasOne;
|
|
|
|
class Spu extends Base
|
|
{
|
|
public const TYPE_NORMAL = 'normal';//普通商品
|
|
public const TYPE_SCORE = 'score';//积分商品
|
|
public const TYPE_GROUP_BUY = 'group_buy';// 团购
|
|
public const TYPE_GROUP_MAKE = 'group_make';// 拼团
|
|
public const TYPE_LIMIT_TIME = 'limit_time';// 限时折扣
|
|
|
|
public const SPU_TYPE_ENTITY = 'entity';// 商品类型-实体
|
|
public const SPU_TYPE_VIRTUAL = 'virtual';// 商品类型-虚拟
|
|
|
|
public static function statusTextList(): array
|
|
{
|
|
return [
|
|
(string) self::COMMON_ON => '已上架',
|
|
(string) self::COMMON_OFF => '已下架',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 正常商品列表查询字段
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public static function spuListFields(): array
|
|
{
|
|
return [
|
|
'id', 'name', 'price', 'original_price', 'cover', 'stock', 'amount', 'is_activity', 'activity_type', 'activity_id'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 积分商品列表查询字段
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public static function scoreListFields(): array
|
|
{
|
|
return self::spuListFields();
|
|
}
|
|
|
|
/**
|
|
* 活动类型
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public static function activityList(): array
|
|
{
|
|
return [
|
|
self::TYPE_LIMIT_TIME,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 活动列表
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function activity(): array
|
|
{
|
|
$list = [];
|
|
foreach (self::activityList() as $item) {
|
|
$arr = [];
|
|
$arr['value'] = $item;
|
|
$arr['name'] = self::activityTextList()[$item];
|
|
$list[] = $arr;
|
|
}
|
|
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* 活动类型说明
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public static function activityTextList(): array
|
|
{
|
|
return [
|
|
self::TYPE_LIMIT_TIME => '限时折扣',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 商品类型
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public static function spuTypeTextList(): array
|
|
{
|
|
return [
|
|
self::SPU_TYPE_ENTITY => '实体物品',
|
|
self::SPU_TYPE_VIRTUAL => '虚拟物品',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 限购周期 单位-天
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public static function limitList(): array
|
|
{
|
|
return [
|
|
'0' => '不限',
|
|
'1' => '每天',
|
|
'7' => '每周',
|
|
'30' => '每月',
|
|
'365' => '每年',
|
|
'9999999' => '终身',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return HasOne
|
|
*/
|
|
public function limitTime(): HasOne
|
|
{
|
|
return $this->hasOne(SpuActivity::class, 'id', 'activity_id');
|
|
}
|
|
} |