예제 #1
0
파일: Qtype.php 프로젝트: eappl/prototype
 public function getQuestionNumList($ConditionList)
 {
     $table_to_process = Base_Widget::getDbTable($this->table_question_num);
     //查询列
     $select_fields = array('QuestionNum' => 'sum(questions)', 'QuestionType' => 'question_type', 'Qtype' => 'qtype');
     //分类统计列
     $group_fields = array('QuestionType', 'Qtype');
     //初始化查询条件
     if ($ConditionList['StartDate'] == $ConditionList['EndDate']) {
         $whereDate = $ConditionList['StartDate'] ? " date = '" . $ConditionList['StartDate'] . "' " : "";
         $whereStartDate = "";
         $whereEndDate = "";
     } else {
         $whereStartDate = $ConditionList['StartDate'] ? " date >= '" . $ConditionList['StartDate'] . "' " : "";
         $whereEndDate = $ConditionList['EndDate'] ? " date <= '" . $ConditionList['EndDate'] . "' " : "";
         $whereDate = "";
     }
     $whereQtype = $ConditionList['QtypeId'] ? " qtype = " . $ConditionList['QtypeId'] . " " : "";
     //$whereQuestionType = $ConditionList['QuestionType']?" question_type in (".$ConditionList['QuestionType'].")":"";
     $QuestionTypeArrTemp = explode(',', $ConditionList['QuestionType']);
     $QuestionTypeArr = $this->config->QuestionTypeList;
     foreach ($QuestionTypeArr as $key => $value) {
         if (!in_array($key, $QuestionTypeArrTemp)) {
             unset($QuestionTypeArr[$key]);
         }
     }
     if (count($QuestionTypeArr) < 1) {
         $QuestionTypeArr = $this->config->QuestionTypeList;
     }
     $t = array();
     foreach ($QuestionTypeArr as $key => $value) {
         $t[] = "'" . $key . "'";
     }
     $whereQuestionType = "question_type in (" . implode(",", $t) . ")";
     $whereCondition = array($whereDate, $whereStartDate, $whereEndDate, $whereQtype, $whereQuestionType);
     //print_R($whereCondition);
     //生成查询列
     $fields = Base_common::getSqlFields($select_fields);
     //生成分类汇总列
     $groups = Base_common::getGroupBy($group_fields);
     //生成条件列
     $where = Base_common::getSqlWhere($whereCondition);
     //初始化问题分类数组
     //获取所有需要显示的主分类列表
     $QtypeList = $this->getAllQtype(1, 'name,id,trading,pid');
     //初始化结果数组
     $QuestionNum = array();
     foreach ($QuestionTypeArr as $QuestionType => $QuestionTypeName) {
         $oCategory = new Kubao_Category();
         $CategoryInfo = $oCategory->getCategoryByQuestionType($QuestionType, 'name');
         $QuestionNum[$QuestionType] = array('content' => $CategoryInfo['name'] . "总量:", 'QuestionNum' => 0, 'QuestionNumList' => array());
         foreach ($QtypeList as $key => $QtypeInfo) {
             if ($QuestionType == "complain") {
                 $TradingConfig = unserialize($QtypeInfo['trading']);
                 //如果该投诉下的问题分类不可直接提交订单申诉则留在列表中,否则去除
                 if (trim($TradingConfig['directOrderUrl']) == "") {
                     $OrderCount = $this->getOrderCount($QtypeInfo['id'], 'order_count');
                     $OrderCount = isset($OrderCount['order_count']) ? intval($OrderCount['order_count']) : 0;
                     $QuestionNum[$QuestionType]['QuestionNumList'][$QtypeInfo['id']] = array('QuestionNum' => 0, 'OrderCount' => $OrderCount, 'QtypeId' => $QtypeInfo['id'], 'content' => $QtypeInfo['name'], 'url' => 'http://sc.5173.com/?index/questionTypeDetail/' . $QtypeInfo['id'] . '/' . $QuestionType);
                     $QuestionNum[$QuestionType]['OrderCount'] += $OrderCount;
                 }
             } else {
                 $QuestionNum[$QuestionType]['QuestionNumList'][$QtypeInfo['id']] = array('QuestionNum' => 0, 'QtypeId' => $QtypeInfo['id'], 'content' => $QtypeInfo['name'], 'url' => 'http://sc.5173.com/?index/questionTypeDetail/' . $QtypeInfo['id'] . '/' . $QuestionType);
             }
         }
         foreach ($QtypeList as $key => $QtypeInfo) {
             if ($QtypeInfo['pid'] > 0) {
                 unset($QuestionNum[$QuestionType]['QuestionNumList'][$QtypeInfo['pid']]);
             }
         }
     }
     $sql = "SELECT {$fields} FROM {$table_to_process} where 1 " . $where . $groups;
     $data = $this->db->getAll($sql);
     foreach ($data as $key => $value) {
         //数据累加
         if (isset($QuestionNum[$value['QuestionType']]['QuestionNumList'][$value['Qtype']])) {
             if ($value['QuestionType'] == "complain") {
                 $QuestionNum[$value['QuestionType']]['QuestionNum'] += $value['QuestionNum'];
                 if ($QuestionNum[$value['QuestionType']]['QuestionNumList'][$value['Qtype']]['OrderCount'] > 0) {
                     $value['QuestionNum'] = $value['QuestionNum'] / $QuestionNum[$value['QuestionType']]['QuestionNumList'][$value['Qtype']]['OrderCount'];
                     if ($value['QuestionNum'] > 1 || $value['QuestionNum'] < 1 / 100 / 100) {
                         $value['QuestionNum'] = "0.01%";
                         //$value['QuestionNum'] = $QuestionNum[$value['QuestionType']]['OrderCount'];
                     } else {
                         $value['QuestionNum'] = sprintf("%2.2f", $value['QuestionNum'] * 100) . "%";
                     }
                 } else {
                     $value['QuestionNum'] = "0.01%";
                     //$value['QuestionNum'] = $value['QuestionNum'];//$QuestionNum[$value['QuestionType']]['OrderCount'];
                 }
                 $QuestionNum[$value['QuestionType']]['QuestionNumList'][$value['Qtype']]['QuestionNum'] = $value['QuestionNum'];
             } else {
                 $QuestionNum[$value['QuestionType']]['QuestionNumList'][$value['Qtype']]['QuestionNum'] = $value['QuestionNum'];
                 $QuestionNum[$value['QuestionType']]['QuestionNum'] += $value['QuestionNum'];
             }
         }
     }
     //初始化为json可识别对象
     foreach ($QuestionTypeArr as $QuestionType => $QuestionTypeName) {
         $QuestionNum[$QuestionType]['QuestionNumList2'] = array();
         foreach ($QuestionNum[$QuestionType]['QuestionNumList'] as $key => $value) {
             $QuestionNum[$QuestionType]['QuestionNumList2'][] = $value;
         }
         $QuestionNum[$QuestionType]['QuestionNumList'] = $QuestionNum[$QuestionType]['QuestionNumList2'];
         unset($QuestionNum[$QuestionType]['QuestionNumList2']);
     }
     if (isset($QuestionNum["complain"])) {
         $Q = sprintf("%2.2f", $QuestionNum["complain"]['QuestionNum'] / $QuestionNum["complain"]['OrderCount'] * 100) . "%";
         if ($Q > 1 || $Q < 1 / 100 / 100) {
             $QuestionNum["complain"]['QuestionNum'] = "0.01%";
         } else {
             $QuestionNum["complain"]['QuestionNum'] = sprintf("%2.2f", $Q) . "%";
         }
     }
     return $QuestionNum;
 }
