$this->ERROR_CODE, 'msg' => $msg, 'data' => $data ]; return json_encode($arr); } protected function jsonSuccess($msg = '成功',$data = []) { $arr = [ 'code' => $this->SUCCESS_CODE, 'msg' => $msg, 'data' => $data ]; return json_encode($arr); } /** * * @param $tableName * @param $queryData * @param $data * @param $idArr * @return array * @throws Exception * @throws PDOException */ protected function queryUpdate($tableName,$queryData,$data,$idArr) { $idArr = []; if ($queryData) { $id = $queryData['id']; $update = []; foreach ($queryData as $key => $row) { if (isset($data[$key]) && $data[$key] != $row) { $update[$key] = $row; } } if ($update) { Db::table($tableName)->where('id',$id)->update($update); } $idArr[] = $id; } else { Db::table($tableName)->insert($data); $idArr[] = Db::table($tableName)->getLastInsID(); } return $idArr; } /** * * @param $tableName * @param $idArr * @param $updateStatus * @throws DataNotFoundException * @throws DbException * @throws Exception * @throws ModelNotFoundException * @throws PDOException */ protected function updateStatus($tableName,$idArr,$updateStatus = ['status' => 0]) { if ($idArr) { # 查询不存在的id $notList = Db::table($tableName)->where('id', 'not in', $idArr)->field('id')->select(); $notIdArr = []; foreach ($notList as $notListRow) $notList[] = $notListRow['id']; if ($notIdArr) { Db::table($tableName)->where('id','in',$notIdArr)->update($updateStatus); } } else { Db::table($tableName)->update($updateStatus); } } }