-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGCodeController.php
38 lines (34 loc) · 1.03 KB
/
GCodeController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* author : forecho <caizhenghai@gmail.com>
* createTime : 2016/4/27 16:46
* description:
*/
namespace yiier\inviteCode;
use yii\db\Exception;
use yiier\inviteCode\models\InviteCode;
use Yii;
class GCodeController extends \yii\console\Controller
{
public function actionIndex($num = 100, $userId = 0)
{
$rows = [];
$time = time();
foreach (range(1, $num) as $value) {
$rows[$value]['code'] = Yii::$app->security->generateRandomString();
$rows[$value]['user_id'] = $userId;
$rows[$value]['created_at'] = $time;
$rows[$value]['updated_at'] = $time;
}
if (!($count = static::saveAll(InviteCode::tableName(), $rows))) {
throw new Exception(33007);
}
$this->stdout($count . "\n");
}
public static function saveAll($tableName, $rows = [])
{
return Yii::$app->db->createCommand()
->batchInsert($tableName, array_keys(array_values($rows)[0]), $rows)
->execute();
}
}