예제 #2
0
 public function ProcessComplainDetail($Complain)
 {
     $oMenCache = new Base_Cache_Memcache("Complaint");
     $Setting = $oMenCache->get('setting');
     $oCategory = new Kubao_Category();
     $oOperator = new Kubao_Operator();
     $oQtype = new Kubao_Qtype();
     $QuestionDetail = $this->GetQuestionDetail($Complain['QuestionId']);
     //获取到问题详情
     if ($QuestionDetail['QuestionId'] > 0) {
         //如果问题尚未被转换分类
         if ($QuestionDetail['Transformed'] != 1) {
             //如果问题被设置为隐藏
             if ($QuestionDetail['Hidden'] == 1) {
                 return $QuestionDetail;
             } else {
                 $QuestionType = "complain";
                 //获取问题分类内容
                 $CategoryInfo = $oCategory->getCategoryByQuestionType($QuestionType);
                 $QuestionDetail['CategoryName'] = $CategoryInfo['id'] ? $CategoryInfo['name'] : "未设置分类";
                 $QuestionDetail['QuestionType'] = ucfirst($QuestionType);
                 $QuestionDetail['PageTitle'] = $QuestionDetail['CategoryName'] . "详情";
                 //获取问题主分类内容
                 $QtypeInfo = $oQtype->getQtypeById($QuestionDetail['QtypeId'], 'id,name');
                 $QuestionDetail['QtypeName'] = $QtypeInfo['id'] ? $QtypeInfo['name'] : "未设置分类";
                 //如果回答中包含客服账号
                 if ($QuestionDetail['Answer']['OperatorName']) {
                     $List = 'id,photo,login_name,cno,QQ,mobile,weixin,weixinPicUrl,tel,name';
                     $M = $oMenCache->get('OperatorInfo_' . $QuestionDetail['Answer']['OperatorName'] . "_" . md5($List));
                     if ($M) {
                         $OperatorInfo = json_decode($M, true);
                         //如果获取到的客服信息不合法
                         if (!$OperatorInfo['login_name']) {
                             //从主站获取客服信息
                             $OperatorInfo = $oOperator->getOperatorFromVadmin($QuestionDetail['Answer']['OperatorName'], $List);
                             $OperatorInfo = $oOperator->processOperatorInfo($OperatorInfo);
                         }
                     } else {
                         //从主站获取客服信息
                         $OperatorInfo = $oOperator->getOperatorFromVadmin($QuestionDetail['Answer']['OperatorName'], $List);
                         //如果没有从主站获取到客服信息
                         if ($OperatorInfo['login_name']) {
                             //格式化显示信息
                             $OperatorInfo = $oOperator->processOperatorInfo($OperatorInfo);
                             $oMenCache->set('OperatorInfo_' . $QuestionDetail['Answer']['OperatorName'] . "_" . md5($List), json_encode($OperatorInfo), 60);
                         }
                     }
                     //如果获取到的客服信息合法
                     if ($OperatorInfo['OperatorName']) {
                         $oMenCache->set('OperatorInfo_' . $QuestionDetail['Answer']['OperatorName'] . "_" . md5($List), json_encode($OperatorInfo), 60);
                         $QuestionDetail['Answer']['OperatorInfo'] = $OperatorInfo;
                     } else {
                         unset($QuestionDetail['Answer']['OperatorInfo']);
                     }
                 }
                 //如果包含接单客服账号
                 if ($QuestionDetail['AcceptOperatorName']) {
                     $List = 'id,photo,login_name,cno,QQ,mobile,weixin,weixinPicUrl,tel,name';
                     //$M = $oMenCache -> get('OperatorInfo_'.$QuestionDetail['AcceptOperatorName']."_".md5($List));
                     if ($M) {
                         $OperatorInfo = json_decode($M, true);
                         //如果获取到的客服信息不合法
                         if (!$OperatorInfo['login_name']) {
                             //从主站获取客服信息
                             $OperatorInfo = $oOperator->getOperatorFromVadmin($QuestionDetail['AcceptOperatorName'], $List);
                             $OperatorInfo = $oOperator->processOperatorInfo($OperatorInfo);
                         }
                     } else {
                         //从主站获取客服信息
                         $OperatorInfo = $oOperator->getOperatorFromVadmin($QuestionDetail['AcceptOperatorName'], $List);
                         //如果没有从本地获取到客服信息
                         if ($OperatorInfo['login_name']) {
                             //格式化显示信息
                             $OperatorInfo = $oOperator->processOperatorInfo($OperatorInfo);
                         }
                     }
                     //如果获取到的客服信息合法
                     if ($OperatorInfo['OperatorName']) {
                         $oMenCache->set('OperatorInfo_' . $QuestionDetail['AcceptOperatorName'] . "_" . md5($List), json_encode($OperatorInfo), 60);
                         $QuestionDetail['AcceptOperatorInfo'] = $OperatorInfo;
                     } else {
                         unset($QuestionDetail['AcceptOperatorInfo']);
                     }
                 }
                 //如果问题状态为 已同步至投诉 并且 状态不是已撤销 并且 问题状态未初始创建 或者 开关允许任何状态撤销
                 if ($QuestionDetail['Sync'] == 1 && $QuestionDetail['QuestionStauts'] != 5 && $QuestionDetail['QuestionStatus'] != 5 && ($QuestionDetail['QuestionStauts'] == 0 || $QuestionDetail['QuestionStatus'] == 0 || $Setting['complainSwitch'])) {
                     //允许问题撤销
                     $QuestionDetail['Revoke'] = 1;
                 }
                 unset($QuestionDetail['CatagoryId'], $QuestionDetail['QtypeId']);
                 return $QuestionDetail;
             }
         } else {
             //如果问题被转换为咨询/建议
             if (in_array($QuestionDetail['QuestionType'], array('ask', 'suggest'))) {
                 return $QuestionDetail;
             } else {
                 return false;
             }
         }
     } else {
         return false;
     }
 }
