Files
2026-04-14 17:46:22 +08:00

151 lines
4.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model\live;
use app\common\basics\Models;
use app\common\enum\LiveGoodsEnum;
use app\common\model\goods\Goods;
use app\common\model\shop\Shop;
/**
* 直播商品
* Class LiveGoods
* @package app\common\model\live
*/
class LiveGoods extends Models
{
/**
* @notes 关联商家
* @return \think\model\relation\HasOne
* @author 段誉
* @date 2023/2/16 12:10
*/
public function shop()
{
return $this->hasOne(Shop::class, 'id', 'shop_id')
->field(['id','logo','type','name'])->append(['type_desc']);
}
/**
* @notes 审核状态描述
* @param $value
* @param $data
* @return string|string[]
* @author 段誉
* @date 2023/2/16 9:45
*/
public function getAuditStatusTextAttr($value, $data)
{
return LiveGoodsEnum::getAuditStatusDesc($data['sys_audit_status']);
}
/**
* @notes 价格描述
* @param $value
* @param $data
* @return string
* @author 段誉
* @date 2023/2/16 20:45
*/
public function getPriceTextAttr($value, $data)
{
if ($data['price_type'] == LiveGoodsEnum::PRICE_ONE) {
return '¥' . $data['price'];
} else {
return '¥' . $data['price'] . '~ ¥' .$data['price2'];
}
}
/**
* @notes 价格形式
* @param $value
* @param $data
* @return string|string[]
* @author 段誉
* @date 2023/2/16 21:55
*/
public function getPriceTypeTextAttr($value, $data)
{
return LiveGoodsEnum::getPriceTypeDesc($data['price_type']);
}
/**
* @notes 价格描述
* @param $value
* @param $data
* @return string|void
* @author 段誉
* @date 2023/2/16 21:59
*/
public function getPriceTipsAttr($value, $data)
{
if ($data['price_type'] == LiveGoodsEnum::PRICE_ONE) {
return '价格 ' . $data['price'] . '元';
}
if ($data['price_type'] == LiveGoodsEnum::PRICE_RANGE) {
return '价格 ' . $data['price'] . '元 ~ ' .$data['price2'] . '元';
}
if ($data['price_type'] == LiveGoodsEnum::PRICE_DISCOUNT) {
return '价格 ' . $data['price'] . '元 现价 ' .$data['price2'] . '元';
}
}
/**
* @notes 来源类型
* @param $value
* @param $data
* @return string|string[]
* @author 段誉
* @date 2023/2/17 9:36
*/
public function getSourceTypeTextAttr($value, $data)
{
return LiveGoodsEnum::getSourceTypeDesc($data['source_type']);
}
/**
* @notes 商品库存
* @param $value
* @param $data
* @return int|mixed
* @author 段誉
* @date 2023/2/17 12:12
*/
public function getGoodsStockAttr($value, $data)
{
$stock = 0;
if ($data['source_type'] == LiveGoodsEnum::SOURCE_TYPE_GOODS) {
$stock = Goods::where('id', $data['source_id'])->value('stock');
$stock = empty($stock) ? 0 : $stock;
}
return $stock;
}
}