<?php
namespace app\model;
/**
 * @property integer $id 主键(ID) - 无注释
 * @property integer $user_id 用户ID
 * @property string $files 文件列表
 * @property string $type 类型
 * @property string $memo 原因
 * @property integer $created_at 创建时间
 * @property integer $updated_at 更新时间
 * @property integer $status 状态
 */
class UserXuanchuan extends Base{
    protected $name = 'user_xuanzhuan';
    protected $autoWriteTimestamp = true;
    protected function getOptions(): array{
        return array_merge(parent::getOptions(),[
            'insert'        =>    [
                'status'    =>  0
            ],
        ]);
    } 
    public static function onAfterUpdate($row)
    {
        $changedData = $row->getChangedData();
        if (isset($changedData['status']) && $changedData['status']==1) {
            if($row->type == 'pyq'){
                \app\model\User::currency1($row->user_id,70,\app\enum\BalanceType::POSTPYQ);
            }else{
                \app\model\User::currency1($row->user_id,70,\app\enum\BalanceType::POSTGROUP);
            }
        }
    }
    function getStatusList(){
        return [
            '0' =>  '等待审核',
            '1' =>  '审核通过',
            '-1' =>  '审核失败',
        ];
    }
    function getTypeList(){
        return [
            'pyq' =>  '朋友圈',
            'group' =>  'QQ群'
        ];
    }
    
    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id');//->setEagerlyType(0);
    }
    
}