$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); } }