manghe/app/common/model/GoodsExtend.php
2025-04-25 19:30:06 +08:00

84 lines
2.6 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
namespace app\common\model;
use app\common\model\Base;
use think\facade\Db;
class GoodsExtend extends Base
{
// 设置数据表名
protected $name = 'goods_extend';
// 设置主键
protected $pk = 'id';
// 自动写入时间戳
protected $autoWriteTimestamp = false;
/**
* 根据盒子ID获取扩展配置
* @param int $goodsId 盒子ID
* @return array|null 盒子扩展配置信息
*/
public static function getByGoodsId($goodsId)
{
return self::where('goods_id', $goodsId)->find();
}
/**
* 删除盒子扩展配置
* @param int $goodsId 盒子ID
* @return bool 删除结果
*/
public static function deleteByGoodsId($goodsId)
{
return self::where('goods_id', $goodsId)->delete();
}
/**
* 根据盒子ID获取扩展配置
* @param int $goodsId 盒子ID
* @param int $goods_type 盒子类型
* @return array|null 盒子扩展配置信息
*/
public static function getGoodsExtendByGoodsId($goodsId, $goods_type)
{
// // 生成缓存键
// $redis = (new \app\common\server\RedisHelper())->getRedis();
// $cache_key = "goods_extend:{$goodsId}:{$goods_type}";
// // 尝试从缓存获取数据
// $cached_data = $redis->get($cache_key);
// if ($cached_data) {
// return json_decode($cached_data, true);
// }
$goods_extend = self::where('goods_id', $goodsId)->find();
if (!$goods_extend) {
// 从goods_type表获取默认值
$goodsType = Db::name('goods_type')
->field('pay_wechat, pay_balance, pay_currency, pay_currency2, pay_coupon, is_deduction')
->where('value', $goods_type)
->find();
if ($goodsType) {
// 如果找到了盒子类型的默认配置
$goods_extend = [
'goods_id' => $goodsId,
'pay_wechat' => $goodsType['pay_wechat'],
'pay_balance' => $goodsType['pay_balance'],
'pay_currency' => $goodsType['pay_currency'],
'pay_currency2' => $goodsType['pay_currency2'],
'pay_coupon' => $goodsType['pay_coupon'],
'is_deduction' => $goodsType['is_deduction']
];
}
}
// // 将数据存入缓存设置5分钟过期时间
// if ($goods_extend) {
// $redis->set($cache_key, json_encode($goods_extend), 300);
// }
return $goods_extend;
}
}