123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736 |
- <?php
- namespace app\admin\controller\borrow;
- use app\admin\controller\borrow\BorrowTools;
- 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 think\facade\Db;
- use app\common\controller\SnowflakeId;
- use Throwable;
- class BorrowUseing 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->BorrowTools = new BorrowTools($this->app);
- }
- public function index(): 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
- ->alias($alias)
- ->where($where)
- ->where("status", 'in', [2, 3, 5])
- ->order($order)
- ->paginate($limit);
- } else if ($user_group_id == 3) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where("status", 'in', [2, 3, 5])
- ->where('college_leader_id', $user_id)
- ->order($order)
- ->paginate($limit);
- } else if ($user_group_id == 4) {
- $res = $this->model
- ->alias($alias)
- ->where($where)
- ->where("status", 'in', [2, 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 add(): void
- {
- if ($this->request->isPost()) {
- $data = $this->request->post();
- if (!$data) {
- $this->error(__('Parameter %s can not be empty', ['']));
- }
- if (array_key_exists('borrow_reason', $data) && $data['borrow_reason'] !== null) {
- $data['borrow_reason'] = html_entity_decode($data['borrow_reason'], ENT_QUOTES, 'UTF-8');
- }
- if (array_key_exists('remarks', $data) && $data['remarks'] !== null) {
- $data['remarks'] = html_entity_decode($data['remarks'], ENT_QUOTES, 'UTF-8');
- }
- $data = $this->excludeFields($data);
- //获取用户类型
- $this->model->startTrans();
- $result = false;
- try {
- $uniID = new SnowflakeId;
- $data['user_id'] = $this->auth->id;
- $data['encoding'] = $uniID->generateParticle();
- $result = $this->model->save($data);
- // 调整仪器
- if (array_key_exists('asset', $data) && !empty($data['asset'])) {
- $toInsert = [];
- foreach ($data['asset'] as $datum) {
- // 数据不存在,准备插入项
- $toInsert[] = [
- 'borrow_id' => $this->model->id,
- 'asset_name' => $datum['model'],
- 'asset_id' => $datum['asset_id'],
- 'origin' => $datum['origin'],
- 'status' => $data['status'],
- 'collection_time' => $datum['collection_time'],
- 'lend_processor' => $datum['lend_processor'],
- 'restitution_processor' => $datum['restitution_processor'],
- 'restitution_time' => $datum['restitution_time'],
- ];
- }
- // 插入新增的数据
- if (!empty($toInsert)) {
- $this->BorrowAccess->insertAll($toInsert);
- }
- }
- if (isset($data['fileList'])) {
- $groupImg = [];
- foreach ($data['fileList'] as $datum) {
- $groupImg[] = [
- 'borrow_id' => $this->model->id,
- 'url' => $datum['sign'],
- ];
- }
- Db::name('borrow_img')->insertAll($groupImg);
- }
- // 提交事务
- $this->model->commit();
- } catch (Throwable $e) {
- // 回滚事务
- $this->model->rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success(__('Update successful'));
- } else {
- $this->error(__('No rows updated'));
- }
- }
- $this->error(__('Parameter error'));
- }
- public function del($ids = null): void
- {
- if (!$this->request->isDelete() || !$ids) {
- $this->error(__('Parameter error'));
- }
- $pk = $this->model->getPk();
- $data = $this->model->where($pk, 'in', $ids)->select();
- $count = 0;
- $count = 0;
- $this->model->startTrans();
- try {
- foreach ($data as $v) {
- $count += $v->delete();
- $this->BorrowAccess->where('borrow_id', 'in', $ids)->select();
- Db::name('borrow_number')->where('borrow_id', $v['id'])->useSoftDelete('delete_time', date('Y-m-d H:i:s', time()))->delete();
- Db::name('borrow_access')->where('borrow_id', $v['id'])->useSoftDelete('delete_time', date('Y-m-d H:i:s', time()))->delete();
- }
- $this->model->commit();
- } catch (Throwable $e) {
- $this->model->rollback();
- $this->error($e->getMessage());
- }
- if ($count) {
- $this->success(__('Deleted successfully'));
- } else {
- $this->error(__('No rows were deleted'));
- }
- }
- public function edit($id = null): void
- {
- $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('*,asset_name as model')->where('borrow_id', $id)->select();
- }
- $row['asset'] = $rows;
- $row['fileList'] = Db::name('borrow_img')->where('borrow_id', $id)->field('*,url as sign')->select();
- $row['accessories'] = Db::name('accessories')->where('borrow_id', $id)->find();
- if ($this->request->isPost()) {
- $data = $this->request->post();
- if (!$data) {
- $this->error(__('Parameter %s can not be empty', ['']));
- }
- if (array_key_exists('borrow_reason', $data) && $data['borrow_reason'] !== null) {
- $data['borrow_reason'] = html_entity_decode($data['borrow_reason'], ENT_QUOTES, 'UTF-8');
- }
- if (array_key_exists('remarks', $data) && $data['remarks'] !== null) {
- $data['remarks'] = html_entity_decode($data['remarks'], ENT_QUOTES, 'UTF-8');
- }
- if (!isset($data['asset']) || $data['asset'] == []) {
- $this->error("仪器选择不能为空!!");
- }
- $data = $this->excludeFields($data);
- //获取用户类型
- $user_id = $this->auth->id;
- $user_group_id = Db::name('admin_group_access')->where('uid', $user_id)->value("group_id");
- $this->model->startTrans();
- $result = false;
- try {
- // 调整仪器的变化
- if (array_key_exists('asset', $data) && !empty($data['asset'])) {
- // 首先检索当前所有相关记录
- $existingRecords = Db::name('borrow_access')
- ->where('borrow_id', $data['id'])
- ->column('*', 'id');
- $toUpdate = [];
- $toInsert = [];
- foreach ($data['asset'] as $datum) {
- if (isset($datum['id'], $existingRecords[$datum['id']])) {
- // 对比现有数据与新数据
- $current = $existingRecords[$datum['id']];
- if ($current['asset_name'] !== $datum['model'] || $current['asset_id'] !== $datum['asset_id']
- || $current['student_id'] !== $datum['student_id'] || $current['origin'] !== $datum['origin']
- || $current['status'] !== $datum['status'] || $current['collection_time'] !== $datum['collection_time']
- || $current['lend_processor'] !== $datum['lend_processor']
- || $current['restitution_processor'] !== $datum['restitution_processor'] || $current['restitution_time'] !== $datum['restitution_time']
- ) {
- // 数据有变化,则准备更新
- $toUpdate[] = [
- 'id' => $datum['id'],
- 'borrow_id' => $data['id'],
- 'asset_name' => $datum['model'],
- 'asset_id' => $datum['asset_id'],
- 'student_id' => $datum['student_id'],
- 'origin' => $datum['origin'],
- 'status' => $data['status'],
- 'collection_time' => $datum['collection_time'],
- 'lend_processor' => $datum['lend_processor'],
- 'restitution_processor' => $datum['restitution_processor'],
- 'restitution_time' => $datum['restitution_time'],
- ];
- }
- // 从现有记录中移除已经处理过的项
- unset($existingRecords[$datum['id']]);
- } else {
- // 数据不存在,准备插入项
- $toInsert[] = [
- 'borrow_id' => $data['id'],
- 'asset_name' => $datum['model'],
- 'asset_id' => $datum['asset_id'],
- 'student_id' => $datum['student_id'],
- 'origin' => $datum['origin'],
- 'status' => $data['status'],
- 'collection_time' => $datum['collection_time'],
- 'lend_processor' => $datum['lend_processor'],
- 'restitution_processor' => $datum['restitution_processor'],
- 'restitution_time' => $datum['restitution_time'],
- ];
- }
- }
- // $existingRecords 中剩下的是需要软删除的
- $toDelete = array_keys($existingRecords);
- if (!empty($toDelete)) {
- Db::name('borrow_number')
- ->where('id', 'in', $toDelete)
- ->useSoftDelete('delete_time', date('Y-m-d H:i:s'))
- ->delete();
- }
- // 更新已变化的数据
- if (!empty($toUpdate)) {
- $this->BorrowNumber->saveAll($toUpdate);
- }
- // 插入新增的数据
- if (!empty($toInsert)) {
- $this->BorrowNumber->insertAll($toInsert);
- }
- }
- if (isset($data['fileList'])) {
- $result = Db::name('borrow_img')->where('borrow_id', $id)->delete();
- if ($result) {
- $groupImg = [];
- foreach ($data['fileList'] as $datum) {
- $groupImg[] = [
- 'borrow_id' => $data['id'],
- 'url' => $datum['sign'],
- ];
- }
- Db::name('borrow_img')->insertAll($groupImg);
- }
- }
- if (array_key_exists('status', $data) && $data['status'] !== null && $data['status'] !== '') {
- if ($data['purpose'] == 0) {
- $this->model->startTrans();
- 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'));
- } else {
- $this->error(__('No rows updated'));
- }
- }
- $this->success('', [
- 'row' => $row
- ]);
- }
- public function scientificBind(): void
- {
- $query = $this->request->param();
- $asset_id = $query['asset_id'];
- $borrow_id = $query['borrow_id'];
- $result = false;
- $is_leadAgree = $this->model->where('id', $borrow_id)->value('college_leader_id');
- if ($is_leadAgree == null) {
- $this->error("请等待学院领导审核");
- }
- $asset_name = Db::name('asset')->where('asset_id', $asset_id)->value('asset_name');
- $data = $this->BorrowTools->getDateForAssetName($asset_id,$asset_name,$borrow_id);
- if ($data !== null) {
- $data = $data->toArray();
- $data['asset_name'] = $asset_name;
- $data['asset_id'] = $asset_id;
- $data['status'] = 0;
- $data['collection_time'] = date('Y-m-d H:i:s', time());
- $data['lend_processor'] = $this->auth->nickname;
- } else {
- $this->error(__('Type of inspection instrument'));
- }
- $this->model->startTrans();
- try {
- //更改仪器状态
- $change = Db::name('asset')->where('asset_id', $asset_id)->data(['status' => 1])->update();
- //更新数据
- $result = $this->BorrowAccess->update($data);
- //判断是否应该更改借单状态
- $is_uesing = $this->BorrowAccess
- ->where(['borrow_id' => $borrow_id])
- ->where('asset_id', null)
- ->find();
- if ($is_uesing == null) {
- $this->model->where('id', $borrow_id)->update(['status' => 3]);
- }
- $this->model->commit();
- } catch (Throwable $e) {
- $this->model->rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success(__('Update successful'));
- } else {
- $this->error(__('No rows updated'));
- }
- }
- public function assetChange(): void
- {
- $query = $this->request->param();
- $old_asset_id = $query['old_asset_id'];
- $new_asset_id = $query['new_asset_id'];
- $borrow_id = $query['borrow_id'];
- $isDamage = $query['isDamage'];
- $assetData = Db::name('borrow_access')
- ->where(['asset_id' => $old_asset_id, 'borrow_id' => $borrow_id, 'status' => 0])
- ->find();
- if ($assetData == null) {
- $this->error("请检查仪器编号!!");
- }
- $isOldAssset = Db::name('asset')->where('asset_id', $new_asset_id)->find();
- if ($isOldAssset == null) {
- $this->error("请检查仪器编号!!");
- }
- if ($isOldAssset['status'] == 1) {
- $this->error("该仪器已借出!!");
- }
-
- $result = false;
- $this->model->startTrans();
- try {
- $asset_name = Db::name('asset')->where('asset_id', $old_asset_id)->value('asset_name');
- $new_asset_name = Db::name('asset')->where('asset_id', $new_asset_id)->value('asset_name');
- if ($isDamage == 1) {
- $back = Db::name('asset')->where('asset_id', $old_asset_id)->data(['status' => 2])->update();
- $thisStatus = 1;
- } else {
- $back = Db::name('asset')->where('asset_id', $old_asset_id)->data(['status' => 0])->update();
- $toUse = Db::name('asset')->where('asset_id', $new_asset_id)->data(['status' => 1])->update();
- $thisStatus = 3;
- }
- $change = Db::name('borrow_access')
- ->where(['borrow_id' => $borrow_id, 'asset_id' => $old_asset_id, 'status' => 0])
- ->data([
- 'status' => $thisStatus,
- 'restitution_processor' => $this->auth->nickname,
- 'restitution_time' => date('Y-m-d H:i:s', time()),
- ])->update();
- if (isset($assetData['student_id'])) {
- $result = $this->BorrowAccess->insert(
- ['borrow_id' => $borrow_id,
- 'asset_name' => $new_asset_name,
- 'student_id' => $assetData['student_id'],
- 'asset_id' => $new_asset_id,
- 'origin' => $assetData['origin'],
- 'collection_time' => date('Y-m-d H:i:s', time()),
- 'lend_processor' => $this->auth->nickname,
- 'status' => 0]
- );
- } else {
- $result = $this->BorrowAccess->insert(
- ['borrow_id' => $borrow_id,
- 'asset_name' => $new_asset_name,
- 'asset_id' => $new_asset_id,
- 'origin' => $assetData['origin'],
- 'collection_time' => date('Y-m-d H:i:s', time()),
- 'lend_processor' => $this->auth->nickname,
- 'status' => 0]
- );
- }
- if (!($change && $result)) {
- $this->error("替换失败!请重试!!");
- }
- $this->model->commit();
- } catch (Throwable $e) {
- $this->model->rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success(__('Update successful'));
- } else {
- $this->error(__('No rows updated'));
- }
- }
- public function assetDamage(): void
- {
- $query = $this->request->param();
- $asset_id = $query['asset_id'];
- $borrow_id = $query['borrow_id'];
- $assetData = Db::name('borrow_access')
- ->where(['asset_id' => $asset_id,'borrow_id' => $borrow_id, 'status' => 0])
- ->find();
- if ($assetData == null) {
- $this->error("请检查仪器编号!!");
- }
- $borrow_id = $assetData['borrow_id'];
- $result = false;
- $this->model->startTrans();
- try {
- $result = Db::name('borrow_access')
- ->where(['borrow_id' => $borrow_id, 'asset_id' => $asset_id, 'status' => 0])
- ->data([
- 'status' => 1,
- 'restitution_processor' => $this->auth->nickname,
- 'restitution_time' => date('Y-m-d H:i:s', time()),
- ])->update();
- $back = Db::name('asset')->where('asset_id', $asset_id)->data(['status' => 2])->update();
- $is_end = $this->BorrowAccess
- ->where(['borrow_id' => $borrow_id])
- ->where('status', "=", '0')
- ->find();
- if ($is_end == null) {
- $this->model->where('id', $borrow_id)->update(['status' => 4]);
- }
- $this->model->commit();
- } catch (Throwable $e) {
- $this->model->rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success(__('Update successful'));
- } else {
- $this->error(__('No rows updated'));
- }
- }
- public function scientificComplete(): void
- {
- $query = $this->request->param();
- if (isset($query['asset_id']) && isset($query['borrow_id'])) {
- $asset_id = $query['asset_id'];
- $borrow_id = $query['borrow_id'];
- } else {
- $this->error('缺少信息,请重试!!');
- }
- $is_r = Db::name('borrow_access')
- ->where(['asset_id' => $asset_id,'borrow_id' => $borrow_id, 'status' => 0])
- ->find();
- if ($is_r == null) {
- $this->error("请检查仪器编号!!");
- }
- $result = false;
- $this->model->startTrans();
- try {
- $result = Db::name('borrow_access')
- ->where(['borrow_id' => $borrow_id, 'asset_id' => $asset_id, 'status' => 0])
- ->data([
- 'status' => 2,
- 'restitution_processor' => $this->auth->nickname,
- 'restitution_time' => date('Y-m-d H:i:s', time())
- ])
- ->update();
- $back = Db::name('asset')->where('asset_id', $asset_id)->data(['status' => 0])->update();
- $is_end = $this->BorrowAccess
- ->where(['borrow_id' => $borrow_id])
- ->where('status', "=", '0')
- ->find();
- // halt($is_end);
- if ($is_end == null) {
- $this->model->where('id', $borrow_id)->update(['status' => 4]);
- }
- $this->model->commit();
- } catch (Throwable $e) {
- $this->model->rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success(__('Update successful'));
- } else {
- $this->error("归还失败!");
- }
- }
- //课程类借取绑定仪器
- public function courseBind(): void
- {
- $query = $this->request->param();
- $result = false;
- if (isset($query['asset_id']) && isset($query['student_phone']) && isset($query['borrow_id'])) {
- $asset_id = $query['asset_id'];
- $student_phone = $query['student_phone'];
- $borrow_id = $query['borrow_id'];
- } else {
- $this->error('缺少信息,请重试!!');
- }
- $student = DB::name('student')->where('student_phone', $student_phone)->find();
- if (!$student) {
- $this->error('该学生未注册!');
- }
- $asset_name = Db::name('asset')->where('asset_id', $asset_id)->value('asset_name');
- $data = $this->BorrowTools->getDateForAssetName($asset_id,$asset_name,$borrow_id);
- $this->model->startTrans();
- try {
- //判断扫描的时是身份码还是仪器码并作出相应操作
- if (array_key_exists('asset_id', $query) && isset($query['asset_id'])) {
- $data->status = 0;
- $data->asset_name = $asset_name;
- $data->asset_id = $asset_id;
- $data->student_id = $student['id'];
- $data->collection_time = date('Y-m-d H:i:s', time());
- $data->lend_processor = $this->auth->nickname;
- $result = $data->save();
- $change = Db::name('asset')->where('asset_id', $asset_id)->data(['status' => 1])->update();
- //检验是否完成绑定并调整借单状态值
- $is_allIn = $this->BorrowAccess
- ->where(['asset_id' => null])
- ->where(['borrow_id' => $borrow_id])
- ->find();
- if ($is_allIn === null) {
- $this->model->where('id', $borrow_id)->update(['status' => '3']);
- }
- }
- $this->model->commit();
- } catch (Throwable $e) {
- $this->model->rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success(__('Update successful'));
- } else {
- $this->error(__('No rows updated'));
- }
- }
- // public function courseBindChange(): void
- // {
- // $query = $this->request->param();
- // $asset_id = $query['asset_id'];
- // $borrow_id = $query['asset_id'];
- // $row = Db::name('borrow_access')
- // ->where(['asset_id' => $asset_id, 'borrow_id' => $borrow_id, 'status' => 0])
- // ->find();
- // if ($row == null) {
- // $this->error("请勿重复扫码!");
- // }
- // $result = false;
- // $this->model->startTrans();
- // try {
- // $assetData = Db::name('asset')->where('asset_id', $asset_id)->find();
- // $change = Db::name('borrow_access')
- // ->where(['borrow_id' => $borrow_id, 'asset_id' => $asset_id, 'status' => 0])
- // ->data(['status' => 1])
- // ->update();
- // $result = $this->BorrowAccess->insert(
- // ['borrow_id' => $borrow_id, 'asset_name' => $assetData['asset_name'], 'origin' => $assetData['origin'], 'status' => -1]
- // );
- // $back = Db::name('asset')->where('asset_id', $asset_id)->data(['status' => 2])->update();
- // if (!($change && $result)) {
- // $this->error("报损失败!请重试!!");
- // }
- // $this->model->commit();
- // } catch (Throwable $e) {
- // $this->model->rollback();
- // $this->error($e->getMessage());
- // }
- // if ($result !== false) {
- // $this->success(__('Update successful'));
- // } else {
- // $this->error(__('No rows updated'));
- // }
- // }
- public function courseComplete(): void
- {
- $query = $this->request->param();
- if (isset($query['asset_id']) && isset($query['borrow_id'])) {
- $asset_id = $query['asset_id'];
- // $student_phone = $query['student_phone'];
- $borrow_id = $query['borrow_id'];
- } else {
- $this->error('缺少信息,请重试!!');
- }
- $row = Db::name('borrow_access')
- ->where(['asset_id' => $asset_id, 'borrow_id' => $borrow_id])
- ->find();
- if ($row == null || $row['status'] !== 0 ) {
- $this->error("请检查仪器编号!!");
- }
- $result = false;
- $this->model->startTrans();
- try {
- $result = Db::name('borrow_access')
- ->where(['borrow_id' => $borrow_id, 'asset_id' => $asset_id, 'status' => 0])
- ->data([
- 'status' => 2,
- 'restitution_processor' => $this->auth->nickname,
- 'restitution_time' => date('Y-m-d H:i:s', time())
- ])->update();
- $back = Db::name('asset')->where('asset_id', $asset_id)->data(['status' => 0])->update();
- $is_end = $this->BorrowAccess
- ->where(['borrow_id' => $borrow_id])
- ->where('status', "=", '0')
- ->find();
- // halt($is_end);
- if ($is_end == null) {
- $this->model->where('id', $borrow_id)->update(['status' => '4']);
- }
- $this->model->commit();
- } catch (Throwable $e) {
- $this->model->rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success(__('Update successful'));
- } else {
- $this->error("归还失败!");
- }
- }
- public function uniUpload(): void
- {
- $data = $this->request->post();
- $borrow_id = $data['borrow_id'];
- $url = $data['url'];
- $res = Db::name('borrow_img')->insert(
- [
- 'borrow_id' => $borrow_id,
- 'url' => $url
- ]
- );
- if ($res) {
- $this->success('上传成功!!');
- } else {
- $this->error('保存失败!!');
- }
- }
- public function delImg(): void
- {
- $data = $this->request->post();
- $borrow_id = $data['borrow_id'];
- $url = $data['url'];
- $res = Db::name('borrow_img')->where([
- 'borrow_id' => $borrow_id,
- 'url' => $url
- ])->delete();
- if ($res) {
- $this->success('删除成功!!');
- } else {
- $this->error('删除失败!!');
- }
- }
- }
|