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(); if (is_array($this->item_info) && !empty($this->item_info)) { $this->item_info = kg_json_encode($this->item_info); } else { $this->item_info = ''; } } public function beforeUpdate() { $this->update_time = time(); if (is_array($this->item_info) && !empty($this->item_info)) { $this->item_info = kg_json_encode($this->item_info); } } public function afterFetch() { $this->amount = (float)$this->amount; if (!empty($this->item_info)) { $this->item_info = json_decode($this->item_info, true); } } public static function itemTypes() { return [ self::ITEM_COURSE => '课程', self::ITEM_PACKAGE => '套餐', self::ITEM_REWARD => '赞赏', self::ITEM_VIP => '会员', self::ITEM_TEST => '测试', ]; } public static function sourceTypes() { return [ self::SOURCE_DESKTOP => 'desktop', self::SOURCE_ANDROID => 'android', self::SOURCE_IOS => 'ios', ]; } public static function statusTypes() { return [ self::STATUS_PENDING => '待支付', self::STATUS_FINISHED => '已完成', self::STATUS_CLOSED => '已关闭', self::STATUS_REFUNDED => '已退款', ]; } }