<?php


namespace app\models\user;


use freedom\basic\BaseModel;
use freedom\traits\ModelTrait;
use think\facade\Db;

/**
 * TODO 会员Model
 * Class User
 * @package app\models\user
 */
class User extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';
    /**
     * 模型名称
     * @var string
     */
    protected $name = 'user';

    use ModelTrait;


    /**
     * TODO 测试
     * @param array $user
     * @return array
     */
    public static function testDb(array $user): array
    {
        $user = array();
        Db::startTrans();
        try {
            $res1 = self::where(['is' => 7])->update(['username' => '6666']);
            $res2 = self::where(['id' => 3])->update($user);
            // 提交事务
            Db::commit();
            return ['status' => 1, 'msg' => 'success'];
        } catch (\Exception $e) {
            print_r($e->getMessage());
            // 回滚事务
            Db::rollback();
            return ['status' => 0, 'msg' => 'fail'];
        }
    }
}