68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?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)
|
|
{
|
|
$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']
|
|
];
|
|
}
|
|
}
|
|
return $goods_extend;
|
|
}
|
|
} |