function IHomeServiceVoteComplainOperation($params = NULL) { global $_SGLOBAL; if ($params['uid']) { if ($params['uid'] <= 0) { $errorMsg = array("errorNo" => "4002", "content" => "the format of parameter is not correct.the parameter uid must be a positive integer."); return json_encode($errorMsg); } else { $query = $_SGLOBAL['db']->query("select username,name from " . tname('space') . " where uid = " . $params['uid']); if ($row = $_SGLOBAL['db']->fetch_array($query)) { if ($row['name']) { $params['uname'] = $row['name']; } else { $params['uname'] = $row['username']; } } else { $errorMsg = array("errorNo" => "500", "content" => "the uid is not exist"); return json_encode($errorMsg); } } } else { $errorMsg = array("errorNo" => "4001", "content" => "lack the neccessary parameter.the parameter uid is not exist or is not a positive integer."); return json_encode($errorMsg); } if ($params['complainId']) { if ($params['complainId'] <= 0) { $errorMsg = array("errorNo" => "4002", "content" => "the format of parameter is not correct.the parameter complainId must be a positive integer."); return json_encode($errorMsg); } else { $query = $_SGLOBAL['db']->query("select uname from " . tname('complain') . " where doid = " . $params['complainId']); if ($row = $_SGLOBAL['db']->fetch_array($query)) { if (isblacklist($row['uid'])) { $errorMsg = array("errorNo" => "500", "content" => "the user of complain is in blacklist."); return json_encode($errorMsg); } } else { $errorMsg = array("errorNo" => "500", "content" => "the complain id is not exist"); return json_encode($errorMsg); } } } else { $errorMsg = array("errorNo" => "4001", "content" => "lack the neccessary parameter.the parameter complainId is not exist or is not a positive integer."); return json_encode($errorMsg); } if ($params['reply_id']) { if ($params['reply_id'] <= 0) { $errorMsg = array("errorNo" => "4002", "content" => "the format of parameter is not correct.the parameter reply_id must be a positive integer."); return json_encode($errorMsg); } else { $query = $_SGLOBAL['db']->query("select * from " . tname('complain_op') . " where id = " . $params['reply_id']); if (!($row = $_SGLOBAL['db']->fetch_array($query))) { $errorMsg = array("errorNo" => "4001", "content" => "the reply_id isn't exist."); return json_encode($errorMsg); } } } else { $errorMsg = array("errorNo" => "4001", "content" => "lack the neccessary parameter.the parameter reply_id is not exist or is not a positive integer."); return json_encode($errorMsg); } if (!$params['vote']) { $errorMsg = array("errorNo" => "4001", "content" => "lack the neccessary parameter.the parameter vote is not exist."); return json_encode($errorMsg); } else { if ($params['vote'] != 'up' & $params['vote'] != 'down') { $errorMsg = array("errorNo" => "4002", "content" => "the format of parameter is not correct.the parameter vote is our of range."); return json_encode($errorMsg); } } # check over $query = $_SGLOBAL['db']->query("select * from " . tname('complain') . " where doid=" . $params['complainId']); $complain = $_SGLOBAL['db']->fetch_array($query); # checked if ($params['vote'] == 'up') { $query = $_SGLOBAL['db']->query("select * from " . tname("complain_op_updown") . " where opid = " . $params['reply_id'] . " and uid = " . $params['uid']); $updown = $_SGLOBAL['db']->fetch_array($query); if (!empty($updown)) { if ($updown['uid'] == $complain['uid'] || $updown['updown'] == 2) { $errorMsg = array("errorNo" => "403", "content" => "updown again"); return json_encode($errorMsg); } $_SGLOBAL['db']->query("delete from " . tname("complain_op_updown") . " where opid = " . $params['reply_id'] . " and uid = " . $params['uid'] . " and updown = 1"); $_SGLOBAL['db']->query("update " . tname('complain_op') . " set upnum=upnum-1 where id=" . $params['reply_id']); $_SGLOBAL['db']->query("update " . tname('complain_dep') . " set upnum=upnum-1,updownnum=updownnum-1,score=score-1 where uid in (select uid from " . tname("complain_op") . " where id=" . $params['reply_id'] . ")"); } else { $downarr = array(); $downarr['opid'] = $params['reply_id']; $downarr['uid'] = $params['uid']; $downarr['updown'] = 1; $downarr['username'] = $params['uname']; $downarr['dateline'] = $_SGLOBAL['timestamp']; $_SGLOBAL['db']->query("update " . tname('complain_dep') . " set upnum=upnum+1,updownnum=updownnum+1,score=score+1 where uid in (select uid from " . tname("complain_op") . " where id= " . $params['reply_id'] . ")"); inserttable("complain_op_updown", $downarr); $_SGLOBAL['db']->query("update " . tname('complain_op') . " set upnum=upnum+1 where id=" . $params['reply_id']); $q = $_SGLOBAL['db']->query("select * from " . tname('complain') . " where uid=" . $params['uid'] . " and doid=" . $params['complainId'] . " and lastopid=" . $params['reply_id'] . " and status=1"); if ($r = $_SGLOBAL['db']->fetch_array($q)) { updatetable('complain', array('status' => 2), array('id' => $r['id'])); $oparr = array(); $oparr['doid'] = $params['complainId']; $oparr['message'] = ''; $oparr['uid'] = $params['uid']; $oparr['username'] = $params['uname']; $oparr['optype'] = 6; $oparr['dateline'] = $_SGLOBAL['timestamp']; $oparr['opvalue'] = 1; inserttable("complain_op", $oparr); } } } else { if ($params['vote'] == 'down') { $query = $_SGLOBAL['db']->query("select * from " . tname("complain_op_updown") . " where opid = " . $params['reply_id'] . " and uid = " . $params['uid']); $updown = $_SGLOBAL['db']->fetch_array($query); if (!empty($updown)) { if ($updown['uid'] == $complain['uid'] || $updown['updown'] == 1) { $errorMsg = array("errorNo" => "403", "content" => "updown again"); return json_encode($errorMsg); } $_SGLOBAL['db']->query("delete from " . tname("complain_op_updown") . " where opid = " . $params['reply_id'] . " and uid = " . $params['uid'] . " and updown = 2"); $_SGLOBAL['db']->query("update " . tname('complain_op') . " set downnum=downnum-1 where id=" . $params['reply_id']); $_SGLOBAL['db']->query("update " . tname('complain_dep') . " set downnum=downnum-1,updownnum=updownnum-1,score=score+1 where uid in (select uid from " . tname("complain_op") . " where id=" . $params['reply_id'] . ")"); } else { $downarr = array(); $downarr['opid'] = $params['reply_id']; $downarr['uid'] = $params['uid']; $downarr['updown'] = 2; $downarr['username'] = $params['uname']; $downarr['dateline'] = $_SGLOBAL['timestamp']; inserttable("complain_op_updown", $downarr); $_SGLOBAL['db']->query("update " . tname('complain_dep') . " set downnum=downnum+1,updownnum=updownnum+1,score=score-1 where uid in (select uid from " . tname("complain_op") . " where id=" . $params['reply_id'] . ")"); $_SGLOBAL['db']->query("update " . tname('complain_op') . " set downnum=downnum+1 where id=" . $params['reply_id']); $sql = "select * from " . tname('complain') . " where uid=" . $params['uid'] . " and doid=" . $params['complainId'] . " and lastopid=" . $params['reply_id'] . " and status=1"; $q = $_SGLOBAL['db']->query("select * from " . tname('complain') . " where uid=" . $params['uid'] . " and doid=" . $params['complainId'] . " and lastopid=" . $params['reply_id'] . " and status=1"); if ($r = $_SGLOBAL['db']->fetch_array($q)) { updatetable('complain', array('status' => 0, 'lastopid' => 0, 'dateline' => $_SGLOBAL['timestamp'], 'times' => 1, 'issendmsg' => 0), array('id' => $r['id'])); $note = cplang("complain_down", array("space.php?do=complain_item&doid={$complain['doid']}")); notification_complain_add($complain["atuid"], "complain", $note); $oparr = array(); $oparr['doid'] = $params['complainId']; $oparr['message'] = ''; $oparr['uid'] = $params['uid']; $oparr['username'] = $params['uname']; $oparr['optype'] = 5; $oparr['dateline'] = $_SGLOBAL['timestamp']; $oparr['opvalue'] = 1; inserttable("complain_op", $oparr); } } } } }
} if ($complainOK) { //֪ͨÓû§ËßÇó·¢Æð³É¹¦ $note = cplang('note_complain_user_success', array("space.php?do=complain_item&doid={$newdoid}")); notification_complain_add($_SGLOBAL['supe_uid'], 'complain', $note); $complain_msg = 'note_complain_user_success'; getreward('complain', 1, $_SGLOBAL['supe_uid']); } if (!$complainOK && $isComplain) { //ËßÇó·¢Æðʧ°Ü if ($UserId == '0000') { $note = cplang("您好,您的诉求已发送成功。谢谢您对ihome社区的大力支持!", array("space.php?do=doing&doid={$newdoid}")); notification_complain_add($_SGLOBAL['supe_uid'], 'complain', $note); } else { $note = cplang('note_complain_user_failed', array("space.php?do=doing&doid={$newdoid}")); notification_complain_add($_SGLOBAL['supe_uid'], 'complain', $note); $complain_msg = 'note_complain_user_failed'; } } //ÒÔÉÏ´¦ÀíͶËßÐÅÏ¢////////////////////////// } //¸üпռänote $setarr = array('note' => $message); $credit = $experience = 0; if (!empty($_POST['spacenote'])) { $reward = getreward('updatemood', 0); $setarr['spacenote'] = $message; } else { $reward = getreward('doing', 0); } updatetable('spacefield', $setarr, array('uid' => $_SGLOBAL['supe_uid']));
//根据@到的用户ID,查询该用户是否为部门 $UserDept = isDepartment($UserId, 0); if ($UserDept) { $nowtime = time(); $dateline = strtotime("+1 days", $nowtime); $complain = array('doid' => $newdoid, 'uid' => $userid, 'uname' => $username, 'atdepartment' => $UserDept['department'], 'atdeptuid' => $UserId, 'from' => $username, 'atuid' => $UserId, 'atuname' => $UserDept['department'], 'isreply' => 0, 'addtime' => $nowtime, 'dateline' => $dateline, 'expire' => 0, 'times' => 1, 'issendmsg' => 0, 'message' => $Message); $newcomplainid = inserttable('complain', $complain, 1); } //通知被@的部门,有用户投诉 $note = cplang('note_complain_buchu', array("space.php?do=doing&doid={$newdoid}", date('Y-m-d H:i', $dateline))); notification_complain_add($UserId, 'complain', $note); $complainOK = TRUE; if ($complainOK) { //通知用户诉求发起成功 $note = cplang('note_complain_user_success', array("space.php?do=doing&doid={$newdoid}")); notification_complain_add($userid, 'complain', $note); getreward('complain', 1, $userid); } //事件feed $feedarr = array('appid' => UC_APPID, 'icon' => 'doing', 'uid' => $userid, 'username' => $username, 'dateline' => $_SGLOBAL['timestamp'], 'title_template' => cplang('feed_doing_title'), 'title_data' => saddslashes(serialize(sstripslashes(array('message' => $Message)))), 'body_template' => '', 'body_data' => '', 'id' => $newcomplainid, 'idtype' => 'doid', 'fromdevice' => $FromDevice); $feedarr['hash_template'] = md5($feedarr['title_template'] . "\t" . $feedarr['body_template']); //喜好hash $feedarr['hash_data'] = md5($feedarr['title_template'] . "\t" . $feedarr['title_data'] . "\t" . $feedarr['body_template'] . "\t" . $feedarr['body_data']); //合并hash inserttable('feed', $feedarr, 1); updatestat('doing'); //更新空间note $setarr = array('note' => $Message); if (!empty($_POST['spacenote'])) { $reward = getreward('updatemood', 0); $setarr['spacenote'] = $Message;
$UpUserArray3 = isDepartment($up_arr[0], 0); if (empty($UpUserArray3)) { continue; } addNeedSend($result, $UpUserArray3['dept_uid'], $nexttime, "条诉求未处理,请您安排处理.", $UpUserArray3, array($result['atuid'] => $UserArray['mobile'] . ',1', $UpUserArray['dept_uid'] => $UpUserArray['mobile'] . ',3', $UpUserArray2['dept_uid'] => $UpUserArray2['mobile'] . ',7'), 10); updatetable("complain", array("issendmsg" => 1, "times" => 10), array("id" => $result['id'])); $note = cplang("note_complain_user", array($complain_url, $result['atdepartment'], '校长')); notification_complain_add($result['uid'], 'complain', $note); $note = cplang("note_complain_buchu3", array($complain_url, date('Y-m-d H:i', $nexttime))); notification_complain_add($UserArray['dept_uid'], 'complain', $note); $note = cplang('note_complain_chuzhang2', array($complain_url, date('Y-m-d H:i', $nexttime))); notification_complain_add($UpUserArray['dept_uid'], 'complain', $note); $note = cplang('note_complain_fuxiaozhang1', array($complain_url, date('Y-m-d H:i', $nexttime), $result['atdepartment'])); notification_complain_add($UpUserArray2['dept_uid'], 'complain', $note); $note = cplang('note_complain_xiaozhang', array($complain_url, date('Y-m-d H:i', $nexttime), $result['atdepartment'])); notification_complain_add($UpUserArray3['dept_uid'], 'complain', $note); $log->debug("complain doid {$result['doid']} send message xiaozhang"); } } var_dump($needSend); //以上处理投诉的逐级汇报////////////////////// //发送上次发送未成功的短信 sendDelayMsg(); sendMobileMsg(); //写入记录文件,以便查看定时任务是否正常执行 $fp = fopen("data/log/checkcomplain.log", "a+"); fwrite($fp, date("Y-m-d H:i:s") . "\t\t检测完毕!\n"); fclose($fp); echo '任务执行完毕~!<br />'; function sendDelayMsg() {
if (empty($dep)) { $arr = array(); $arr['uid'] = $legalEntity; $arr['username'] = $legalEntityName; $arr['upnum'] = 0; $arr['downnum'] = 0; $arr['allreplynum'] = 1; $arr['allreplysecs'] = $_SGLOBAL['timestamp'] - $complain['dateline']; $arr['score'] = 0; $arr['aversecs'] = 0; $arr['lastupdate'] = 0; inserttable('complain_dep', $arr); } else { $arr['allreplynum'] = $dep['allreplynum'] + 1; $arr['allreplysecs'] = $dep['allreplysecs'] + $_SGLOBAL['timestamp'] - $complain['dateline']; updatetable("complain_dep", $arr, array('uid' => $legalEntity)); } } inserttable('complain_resp', array('uid' => $legalEntity, 'doid' => $doid, 'opid' => $opid, 'replysecs' => $_SGLOBAL['timestamp'] - $complain['dateline'], 'dateline' => $_SGLOBAL['timestamp'])); $note = cplang('note_doingcomplain_reply', array("space.php?do=complain_item&doid={$complain['doid']}")); notification_complain_add($complain['uid'], 'complain', $note, $legalEntity, $legalEntityName); // notification_add($complain['uid'], 'system', $note); // echo "complain_add2"; } echo "do_success"; exit; } echo "error_op"; exit; } include template("cp_complain");