public function ModelBase() { parent::mysqlmodel(); $this->provider->debug = FALSE; $this->provider->properties = $GLOBALS['AppConfig']['db']; }
public function view_replyMessageAli_site() { include_once WEB_PATH . 'lib/AliMessage.class.php'; $text = isset($_POST['text']) ? trim($_POST['text']) : ''; //回复的内容 $buyerId = isset($_GET['buyerid']) ? trim($_GET['buyerid']) : ''; //买家id $account = isset($_GET['account']) ? trim($_GET['account']) : ''; //卖家账号 $relationid = isset($_GET['relationid']) ? trim($_GET['relationid']) : ''; //消息关系id $bigestid = isset($_GET['bigestid']) ? trim($_GET['bigestid']) : ''; //最大的id $region_h = isset($_GET['region_h']) ? trim($_GET['region_h']) : 0; //回复区间id 头 $region_e = isset($_GET['region_e']) ? trim($_GET['region_e']) : 0; //回复区间id 尾 $msg_obj = new messageModel(); if (empty($buyerId)) { $msgdata = array('errCode' => 10017, 'errMsg' => '缺少买家ID!'); echo json_encode($msgdata); exit; } if (empty($account)) { $msgdata = array('errCode' => 10017, 'errMsg' => '缺少卖家账号!'); echo json_encode($msgdata); exit; } if (empty($text)) { $msgdata = array('errCode' => 10013, 'errMsg' => '回复内容不能为空!'); echo json_encode($msgdata); exit; } //加载token信息 $configFile = WEB_PATH . 'lib/ali_keys/' . "config_{$account}.php"; // echo $configFile;"\n";exit; if (file_exists($configFile)) { include $configFile; } else { echo date('Y-m-d H:i:s', time()) . '---' . __LINE__ . "key file was not found !\n"; exit; } /*将消息标记为已读*/ $mysql_obj = new MysqlModel(); $dataSet = array('hasread' => 2, 'replytime' => time()); $whereSql = " where message_id>={$region_h} and message_id<={$region_e} and role=1 and relationId={$relationid}"; $effectNum = $mysql_obj->update('msg_alisitemessage', $dataSet, $whereSql); $aliRepl_obj = new AliMessage(); $aliRepl_obj->setConfig($appKey, $appSecret, $refresh_token); $aliRepl_obj->doInit(); $result = $aliRepl_obj->replySiteMessage($buyerId, $text); $alireobj = new AliSiteReplyModel(); $data = array(); $data['relationid'] = $relationid; //站内信关联id $data['content'] = $text; //内容 $data['replyuser'] = $_SESSION['globaluserid']; //回复人id $alireobj->addNewReplyData($data); $starttime = time() - 300; $endtime = time() + 300; $starttime = trunToLosangeles('m/d/Y H:i:s', $starttime); $endtime = trunToLosangeles('m/d/Y H:i:s', $endtime); sleep(6); $newMsg = $aliRepl_obj->getSiteMessageMin($starttime, $endtime, $bigestid, $buyerId); // print_r($newMsg);exit; $newdiv = ''; foreach ($newMsg as $nmsg) { if ($bigestid < $nmsg['id']) { $bigestid = $nmsg['id']; } $sendtime = aliTranslateTime($nmsg['gmtCreate']); $sendtime = date('Y-m-d H:i:s', $sendtime); // print_r($nmsg);exit; $imgstr = ''; $orderstr = ''; if (!empty($nmsg['orderUrl'])) { $orderstr = <<<EOF \t<div style="float:left; margin-left:10px;"> <a href="{$nmsg['orderUrl']}" target="_blank">{$nmsg['orderId']}</a> </div> EOF; } if (!empty($nmsg['fileUrl'])) { $imgstr = <<<EOF \t<div style="float:left;padding-left:3px;padding-top:1px;"> \t\t\t\t <a href="{$commn[fileUrl]}" target="_blank"><img src="{$commn[fileUrl]}" style="width:78px; height:78px;"></a> \t\t\t\t</div> EOF; } $newdiv .= <<<EOF <div style="background-color:#E1FACF; padding:2px; margin-top:3px;margin-bottom:3px;"> \t <div><span style=" width:100px;font-family:Arial,Verdana,Helvetica,sans-serif; font-size:13px;">{$nmsg['senderName']}</span> :{$sendtime}</div> \t <div style="padding-left:113px;color:#525252;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:13px;">{$nmsg['content']}</div> \t\t <div style="background-color:#fff"> \t {$imgstr} {$orderstr} \t\t\t <div style="clear:both;"></div> \t </div> \t </div> EOF; } if (FALSE === $result) { //执行失败 $msgdata = array('errCode' => 10015, 'errMsg' => '回复失败!'); echo json_encode($msgdata); exit; } else { //执行成功 $msgdata = array('errCode' => 10016, 'errMsg' => '回复成功!', 'newmsg' => $newdiv, 'bigestid' => $bigestid); echo json_encode($msgdata); exit; } }
public function view_messageStatisticsAli() { $starttime = isset($_GET['starttime']) ? trim($_GET['starttime']) : ''; $endtime = isset($_GET['endtime']) ? trim($_GET['endtime']) : ''; $type = isset($_GET['type']) ? trim($_GET['type']) : 'order'; $wheresql = ''; date_default_timezone_set('America/Los_Angeles'); //转换成洛杉矶时间 $start_stamp = strtotime($starttime); $end_stamp = strtotime($endtime) + 84600; date_default_timezone_set('Asia/Shanghai'); if (!empty($starttime)) { $wheresql .= ' and createtimestamp > ' . $start_stamp; } if (!empty($endtime)) { $wheresql .= ' and createtimestamp < ' . $end_stamp; } $localuser = new GetLoacalUserModel(); $mysql_obj = new MysqlModel(); $cat_obj = new messagecategoryModel(); $list = $cat_obj->getAllCategoryInfoList('', 2); // print_r($list); $userGroup = array(); foreach ($list as $lival) { $cat_name = trim($lival['category_name']); $nameBreak = explode("--", $cat_name); $userName = array_pop($nameBreak); if (array_key_exists($userName, $userGroup)) { $userGroup[$userName][] = $lival['id']; } else { $userGroup[$userName] = array($lival['id']); } } $userName2loginName = array('韩庆新' => '*****@*****.**', '王丽娟' => '*****@*****.**', '王玲' => '*****@*****.**', '王铭' => '*****@*****.**', '喻情' => '*****@*****.**', '黄海娣' => '*****@*****.**', '袁岸' => '*****@*****.**', '潘小红' => '*****@*****.**', '陈小燕' => '*****@*****.**', '肖奇生' => '*****@*****.**', '戴霞' => '*****@*****.**', '温健玲' => '*****@*****.**', '肖庚莲' => '*****@*****.**'); $name2id = $localuser->getUserId($userName2loginName); //中文名称到系统用户id的映射关系 // print_r($name2id); if ($type == 'order') { //处理订单留言 $sql = "select fieldId , hasread,count(*) as num from msg_aliordermessage where role=1 and hasread in (0,1)\n {$wheresql} group by fieldId, hasread\n "; // echo $sql;exit; $resultList = $mysql_obj->getQueryResult($sql); $statistics = array(); //统计数据 foreach ($userGroup as $username => $ids) { if (!array_key_exists($username, $statistics)) { $statistics[$username] = array(0 => 0, 1 => 0); } foreach ($resultList as $row) { if (in_array($row['fieldId'], $ids)) { if ($row['hasread'] == 0) { //累加未回复留言 $statistics[$username][0] += $row['num']; } elseif ($row['hasread'] == 1) { //累加已读留言 $statistics[$username][1] += $row['num']; } } } } foreach ($statistics as $key => $item) { $total = array_sum($item); $statistics[$key]['total'] = $total; } // print_r($statistics); $replyedStatistics = array(); //已回复留言统计 $userIdSql = implode(', ', $name2id); $sqlre = "select replyer, count(*) as num from msg_aliordermessage where role=1 and replyer in ({$userIdSql}) \n and hasread=2 {$wheresql} group by replyer"; // echo $sqlre;exit; $replyResult = $mysql_obj->getQueryResult($sqlre); $replyList = array(); foreach ($replyResult as $reRow) { $replyList[$reRow['replyer']] = $reRow['num']; } $totalNohandle = 0; //未处理的留言总数 $totalRead = 0; //已读留言总数 $totalReply = 0; //已回复留言总数 foreach ($statistics as $r) { $totalNohandle += $r[0]; $totalRead += $r[1]; $totalReply += $r[2]; } global $dbConn; $accountGroup = $this->getAliAccountGroup(); $gropAmount = array(); foreach ($accountGroup as $key => $group) { $sql_str = implode("', '", $group); $sql = "select count(1) as num from msg_aliordermessage where receiverid in ('{$sql_str}') {$wheresql}"; $row = $dbConn->fetch_first($sql); $gropAmount[$key] = $row['num']; } $filpNameId = array_flip($name2id); foreach ($statistics as $user => $rows) { $userId = isset($name2id[$user]) ? $name2id[$user] : -1; if (isset($replyList[$userId])) { $statistics[$user][2] = $replyList[$userId]; } else { $statistics[$user][2] = 0; } } $thirdmenue = 1; } else { //处理站内信 $sql = "select fieldId , hasread, count(*) as num from msg_alisitemessage where role=1 and hasread in (0,1)\n {$wheresql} group by fieldId, hasread\n "; $resultList = $mysql_obj->getQueryResult($sql); $statistics = array(); // 统计数据 foreach ($userGroup as $username => $ids) { if (!array_key_exists($username, $statistics)) { $statistics[$username] = array(0 => 0, 1 => 0); } foreach ($resultList as $row) { if (in_array($row['fieldId'], $ids)) { if ($row['hasread'] == 0) { // 累加未回复留言 $statistics[$username][0] += $row['num']; } elseif ($row['hasread'] == 1) { // 累加已读留言 $statistics[$username][1] += $row['num']; } } } } foreach ($statistics as $key => $item) { $total = array_sum($item); $statistics[$key]['total'] = $total; } // print_r($statistics); $replyedStatistics = array(); // 已回复留言统计 $userIdSql = implode(', ', $name2id); $sqlre = "select replyer, count(*) as num from msg_alisitemessage where role=1 and replyer in ({$userIdSql}) \n and hasread=2 {$wheresql} group by replyer"; // echo $sqlre;exit; $replyResult = $mysql_obj->getQueryResult($sqlre); $replyList = array(); foreach ($replyResult as $reRow) { $replyList[$reRow['replyer']] = $reRow['num']; } $totalNohandle = 0; // 未处理的留言总数 $totalRead = 0; // 已读留言总数 $totalReply = 0; // 已回复留言总数 foreach ($statistics as $r) { $totalNohandle += $r[0]; $totalRead += $r[1]; $totalReply += $r[2]; } global $dbConn; $accountGroup = $this->getAliAccountGroup(); $gropAmount = array(); foreach ($accountGroup as $key => $group) { $sql_str = implode("', '", $group); $sql = "select count(1) as num from msg_alisitemessage where receiverid in ('{$sql_str}') {$wheresql}"; $row = $dbConn->fetch_first($sql); $gropAmount[$key] = $row['num']; } // print_r($gropAmount);exit; $filpNameId = array_flip($name2id); // print_r($filpNameId); foreach ($statistics as $user => $rows) { $userId = isset($name2id[$user]) ? $name2id[$user] : -1; if (isset($replyList[$userId])) { $statistics[$user][2] = $replyList[$userId]; } else { $statistics[$user][2] = 0; } } // print_r($statistics);exit; $thirdmenue = 2; } // exit; // print_r($data);exit; $this->smarty->assign('third_menue', $thirdmenue); $this->smarty->assign('starttime', $starttime); $this->smarty->assign('endtime', $endtime); $this->smarty->assign('totalNhandle', $totalNohandle); $this->smarty->assign('totalread', $totalRead); $this->smarty->assign('totalreply', $totalReply); $this->smarty->assign('type', $type); $this->smarty->assign('toplevel', 3); // $this->smarty->assign('navlist', $navlist); $this->smarty->assign('statistics', $statistics); $this->smarty->assign('statistics_2', $gropAmount); $this->smarty->assign('sec_menue', 2); $this->smarty->display('msgstatisticsAliorder.htm'); }