// +---------------------------------------------------------------------- declare(strict_types=1); namespace app\appmall\model; use app\appmall\library\AppmallSchema; use ywxapp\model\BaseModel; /** * 开发者(中心站) * 表:appmall_developers * @mixin \think\Model */ class Developer extends BaseModel { protected function getOptions(): array { return [ 'strict' => true, 'name' => 'appmall_developers', 'autoWriteTimestamp' => 'int', 'createTime' => 'create_at', 'updateTime' => 'update_at', ]; } /** * 表结构自愈:缺表建表 + 老库扩展列补齐(事实源 app/appmall/install.sql)。 */ public static function ensureSchema(): void { AppmallSchema::ensureTable('appmall_developers', [ 'balance' => "decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '可提现余额'", 'frozen_balance' => "decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '待结算/冻结金额'", ]); } /** * 模型一被使用(含静态查询)就先兜底建表,任何入口都不会再撞 1146。 */ protected function initialize() { parent::initialize(); self::ensureSchema(); } /** * 关联收益记录 * @return \think\model\relation\HasMany */ public function revenues() { return $this->hasMany(Revenue::class, 'developer_id', 'id'); } /** * 关联提现单 * @return \think\model\relation\HasMany */ public function withdrawals() { return $this->hasMany(Withdrawal::class, 'developer_id', 'id'); } }