|
@@ -10,6 +10,7 @@ use ba\Random;
|
|
|
use modules\notification\Notification;
|
|
|
use think\facade\Db;
|
|
|
use app\common\controller\SnowflakeId;
|
|
|
+use think\migration\command\migrate\Status;
|
|
|
use Throwable;
|
|
|
use app\admin\controller\borrow\BorrowTools;
|
|
|
use app\common\library\xmwechat\offiaccount\OaService;
|
|
@@ -70,6 +71,12 @@ class BorrowApp extends Backend
|
|
|
['college_leader_id', '=', $this->auth->id]
|
|
|
]);
|
|
|
})
|
|
|
+ ->whereOr(function($query) {
|
|
|
+ $query->where([
|
|
|
+ ["status", "in", [0,2,6]],
|
|
|
+ ['user_id', '=', $this->auth->id]
|
|
|
+ ]);
|
|
|
+ })
|
|
|
->order($order)
|
|
|
->paginate($limit);
|
|
|
} else if ($user_group_id == 4) {
|
|
@@ -78,8 +85,8 @@ class BorrowApp extends Backend
|
|
|
->where($where)
|
|
|
->where(function($query) {
|
|
|
$query->where([
|
|
|
- ["status", "=", [0,2,6]],
|
|
|
- ['user_id', '=', $user_id]
|
|
|
+ ["status", "in", [0,2,6]],
|
|
|
+ ['user_id', '=', $this->auth->id]
|
|
|
]);
|
|
|
})
|
|
|
->order($order)
|
|
@@ -108,6 +115,12 @@ class BorrowApp extends Backend
|
|
|
['college_leader_id', '=', $this->auth->id]
|
|
|
]);
|
|
|
})
|
|
|
+ ->whereOr(function($query) {
|
|
|
+ $query->where([
|
|
|
+ ["status", "in", [3,5]],
|
|
|
+ ['user_id', '=', $this->auth->id]
|
|
|
+ ]);
|
|
|
+ })
|
|
|
->order($order)
|
|
|
->paginate($limit);
|
|
|
} else if ($user_group_id == 4) {
|
|
@@ -116,8 +129,8 @@ class BorrowApp extends Backend
|
|
|
->where($where)
|
|
|
->where(function($query) {
|
|
|
$query->where([
|
|
|
- ["status", "=", [3,5]],
|
|
|
- ['user_id', '=', $user_id]
|
|
|
+ ["status", "in", [3,5]],
|
|
|
+ ['user_id', '=', $this->auth->id]
|
|
|
]);
|
|
|
})
|
|
|
->order($order)
|
|
@@ -130,7 +143,7 @@ class BorrowApp extends Backend
|
|
|
->where($where)
|
|
|
->where(function($query) {
|
|
|
$query->where([
|
|
|
- ["status", "in", [1,4,7]]
|
|
|
+ ["status", "in", [1,4,7,8]]
|
|
|
]);
|
|
|
})
|
|
|
->order($order)
|
|
@@ -141,11 +154,17 @@ class BorrowApp extends Backend
|
|
|
->where($where)
|
|
|
->where(function($query) {
|
|
|
$query->where([
|
|
|
- ["status", "in", [1,4,7]],
|
|
|
+ ["status", "in", [1,4,7,8]],
|
|
|
['purpose', '=', 0],
|
|
|
['college_leader_id', '=', $this->auth->id]
|
|
|
]);
|
|
|
})
|
|
|
+ ->whereOr(function($query) {
|
|
|
+ $query->where([
|
|
|
+ ["status", "in", [1,4,7,8]],
|
|
|
+ ['user_id', '=', $this->auth->id]
|
|
|
+ ]);
|
|
|
+ })
|
|
|
->order($order)
|
|
|
->paginate($limit);
|
|
|
} else if ($user_group_id == 4) {
|
|
@@ -154,8 +173,8 @@ class BorrowApp extends Backend
|
|
|
->where($where)
|
|
|
->where(function($query) {
|
|
|
$query->where([
|
|
|
- ["status", "=", [1,4,7]],
|
|
|
- ['user_id', '=', $user_id]
|
|
|
+ ["status", "in", [1,4,7,8]],
|
|
|
+ ['user_id', '=', $this->auth->id]
|
|
|
]);
|
|
|
})
|
|
|
->order($order)
|
|
@@ -443,6 +462,225 @@ class BorrowApp extends Backend
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function editAccessories($id = null): void
|
|
|
+ {
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $data = $this->request->post()['data'];
|
|
|
+ //获取用户类型
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+ $this->model->startTrans();
|
|
|
+ $result = false;
|
|
|
+ //判断是否是科研类借取并判断是否需要领导审核
|
|
|
+ try {
|
|
|
+ $open_id = Db::name('oauth_log')->where('user_id',$user_id)->value('opid');
|
|
|
+ if ($open_id !== null) {
|
|
|
+ $text = [
|
|
|
+ "openid" => $open_id,
|
|
|
+ "pagepath" => "pages/login/index",
|
|
|
+ "data" => [
|
|
|
+ 'character_string1' => $data['id'],
|
|
|
+ 'thing5' => $this->auth->nickname,
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ //判断是否是科研类借取并判断是否需要领导审核
|
|
|
+ if ($data['purpose'] == 0) {
|
|
|
+ $text['data']['const3'] = '科研借单';
|
|
|
+ $text['data']['const4'] = ['需要修改配件数量'];
|
|
|
+ $data['status'] = 8;
|
|
|
+ try {
|
|
|
+ $result = $this->model->update($data);
|
|
|
+ $this->model->commit();
|
|
|
+ } catch (Throwable $e) {
|
|
|
+ $this->model->rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $data['approval_person'] = $this->auth->nickname;
|
|
|
+ $data['approval_person_id'] = $this->auth->id;
|
|
|
+ $text['data']['const3'] = ['教学借单'];
|
|
|
+ $text['data']['const4'] = ['需要修改配件数量'];
|
|
|
+ $data['status'] = 8;
|
|
|
+ try {
|
|
|
+ $result = $this->model->update($data);
|
|
|
+ $this->model->commit();
|
|
|
+ } catch (Throwable $e) {
|
|
|
+ $this->model->rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提交事务
|
|
|
+ $this->model->commit();
|
|
|
+ } catch (Throwable $e) {
|
|
|
+ // 回滚事务
|
|
|
+ $this->model->rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($result !== false) {
|
|
|
+// $this->success(__('Update successful'));
|
|
|
+ $open_id = Db::name('oauth_log')->where('user_id',$user_id)->value('opid');
|
|
|
+ if ($open_id !== null) {
|
|
|
+ // halt($text);
|
|
|
+ $res = self::wxResultMessage($text);
|
|
|
+
|
|
|
+ if ($res === true) {
|
|
|
+ $this->success(__('Update successful'));
|
|
|
+ } else {
|
|
|
+ $this->success("更新成功,但消息发送失败,请检查网络或联系管理员");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $this->success('更新成功!但对方未配置公众号,消息提示失败!');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->error(__('No rows updated'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function changeAssetNum($id = null): void
|
|
|
+ {
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $data = $this->request->post()['data'];
|
|
|
+ // 调整仪器的变化
|
|
|
+ if($data['status'] != 8){
|
|
|
+ $this->BorrowTools->checkRules($data);
|
|
|
+ $data = $this->BorrowTools->checkText($data);
|
|
|
+ $this->BorrowTools->checkAsset($data);
|
|
|
+
|
|
|
+ $asset_userArr = [];
|
|
|
+ $admin_idArr = [];
|
|
|
+ $open_idArr = [];
|
|
|
+
|
|
|
+ //获取消息推送目标人
|
|
|
+ foreach ($data['asset'] as $k => $v){
|
|
|
+ $asset_user = Db::name('asset')->where('asset_name',$data['asset'][$k]['model'])->value('user');
|
|
|
+ $admin_id = Db::name('admin')->where('nickname',$asset_user)->value('id');
|
|
|
+ $open_id = Db::name('oauth_log')->where('user_id', $admin_id)->value('opid');
|
|
|
+ if(!in_array($asset_user,$asset_userArr)){
|
|
|
+ $asset_userArr[] = $asset_user;
|
|
|
+ }
|
|
|
+ if(!in_array($admin_id,$admin_idArr)){
|
|
|
+ $admin_idArr[] = $admin_id;
|
|
|
+ }
|
|
|
+ if(!in_array($open_id,$open_idArr)){
|
|
|
+ $open_idArr[] = $open_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data['approval_person_id'] = implode(',',$admin_idArr);
|
|
|
+ $data['approval_person'] = implode(',',$asset_userArr);
|
|
|
+
|
|
|
+ if (!empty($open_idArr) && $open_idArr !== null ) {
|
|
|
+ $text = [
|
|
|
+ "pagepath" => "pages/login/index",
|
|
|
+ "data" => [
|
|
|
+ 'character_string7' => $this->model->id,
|
|
|
+ 'thing4' => $data['username'],
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取用户类型
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+ $user_group_id = Db::name('admin_group_access')->where('uid', $user_id)->value("group_id");
|
|
|
+
|
|
|
+ $data = $this->excludeFields($data);
|
|
|
+
|
|
|
+ $this->model->startTrans();
|
|
|
+ $result = false;
|
|
|
+ //判断是否是科研类借取并判断是否需要领导审核
|
|
|
+ try {
|
|
|
+ if($data['status'] == 8){
|
|
|
+ $data['status'] = 2;
|
|
|
+ }else{
|
|
|
+ $data['status'] = 0;
|
|
|
+ }
|
|
|
+ //判断是否是科研类借取并判断是否需要领导审核
|
|
|
+ if ($data['purpose'] == 0) {
|
|
|
+ $text['data']['const6'] = ['科研借单'];
|
|
|
+ $leader = Db::name('admin')->where('switch', 1)->find();
|
|
|
+ $data['college_leader'] = $leader['nickname'];
|
|
|
+ if ($user_group_id !== 3) {
|
|
|
+ try {
|
|
|
+ $result = $this->model->update($data);
|
|
|
+ $this->model->commit();
|
|
|
+ } catch (Throwable $e) {
|
|
|
+ $this->model->rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $data['college_leader_id'] = $user_id;
|
|
|
+ $data['college_leader'] = $this->auth->nickname;
|
|
|
+ if ($data['status'] == '1') {
|
|
|
+ $data['status'] = 7;
|
|
|
+ }
|
|
|
+ $result = false;
|
|
|
+ $this->model->startTrans();
|
|
|
+ try {
|
|
|
+ $result = $this->model->update($data);
|
|
|
+ $this->model->commit();
|
|
|
+ } catch (Throwable $e) {
|
|
|
+ $this->model->rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $text['data']['const6'] = ['教学借单'];
|
|
|
+ $result = $this->model->update($data);
|
|
|
+ }
|
|
|
+ Db::name('accessories')->update($data['accessories']);
|
|
|
+ // 提交事务
|
|
|
+ $this->model->commit();
|
|
|
+ } catch (Throwable $e) {
|
|
|
+ // 回滚事务
|
|
|
+ $this->model->rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($result !== false) {
|
|
|
+ if (!empty($open_idArr) && $open_idArr !== null && $data['status'] != 8) {
|
|
|
+ foreach ($open_idArr as $k => $v){
|
|
|
+ $text['open_id'] = $open_idArr[$k];
|
|
|
+ if ( $open_idArr[$k] !== [] && $open_idArr[$k] !== null) {
|
|
|
+ // halt($text);
|
|
|
+ $res = self::wxAuditMessage($text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($res === true) {
|
|
|
+ $this->success(__('Update successful'));
|
|
|
+ } else {
|
|
|
+ $this->success("更新成功,但消息发送失败,请检查网络或联系管理员");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->success('更新成功!但对方未配置公众号,消息提示失败!');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->error(__('No rows were added'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $row = $this->model->find($id);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('Record not found'));
|
|
|
+ }
|
|
|
+ if ($row['status'] == 0 || $row['status'] == 1 || $row['status'] == 6 || $row['status'] == 7) {
|
|
|
+ $rows = $this->BorrowNumber->field('*,asset_name as model')->where('borrow_id', $id)->select();
|
|
|
+ } else {
|
|
|
+ $rows = $this->BorrowAccess->field('a.*,s.student_name,a.asset_name as model')->alias('a')->leftjoin('student s', 'a.student_id = s.id')->where('borrow_id', $id)->select();
|
|
|
+ }
|
|
|
+ $row['accessories'] = Db::name('accessories')->where('borrow_id', $id)->find();
|
|
|
+ $row['asset'] = $rows;
|
|
|
+ $row['borrowImg'] = Db::name('borrow_img')->where('borrow_id', $id)->select();
|
|
|
+
|
|
|
+ $this->success('', [
|
|
|
+ 'row' => $row
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
public function add(): void
|
|
|
{
|
|
|
if ($this->request->isPost()) {
|