123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- /*
- * @Author: wang jun
- * @Date: 2021-10-29 16:16:29
- * @Last Modified by: wang jun
- * @Last Modified time: 2021-12-24 15:11:29
- */
- namespace app\index\logic;
- use app\index\model\trainmodel;
- use app\index\model\trainsignusermodel;
- class trainlogic
- {
- /**
- * 新增培训
- * 20211224
- * wj
- */
- public function newinfo($info)
- {
- $fillField = ['name', 'maxpersion'];
- foreach ($fillField as $key => $value) {
- if (!isset($info[$value]) || empty($info[$value])) {
- return backarr(0, "请求失败");
- }
- }
- $m_t = new trainmodel();
- if (!isset($info['createtime']) || empty($info['createtime'])) {
- $info['createtime'] = date('Y-m-d H:i:s', time());
- }
- $id = $m_t->insertData($info);
- if (!$id) {
- return backarr(0, "操作失败");
- }
- return backarr(1, "操作成功", ['id' => $id]);
- }
- /**
- * 改详细信息
- * 20211224
- * wj
- */
- public function updateinfo($arr)
- {
- if (!isset($arr['id']) || empty($arr['id'])) {
- return backarr(0, "请求失败");
- }
- $m_t = new trainmodel();
- $id = $arr['id'];
- $where = ['id' => $id];
- $tinfo = $m_t->getInfo($where);
- if (empty($tinfo)) {
- return backarr(0, "无数据");
- }
- $updateField = ['name', 'disstr', 'starttime', 'endtime', 'maxpersion'];
- $updateData = [];
- foreach ($updateField as $key => $value) {
- if (isset($arr[$value]) && !empty($arr[$value]) && $tinfo[$value] != $arr[$value]) {
- $updateData[$value] = $arr[$value];
- }
- }
- if (isset($updateField['starttime']) && isset($updateField['endtime'])) {
- if (strtotime($updateField['starttime']) > strtotime($updateField['endtime'])) {
- return backarr(0, "时间段错误");
- }
- }
- if (empty($updateData)) {
- return backarr(0, "无修改数据");
- }
- $row = $m_t->updateinfo($where, $updateData);
- if (!$row) {
- return backarr(0, "操作失败");
- }
- return backarr(1, "操作成功", ['id' => $id]);
- }
- /**
- * 获取信息根据id
- * 20211224
- * wj
- */
- public function getinfobyid($arr)
- {
- if (!isset($arr['id']) || empty($arr['id'])) {
- return backarr(0, "请求失败");
- }
- $id = $arr['id'];
- $m_t = new trainmodel();
- $where = ['id' => $id];
- $cinfo = $m_t->getInfo($where);
- if (empty($cinfo)) {
- return backarr(0, "无数据");
- }
- return backarr(1, "操作成功", $cinfo);
- }
- /**
- * 修改isactive根据id
- * 20211224
- * wj
- */
- public function updateisactivebyid($arr)
- {
- if (!isset($arr['id']) || empty($arr['id']) || !isset($arr['isactive']) || !in_array($arr['isactive'], [0, 1])) {
- return backarr(0, "请求失败");
- }
- $id = $arr['id'];
- $isactive = $arr['isactive'];
- $m_t = new trainmodel();
- $where = ['id' => $id];
- $cinfo = $m_t->getInfo($where);
- if (empty($cinfo)) {
- return backarr(0, "无数据");
- }
- $updateData = [];
- if ($isactive != $cinfo['isactive']) {
- $updateData['isactive'] = $isactive;
- }
- if (empty($updateData)) {
- return backarr(0, "无修改数据", ['id' => $id]);
- }
- $row = $m_t->updateinfo($where, $updateData);
- if (!$row) {
- return backarr(0, "操作失败");
- }
- return backarr(1, "操作成功", ['id' => $id, 'isactive' => $isactive]);
- }
- /***
- * 获取列表 按时间倒序
- * 20211224
- * wj
- */
- public function getlistbywhere($arr)
- {
- $m_t = new trainmodel();
- $where = [];
- if (isset($arr['name']) && !empty($arr['name'])) {
- $where['name'] = ['like', '%' . $arr['name'] . '%'];
- }
- if (isset($arr['isactive']) && is_numeric($arr['isactive']) && in_array($arr['isactive'], [0, 1])) {
- $where['isactive'] = $arr['isactive'];
- }
- if (isset($arr['worktype']) && !empty($arr['worktype'])) {
- $where['worktype'] = ['like', '%' . $arr['worktype'] . '%'];
- }
- $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
- $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
- $count = $m_t->getList($where, 'count');
- if ($count <= 0) {
- return backarr(0, "无数据");
- }
- $list = $m_t->getList($where, '*', $page, $size);
- if (isset($arr['userid']) && !empty($arr['userid'])) {
- $userid = $arr['userid'];
- $m_tu = new trainsignusermodel();
- foreach ($list as $key => $value) {
- $list[$key]['userid'] = $userid;
- $where = ['tid' => $value['id'], 'userid' => $userid, 'status' => 1];
- $tuinfo = $m_tu->getInfo($where);
- if (empty($tuinfo)) {
- $list[$key]['status'] = 0;
- } else {
- $list[$key]['status'] = 1;
- }
- }
- }
- return backarr(1, "查询成功", $list);
- }
- }
|