/** * function ::create ($data) */ public static function create($data) { // $now = strtotime('now'); // $username = Yii::$app->user->identity->username; $model = new PurchaseOrder(); if ($model->load($data)) { do { $model->transaction_id = rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . date('y'); } while (static::findOne(['transaction_id' => $model->transaction_id])); $model->language_id = Yii::$app->session->get('language_id'); $model->customer_id = isset(Yii::$app->user->identity) ? Yii::$app->user->identity->id : null; $model->status = static::STATUS_NEW; if ($model->save()) { return $model; } $model->getErrors(); return $model; } return false; }