HaniBlindBox/server/php/app/common/model/DiamondOrder.php
2026-01-01 20:46:07 +08:00

82 lines
1.8 KiB
PHP

<?php
declare (strict_types = 1);
namespace app\common\model;
use think\Model;
/**
* 钻石支付订单记录模型
*/
class DiamondOrder extends Model
{
// 表名
protected $name = 'diamond_orders';
// 自动写入时间戳
protected $autoWriteTimestamp = true;
// 定义时间戳字段名
protected $createTime = 'created_at';
protected $updateTime = false; // 不使用更新时间
// 类型转换
protected $type = [
'id' => 'integer',
'user_id' => 'integer',
'diamond_id' => 'integer',
'amount_paid' => 'float',
'is_first_charge' => 'boolean',
];
// 设置只读字段
protected $readonly = ['order_no'];
// 订单状态常量
const STATUS_PENDING = 'pending';
const STATUS_SUCCESS = 'success';
const STATUS_FAILED = 'failed';
// 支付方式常量
const PAY_METHOD_ALIPAY = 'alipay';
const PAY_METHOD_WECHAT = 'wechat';
/**
* 关联用户
*/
public function user()
{
return $this->belongsTo('User', 'user_id');
}
/**
* 获取订单状态列表
*/
public static function getStatusList()
{
return [
self::STATUS_PENDING => '待支付',
self::STATUS_SUCCESS => '支付成功',
self::STATUS_FAILED => '支付失败'
];
}
/**
* 获取支付方式列表
*/
public static function getPayMethodList()
{
return [
self::PAY_METHOD_ALIPAY => '支付宝',
self::PAY_METHOD_WECHAT => '微信支付'
];
}
/**
* 生成唯一订单号
*/
public static function generateOrderNo()
{
return date('YmdHis') . substr(implode('', array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
}