'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); } }