예제 #3
0
 function ApplyToOperator($QuestionId, $OperatorName, $force = false)
 {
     //获取咨询、建议的分类ID
     $oCategory = new Kubao_Category();
     $oOperator = new Kubao_Operator();
     $Category_Ask = $oCategory->getCategoryByQuestionType('ask');
     $Category_Suggest = $oCategory->getCategoryByQuestionType('suggest');
     //获取问题
     $QuestionInfo = $this->getQuestion($QuestionId);
     //问题存在
     if ($QuestionInfo['id']) {
         //问题 尚未分单 且 尚未被撤销 且 接手客服为空 且 为非协助状态 且 问题分类在指定列表中
         if ($QuestionInfo['is_hawb'] == 0 && $QuestionInfo['revocation'] == 0 && $QuestionInfo['js_kf'] == "" && $QuestionInfo['help_status'] == 0 && in_array($QuestionInfo['cid'], array(0, $Category_Ask['id'], $Category_Suggest['id']))) {
             $this->db->begin();
             $updateArr = array("is_hawb" => 1, "js_kf" => $OperatorName, "receive_time" => time());
             $UpdateQuestion = $this->updateQuestion($QuestionInfo['id'], $updateArr);
             //如果更新成功
             if ($UpdateQuestion) {
                 $OperatorInfo = $oOperator->getOperatorByName($OperatorName, "login_name,pid,ishandle,isonjob,isbusy");
                 //如果客服存在 且 (是强制分单 或 客服非忙碌) 且 客服可以接单 且 客服在班
                 if ($OperatorInfo['login_name'] != '' && ($force == true || $OperatorInfo['isbusy'] == 0) && $OperatorInfo['ishandle'] == 1 && $OperatorInfo['isonjob'] == 1) {
                     //如果强制分单,则将当前单量置为负值
                     if ($force == true) {
                         $OperatorAccepted['num'] = -1;
                         $OperatorAccepted['num_add'] = -1;
                     } else {
                         //检查客服已分配单量
                         $OperatorAccepted = $oOperator->getOperatorAccecpted($OperatorName, "num,num_add");
                     }
                     //获取分单数量限制
                     $PostLimit = $oOperator->getPost($OperatorInfo['pid'], "question_limit,question_limit_add");
                     //首问
                     if ($QuestionInfo['pid'] == 0) {
                         //首问单量小于首问最大单量
                         if (intval($OperatorAccepted['num']) < $PostLimit['question_limit']) {
                             //更新首问数量
                             $UpdateAcceptedNum = $oOperator->UpdateOperatorAccecpted($OperatorName, 1, 0);
                         } else {
                             //单量不足,回滚
                             $this->db->rollback();
                             return false;
                         }
                     } else {
                         //追问单量小于追问最大单量
                         if (intval($OperatorAccepted['num_add']) < $PostLimit['question_limit_add']) {
                             //更新追问数量
                             $UpdateAcceptedNum = $oOperator->UpdateOperatorAccecpted($OperatorName, 1, 1);
                         } else {
                             //单量不足,回滚
                             $this->db->rollback();
                             return false;
                         }
                     }
                     if ($UpdateAcceptedNum) {
                         //更新成功,提交
                         $this->db->commit();
                         return true;
                     } else {
                         // 更新失败,回滚
                         $this->db->rollback();
                         return false;
                     }
                 } else {
                     //客服不在班或不存在
                     $this->db->rollback();
                     return false;
                 }
             } else {
                 //更新失败
                 $this->db->rollback();
                 return false;
             }
         } else {
             return false;
         }
     } else {
         //无此问题
         return false;
     }
 }