添加合同列表
This commit is contained in:
parent
93ffafe0e5
commit
05cbc4e9f7
@ -23,6 +23,9 @@ use app\common\model\auth\AdminJobs;
|
|||||||
use app\common\model\auth\AdminRole;
|
use app\common\model\auth\AdminRole;
|
||||||
use app\common\model\auth\AdminSession;
|
use app\common\model\auth\AdminSession;
|
||||||
use app\common\cache\AdminTokenCache;
|
use app\common\cache\AdminTokenCache;
|
||||||
|
use app\common\model\contract\Contract;
|
||||||
|
use app\common\model\user\User;
|
||||||
|
use app\common\service\ConfigService;
|
||||||
use app\common\service\FileService;
|
use app\common\service\FileService;
|
||||||
use think\facade\Config;
|
use think\facade\Config;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
@ -54,25 +57,14 @@ class AdminLogic extends BaseLogic
|
|||||||
$params['password'] = $password;
|
$params['password'] = $password;
|
||||||
$params['create_time'] = time();
|
$params['create_time'] = time();
|
||||||
$admin_id = Admin::strict(false)->field(true)->insertGetId($params);
|
$admin_id = Admin::strict(false)->field(true)->insertGetId($params);
|
||||||
$datas=[
|
|
||||||
'company_id'=>$admin_id,
|
|
||||||
'contract_type'=>$params['contract_type'],
|
|
||||||
'contract_no'=>time(),
|
|
||||||
'file'=>$params['file'],
|
|
||||||
'create_time'=>time(),
|
|
||||||
'update_time'=>time(),
|
|
||||||
'party_a'=>$params['party_a'],
|
|
||||||
'party_b'=>$admin_id,
|
|
||||||
'type'=>2
|
|
||||||
];
|
|
||||||
Db::name('contract')->insert($datas);
|
|
||||||
// 角色
|
// 角色
|
||||||
self::insertRole($admin_id, explode(',',$params['role_id']) ?? []);
|
self::insertRole($admin_id, explode(',',$params['role_id']) ?? []);
|
||||||
// 部门
|
// 部门
|
||||||
// self::insertDept($admin_id, $params['dept_id'] ?? []);
|
// self::insertDept($admin_id, $params['dept_id'] ?? []);
|
||||||
// 岗位
|
// 岗位
|
||||||
// self::insertJobs($admin_id, $params['jobs_id'] ?? []);
|
// self::insertJobs($admin_id, $params['jobs_id'] ?? []);
|
||||||
|
self::createUser($params['account'], $password, $admin_id);
|
||||||
|
self::contract($admin_id, $params);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -135,6 +127,7 @@ class AdminLogic extends BaseLogic
|
|||||||
AdminJobs::delByUserId($params['id']);
|
AdminJobs::delByUserId($params['id']);
|
||||||
// 角色
|
// 角色
|
||||||
self::insertRole($params['id'], explode(',',$params['role_id']) ?? []);
|
self::insertRole($params['id'], explode(',',$params['role_id']) ?? []);
|
||||||
|
self::contract($params['id'], $params);
|
||||||
// 部门
|
// 部门
|
||||||
// self::insertDept($params['id'], $params['dept_id'] ?? []);
|
// self::insertDept($params['id'], $params['dept_id'] ?? []);
|
||||||
// // 岗位
|
// // 岗位
|
||||||
@ -340,4 +333,38 @@ class AdminLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function createUser($account, $password, $adminId)
|
||||||
|
{
|
||||||
|
$userSn = User::createUserSn();
|
||||||
|
$avatar = ConfigService::get('default_image', 'user_avatar');
|
||||||
|
User::create([
|
||||||
|
'sn' => $userSn,
|
||||||
|
'avatar' => $avatar,
|
||||||
|
'nickname' => '用户' . $userSn,
|
||||||
|
'account' => $account,
|
||||||
|
'password' => $password,
|
||||||
|
'channel' => 3,
|
||||||
|
'admin_id' => $adminId,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function contract($adminId, $data)
|
||||||
|
{
|
||||||
|
if (!empty($data['file'])) {
|
||||||
|
$admin = Admin::find($adminId);
|
||||||
|
$where = empty($admin['company_id']) ? ['admin_id' => $adminId] : ['company_id' => $admin['company_id']];
|
||||||
|
$model = Contract::where($where)->find();
|
||||||
|
if (empty($model)) {
|
||||||
|
$model = new Contract();
|
||||||
|
$model->admin_id = $admin['id'];
|
||||||
|
$model->company_id = $admin['company_id'];
|
||||||
|
$model->contract_no = time();
|
||||||
|
$model->create_time = time();
|
||||||
|
$model->update_time = time();
|
||||||
|
$model->type = 2;
|
||||||
|
}
|
||||||
|
$model->save($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
31
app/api/controller/ContractController.php
Normal file
31
app/api/controller/ContractController.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\controller;
|
||||||
|
|
||||||
|
use app\common\model\auth\Admin;
|
||||||
|
use app\common\model\contract\Contract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索
|
||||||
|
* Class ContractController
|
||||||
|
* @package app\api\controller
|
||||||
|
*/
|
||||||
|
class ContractController extends BaseApiController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$page = $this->request->get('page', 1);
|
||||||
|
$limit = $this->request->get('limit', 15);
|
||||||
|
$admin = Admin::where('id', $this->userInfo['admin_id'])->find();
|
||||||
|
if (empty($admin)) {
|
||||||
|
return $this->success();
|
||||||
|
}
|
||||||
|
$where = empty($admin['company_id']) ? ['admin_id' => $admin['id']] : ['company_id' => $admin['company_id']];
|
||||||
|
$query = Contract::where($where);
|
||||||
|
$count = $query->count();
|
||||||
|
$contract = $query->page($page)->limit($limit)->select();
|
||||||
|
return $this->success('success', ['count' => $count, 'data' => $contract], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
app/common/cache/AdminTokenCache.php
vendored
1
app/common/cache/AdminTokenCache.php
vendored
@ -97,6 +97,7 @@ class AdminTokenCache extends BaseCache
|
|||||||
'token' => $token,
|
'token' => $token,
|
||||||
'terminal' => $adminSession->terminal,
|
'terminal' => $adminSession->terminal,
|
||||||
'expire_time' => $adminSession->expire_time,
|
'expire_time' => $adminSession->expire_time,
|
||||||
|
'company_id' => $admin->company_id,
|
||||||
];
|
];
|
||||||
$this->set($this->prefix . $token, $adminInfo, new \DateTime(Date('Y-m-d H:i:s', $adminSession->expire_time)));
|
$this->set($this->prefix . $token, $adminInfo, new \DateTime(Date('Y-m-d H:i:s', $adminSession->expire_time)));
|
||||||
return $this->getAdminInfo($token);
|
return $this->getAdminInfo($token);
|
||||||
|
1
app/common/cache/UserTokenCache.php
vendored
1
app/common/cache/UserTokenCache.php
vendored
@ -81,6 +81,7 @@ class UserTokenCache extends BaseCache
|
|||||||
'avatar' => $user->avatar,
|
'avatar' => $user->avatar,
|
||||||
'terminal' => $userSession->terminal,
|
'terminal' => $userSession->terminal,
|
||||||
'expire_time' => $userSession->expire_time,
|
'expire_time' => $userSession->expire_time,
|
||||||
|
'admin_id' => $user->admin_id,
|
||||||
];
|
];
|
||||||
|
|
||||||
$ttl = new \DateTime(Date('Y-m-d H:i:s', $userSession->expire_time));
|
$ttl = new \DateTime(Date('Y-m-d H:i:s', $userSession->expire_time));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user