keepSnapshots(true); $this->addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->status = self::STATUS_PENDING; $this->sn = date('YmdHis') . rand(1000, 9999); $this->create_time = time(); } public function beforeUpdate() { $this->update_time = time(); } public function afterSave() { if ($this->hasUpdated('status')) { $tradeStatus = new TradeStatus(); $tradeStatus->trade_id = $this->id; $tradeStatus->status = $this->getSnapshotData()['status']; $tradeStatus->create(); } } public function afterFetch() { $this->amount = (float)$this->amount; } public static function channelTypes() { return [ self::CHANNEL_ALIPAY => '支付宝', self::CHANNEL_WXPAY => '微信', ]; } public static function statusTypes() { return [ self::STATUS_PENDING => '待支付', self::STATUS_FINISHED => '已完成', self::STATUS_CLOSED => '已关闭', self::STATUS_REFUNDED => '已退款', ]; } }