<?php

namespace common\models;
use yii\base\Exception;
use Yii;
use fx\util\FxUtil;

/**
 * This is the model class for table "order_main".
 *
 * @property integer $id
 * @property string $name
 */
class Test extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'fx_user';
    }
    public function testList(){
        $select = [
            'uid',
           new Expression("ifnull(user_name,'') as user_name") ,
            'phone',
            'nickname'
        ];
        $list=self::find()->select($select)
            ->limit(100)
            ->asArray(true)
            ->all();
        return $list;
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'number'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'Order ID',
            'name' => 'Spider Order ID',
        ];
    }

    /**
     * Function Description:插入主订单
     * Function Name: insertOrder
     *
     * @return bool
     *
     * @author 娄梦宁
     */
    public function insertOrder(){
        $values=[
            'name'=>'3333',
        ];
        $transaction=Yii::$app->db->beginTransaction();
        try{
            $this->attributes=$values;
            $res=$this->insert(true);
            if(!$res){
                throw new Exception('添加出错');
            }
            $transaction->commit();
            return true;
        }catch (Exception $e){
            $transaction->rollBack();
            return false;
        }
    }
}

