123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896 |
- <?php
- namespace app\admin\controller\borrow;
- use app\admin\model\Borrow as BorrowModel;
- use app\admin\model\BorrowAccess;
- use app\admin\model\BorrowNumber;
- use app\common\controller\Backend;
- 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;
- class BorrowApp extends Backend
- {
- protected array|string $quickSearchField = ['username', 'mobile'];
- public function initialize(): void
- {
- parent::initialize();
- $this->model = new BorrowModel;
- $this->BorrowAccess = new BorrowAccess();
- $this->BorrowNumber = new BorrowNumber();
- $this->adminModel = $this->auth->getAdmin();
- $this->BorrowTools = new BorrowTools($this->app);
- }
- public function apply(): void
- {
- if ($this->request->param('select')) {
- $this->select();
- }
- $type = $this->request->get()['type'];
- $user_id = $this->auth->id;
- $user_group_id = Db::name('admin_group_access')->where('uid', $user_id)->value("group_id");
- list($where, $alias, $limit, $order) = $this->queryBuilder();
- if($type == 1){
- if ($user_group_id == 1 || $user_group_id == 2) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where(function($query) {
- $query->where([
- ["status", "in", [0,2,6]]
- ]);
- })
- ->order($order)
- ->paginate($limit);
- } else if ($user_group_id == 3) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where(function($query) {
- $query->where([
- ["status", "=", 6],
- ['purpose', '=', 0]
- ]);
- })
- ->whereOr(function($query) {
- $query->where([
- ["status", "=", 3],
- ['purpose', '=', 0],
- ['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) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where(function($query) {
- $query->where([
- ["status", "in", [0,2,6]],
- ['user_id', '=', $this->auth->id]
- ]);
- })
- ->order($order)
- ->paginate($limit);
- }
- }else if($type == 2){
- if ($user_group_id == 1 || $user_group_id == 2) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where(function($query) {
- $query->where([
- ["status", "in", [3,5]]
- ]);
- })
- ->order($order)
- ->paginate($limit);
- } else if ($user_group_id == 3) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where(function($query) {
- $query->where([
- ["status", "in", [3,5]],
- ['purpose', '=', 0],
- ['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) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where(function($query) {
- $query->where([
- ["status", "in", [3,5]],
- ['user_id', '=', $this->auth->id]
- ]);
- })
- ->order($order)
- ->paginate($limit);
- }
- }else if($type == 3){
- if ($user_group_id == 1 || $user_group_id == 2) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where(function($query) {
- $query->where([
- ["status", "in", [1,4,7,8]]
- ]);
- })
- ->order($order)
- ->paginate($limit);
- } else if ($user_group_id == 3) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where(function($query) {
- $query->where([
- ["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) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where(function($query) {
- $query->where([
- ["status", "in", [1,4,7,8]],
- ['user_id', '=', $this->auth->id]
- ]);
- })
- ->order($order)
- ->paginate($limit);
- }
- }
- $this->success('', [
- 'list' => $res,
- 'remark' => get_route_remark(),
- ]);
- }
- public function Useinng(): void
- {
- if ($this->request->param('select')) {
- $this->select();
- }
- $user_id = $this->auth->id;
- $user_group_id = Db::name('admin_group_access')->where('uid', $user_id)->value("group_id");
- list($where, $alias, $limit, $order) = $this->queryBuilder();
- if ($user_group_id == 1 || $user_group_id == 2) {
- $res = $this->model
- ->where($where)
- ->where("status", 'in', [3, 5])
- ->order($order)
- ->paginate($limit);
- } else if ($user_group_id == 3) {
- $res = $this->model
- ->where($where)
- ->where("status", 'in', [3, 5])
- ->where('college_leader_id', $user_id)
- ->order($order)
- ->paginate($limit);
- } else if ($user_group_id == 4) {
- $res = $this->model
- ->where($where)
- ->where("status", 'in', [3, 5])
- ->where('user_id', $user_id)
- ->order($order)
- ->paginate($limit);
- }
- $this->success('', [
- 'list' => $res->items(),
- 'total' => $res->total(),
- 'remark' => get_route_remark(),
- ]);
- }
- public function toEnd(): void
- {
- if ($this->request->param('select')) {
- $this->select();
- }
- $user_id = $this->auth->id;
- $user_group_id = Db::name('admin_group_access')->where('uid', $user_id)->value("group_id");
- list($where, $alias, $limit, $order) = $this->queryBuilder();
- if ($user_group_id == 1 || $user_group_id == 2) {
- $res = $this->model
- ->where($where)
- ->where("status", 'in', [1, 4])
- ->order($order)
- ->paginate($limit);
- } else if ($user_group_id == 3) {
- $res = $this->model
- ->where($where)
- ->where("status", 'in', [1, 4])
- ->where('college_leader_id', $user_id)
- ->order($order)
- ->paginate($limit);
- } else if ($user_group_id == 4) {
- $res = $this->model
- ->where($where)
- ->where("status", 'in', [1, 4])
- ->where('user_id', $user_id)
- ->order($order)
- ->paginate($limit);
- }
- $this->success('', [
- 'list' => $res->items(),
- 'total' => $res->total(),
- 'remark' => get_route_remark(),
- ]);
- }
- public function consoleInformation(): void
- {
- $user_id = $this->auth->id;
- $user_group_id = Db::name('admin_group_access')->where('uid', $user_id)->value("group_id");
- $res = [
- 'damage_num' => Db::name('asset')->where("status", 2)->count(),
- 'asset_count' => Db::name('asset')->count(),
- 'asset_lent' => Db::name('asset')->where('status', 1)->count(),
- 'asset_value' => Db::name('asset')->sum('unit_price'),
- 'damage_people' => Db::name('asset')->where("status", 2)->count(),
- 'damage_nature' => Db::name('asset')->where("status", 2)->count(),
- 'apply' => $this->model->where("status", 0)->count(),
- 'useing' => $this->model->where("status", 2)->count(),
- 'overdue' => $this->model->where("status", 5)->count(),
- ];
- $this->success('', $res);
- }
- public function edit($id = null): void
- {
- if ($this->request->isPost()) {
- $data = $this->request->post()['data'];
- $this->BorrowTools->checkRules($data);
- $data = $this->BorrowTools->checkText($data);
- //获取用户类型
- $user_id = $this->auth->id;
- $user_group_id = Db::name('admin_group_access')->where('uid', $user_id)->value("group_id");
- if ($data['status'] == 1 ) {
- if(!isset($data['annotation'])){
- $this->error("驳回时请填写批注!");
- }
- }
- if ( $data['status'] == 7 ) {
- if(!isset($data['college_annotation'])){
- $this->error("驳回时请填写批注!");
- }
- }
- if (!(array_key_exists('status', $data) && $data['status'] !== null && $data['status'] !== '')) {
- $this->error("请检查仪器状态");
- }
- $data = $this->excludeFields($data);
- $this->model->startTrans();
- $result = false;
- //判断是否是科研类借取并判断是否需要领导审核
- try {
- // 调整仪器的变化
- $this->BorrowTools->checkAsset($data);
- $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'] = '科研借单';
- if ($user_group_id !== 3) {
- $data['approval_person'] = $this->auth->nickname;
- $data['approval_person_id'] = $this->auth->id;
- if ($data['status'] == 6) {
- $text['data']['const4'] = ['审批通过'];
- $data['status'] = 6;
- } else if ($data['status'] == 1) {
- $text['data']['const4'] = ['已驳回'];
- $data['status'] = 1;
- }
- 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') {
- $text['data']['const4'] = ['已驳回'];
- $data['status'] = 7;
- } else {
- $text['data']['const4'] = ['审批通过'];
- }
- $result = false;
- $this->model->startTrans();
- try {
- $result = $this->model->update($data);
- if ($data['status'] == 2 && array_key_exists('asset', $data)) {
- // $num = count($data['asset']);
- foreach ($data['asset'] as $v) {
- for ($i = 0; $i < $v['num']; $i++) {
- $this->BorrowAccess->insert(
- [
- 'asset_name' => $v['model'],
- 'origin' => $v['origin'],
- 'borrow_id' => $data['id'],
- 'status' => -1,
- ]
- );
- }
- }
- }
- $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'] = ['教学借单'];
- if ($data['status'] == 2) {
- $text['data']['const4'] = ['审批通过'];
- } else if ($data['status'] == 1) {
- $text['data']['const4'] = ['已驳回'];
- }
- $result = $this->model->update($data);
- if ($data['status'] == 2 && array_key_exists('asset', $data)) {
- foreach ($data['asset'] as $v) {
- for ($i = 0; $i < $v['num']; $i++) {
- $this->BorrowAccess->insert(
- [
- 'asset_name' => $v['model'],
- 'origin' => $v['origin'],
- 'borrow_id' => $data['id'],
- 'status' => -1,
- ]
- );
- }
- }
- }
- }
- // 提交事务
- $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'));
- }
- }
- $row = $this->model->find($id);
- if (!$row) {
- $this->error(__('Record not found'));
- }
- if ($row['status'] == 0 || $row['status'] == 1 || $row['status'] == 6) {
- $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 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;
- $data['annotation'] = '';
- $data['college_annotation'] = '';
- }
- //判断是否是科研类借取并判断是否需要领导审核
- 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()) {
- $data = $this->request->post()['data'];
- $this->BorrowTools->checkRules($data);
- $data = $this->BorrowTools->checkText($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);
- //校验数据
- $uniID = new SnowflakeId;
- $data['user_id'] = $this->auth->id;
- $this->model->startTrans();
- //尝试存储
- try {
- $data['status'] = 0;
- $data['encoding'] = $uniID->generateParticle();
- if ($open_idArr !== [] && $open_idArr !== null) {
- $text = [
- "pagepath" => "pages/login/index",
- "data" => [
- 'character_string7' => $this->model->id,
- 'thing4' => $data['username']
- ]
- ];
- }
- if ($data['purpose'] == 0) {
- $text['data']['const6'] = ['科研借单'];
- $data['college_leader'] = Db::name('admin')->where('switch',1)->value('nickname');
- } else {
- $text['data']['const6'] = ['教学借单'];
- }
- $result = $this->model->save($data);
- $data['accessories']['borrow_id'] = $this->model->id;
- Db::name('accessories')->insert($data['accessories']);
- $groupAccess = [];
- foreach ($data['asset'] as $datum) {
- if ($datum['model'] !== '') {
- $groupAccess[] = [
- 'borrow_id' => $this->model->id,
- 'asset_name' => $datum['model'],
- 'origin' => $datum['origin'],
- 'num' => $datum['num']
- ];
- }
- }
- // halt($result);
- $this->BorrowNumber->saveAll($groupAccess);
- $this->model->commit();
- } catch (Throwable $e) {
- // 回滚事务
- $this->model->rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- if ($open_idArr !== [] && $open_idArr !== null) {
- 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 (isset($res)) {
- $this->success(__('Update successful'));
- } else {
- $this->success("更新成功,但消息发送失败,请检查网络或联系管理员");
- }
- }else{
- // halt(2);
- $this->success('更新成功!但对方未配置公众号,消息提示失败!');
- }
- } else {
- // halt(3);
- $this->error(__('No rows were added'));
- }
- }
- else {
- $res = $this->model->where('user_id',$this->auth->id)->find();
- $this->success('',$res);
- }
- }
- public function editPassword(): void
- {
- if ($this->request->isPost()) {
- $data = $this->request->param()['data'];
- if (!$data) {
- $this->error(__('Parameter %s can not be empty', ['']));
- }
- $result = $this->adminModel->resetPassword($this->auth->id, $data['_value']);
- if ($result !== false) {
- $this->success(__('Update successful'));
- } else {
- $this->error(__('No rows updated'));
- }
- }
- }
- /**
- * 仪器预约待审核通知
- * @param
- * @return void
- * @throws \Exception
- */
- public function wxAuditMessage($res = null): bool
- {
- $openid = $res["open_id"];
- $template_id = 'xsYnur6koCvgu1nUQwHmu8DX5SoL06P_nYMyK_oThGU';
- $data = [
- 'character_string7' => ['value' => $res["data"]["character_string7"]],
- 'thing4' => ['value' => $res["data"]["thing4"]],
- 'const6' => ['value' => $res["data"]["const6"]],
- 'time9' => ['value' => date('Y-m-d H:i')],
- ];
- $url = 'http://weixin.qq.com/download';
- $miniprogram = [
- 'appid' => 'wx58633590ab59b7a1',
- 'pagepath' => ''
- ];
- $result = OaService::getInstance()->sendTemplateMessage($openid, $template_id, $data, $url, $miniprogram);
- return $result;
- }
- public function getProtocol(){
- $data = Db::name('protocol')->where("switch",1)->value('editor');
- if($data){
- $this->success('', [
- 'data' => $data,
- 'data1' => htmlspecialchars_decode($data)
- ]);
- }else{
- $this->error("失败!");
- }
- }
- /**
- * 仪器预约审核结果通知
- * @param
- * @return void
- * @throws \Exception
- */
- public function wxResultMessage($res): bool
- {
- $openid = $res["openid"];
- // halt($res);
- $template_id = 'Fxd6WNSNPbxEzQ35mDCcjzJBZClv1F9L7jWCcZmAlRI';
- $data = [
- 'character_string1' => ['value' => $res["data"]["character_string1"]],
- 'const3' => ['value' => [$res["data"]["const3"]]],
- 'const4' => ['value' => $res["data"]["const4"]],
- 'thing5' => ['value' => $res["data"]["thing5"]],
- // 'time9' => ['value' => date('Y-m-d H:i')],
- ];
- $url = 'http://weixin.qq.com/download';
- $miniprogram = [
- 'appid' => 'wx58633590ab59b7a1',
- 'pagepath' => "pages/login/index"
- ];
- $result = OaService::getInstance()->sendTemplateMessage($openid, $template_id, $data, $url, $miniprogram);
- return $result;
- }
- // public function (): void
- // {
- // if ($this->request->param('select')) {
- // $this->select();
- // }
- // $user_id = $this->auth->id;
- // $user_group_id = Db::name('admin_group_access')->where('uid',$user_id)->value("group_id");
- // $res = [
- // 'damage_num' => Db::name('asset')->where("status",2)->count(),
- // 'damage_people' => Db::name('asset')->where("status",2)->where("damage_type",1)->count(),
- // 'damage_nature'=> Db::name('asset')->where("status",2)->where("damage_type",0)->count(),
- // 'apply'=> $this->model->where("status",0)->count(),
- // 'useing'=> $this->model->where("status",2)->count(),
- // 'overdue'=> $this->model->where("status",5)->count(),
- // ];
- // $this->success('', $res);
- // }
- }
|