|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace app\admin\logic;
|
|
|
|
|
|
+use app\model\AccountBatchLogModel;
|
|
|
use app\model\AccountModel;
|
|
|
use app\model\CommonModel;
|
|
|
use think\Exception;
|
|
@@ -38,9 +39,11 @@ class AccountLogic extends BaseLogic
|
|
|
//添加
|
|
|
public static function add(array $data = []): Json
|
|
|
{
|
|
|
+ $username_prefix = env('account_username_prefix');
|
|
|
+
|
|
|
$rs = AccountModel::field('id,username')
|
|
|
->where('is_del', CommonModel::$del_normal)
|
|
|
- ->where('username', $data['username'])
|
|
|
+ ->where('username', $username_prefix.$data['username'])
|
|
|
->findOrEmpty()
|
|
|
->isEmpty();
|
|
|
if (!$rs) return json_show(CommonModel::$error_param, '该账号已存在');
|
|
@@ -50,7 +53,7 @@ class AccountLogic extends BaseLogic
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
|
|
$res = AccountModel::create([
|
|
|
- 'username' => Config::get('common.account_username_prefix') . $data['username'],
|
|
|
+ 'username' => $username_prefix . $data['username'],
|
|
|
'pwd' => $pwd,
|
|
|
'salt' => $salt,
|
|
|
'password' => getPassword($pwd, $salt),
|
|
@@ -108,52 +111,13 @@ class AccountLogic extends BaseLogic
|
|
|
//批量添加账户
|
|
|
public static function batchAdd(array $data = []): Json
|
|
|
{
|
|
|
- Db::startTrans();
|
|
|
-
|
|
|
- try {
|
|
|
-
|
|
|
- $rs = AccountModel::field('id,username')
|
|
|
- ->where('is_del', CommonModel::$del_normal)
|
|
|
- ->whereLike('username', $data['username_prefix'] . $data['username_year'] . '____')
|
|
|
- ->findOrEmpty();
|
|
|
- if (!$rs->isEmpty()) throw new Exception($rs->username . '账号已存在');
|
|
|
-
|
|
|
- $date = date('Y-m-d H:i:s');
|
|
|
-
|
|
|
- for ($i = 0; $i <= 9999; $i++) {
|
|
|
- $pwd = randomkeys(6);
|
|
|
- $salt = randomkeys(4);
|
|
|
- Db::name('account')->insert([
|
|
|
- 'username' => Config::get('common.account_username_prefix') . $data['username_prefix'] . $data['username_year'] . str_pad($i, 4, '0', STR_PAD_LEFT),
|
|
|
- 'pwd' => $pwd,
|
|
|
- 'salt' => $salt,
|
|
|
- 'password' => getPassword($pwd, $salt),
|
|
|
- 'company_id' => $data['company_id'],
|
|
|
- 'card_id' => $data['card_id'],
|
|
|
- 'status' => AccountModel::$status_not_active,
|
|
|
- 'is_del' => CommonModel::$del_normal,
|
|
|
- 'starttime' => $data['starttime'],
|
|
|
- 'expiretime' => date('Y-m-d', strtotime($data['expiretime']) + 3600 * 24),
|
|
|
- 'createrid' => self::$uid,
|
|
|
- 'creater' => self::$uname,
|
|
|
- 'addtime' => $date,
|
|
|
- 'updaterid' => self::$uid,
|
|
|
- 'updater' => self::$uname,
|
|
|
- 'updatetime' => $date,
|
|
|
- ]);//比insertAll方法快2/3
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- Db::name('account_batch_log')->insert(array_merge($data, ['addtime' => date('Y-m-d H:i:s')]));
|
|
|
-
|
|
|
- Db::commit();
|
|
|
-
|
|
|
- return json_show(CommonModel::$success, '10000个账户批量添加成功');
|
|
|
-
|
|
|
- } catch (Exception $exception) {
|
|
|
- Db::rollback();
|
|
|
- return json_show(CommonModel::$error_param, '批量添加账户失败,' . $exception->getMessage());
|
|
|
- }
|
|
|
+ $rs = AccountBatchLogModel::create(array_merge($data,[
|
|
|
+ 'status'=>AccountBatchLogModel::$status_wait_handle,
|
|
|
+ 'addtime'=>date('Y-m-d H:i:s'),
|
|
|
+ ]))->save();
|
|
|
+
|
|
|
+ return $rs?json_show(CommonModel::$success,'批量添加账户成功'):json_show(CommonModel::$error_param,'批量添加账户失败');
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//删除
|
|
@@ -185,7 +149,7 @@ class AccountLogic extends BaseLogic
|
|
|
->leftJoin('company b', 'b.id=a.company_id AND b.is_del=' . CommonModel::$del_normal)
|
|
|
->leftJoin('card c', 'c.id=a.card_id AND c.is_del=' . CommonModel::$del_normal)
|
|
|
->where($where)
|
|
|
- ->field('a.id,b.title company_title,c.title card_title,a.username_prefix,a.username_year,a.starttime,a.expiretime,a.addtime')
|
|
|
+ ->field('a.id,b.title company_title,c.title card_title,a.username_prefix,a.username_year,a.starttime,a.expiretime,a.status,a.reason,a.addtime')
|
|
|
->order('a.id', 'desc')
|
|
|
->page($data['page'], $data['size'])
|
|
|
->select()
|