339 lines
14 KiB
PHP
339 lines
14 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\model\Message;
|
||
use app\model\Notice;
|
||
use app\model\Attachment;
|
||
use think\Db;
|
||
use think\facade\Request;
|
||
use think\facade\Log;
|
||
|
||
class MessageRemind extends Base
|
||
{
|
||
private $type =array(1=>'询价待处理',2=>"订单进度",3=>"调价待处理",4=>"查勘待派单",5=>"查勘待跟进",6=>"报告待制作",7=>"报告待审核",8=>"工作流待处理",9=>"工作流进度");
|
||
private $message_type =array(1=>'询价待处理',2=>"订单进度",3=>"调价待处理",4=>"查勘待派单",5=>"查勘待跟进",6=>"报告待制作",
|
||
7=>"报告待审核",8=>"工作流待处理",9=>"工作流进度",10=>'询价待处理',11=>"订单进度",12=>"调价待处理",13=>"查勘待派单",
|
||
14=>"查勘待跟进",15=>"报告待制作",16=>"报告待审核",17=>"工作流待处理",18=>"工作流进度",18=>"查勘待跟进",19=>"报告待制作",
|
||
20=>"报告待审核",21=>"工作流待处理",22=>"工作流进度",23=>"查勘待跟进",24=>"报告待制作",25=>"报告待审核");
|
||
/**
|
||
* 获取信息列表
|
||
* @author cavan
|
||
*/
|
||
public function MessageRemindList()
|
||
{
|
||
if(empty($this->userInfo)){
|
||
return $this->buildFailed("登录已失效");
|
||
}
|
||
$Mdb = new Message();
|
||
|
||
$resultData=$Mdb->where(["status"=>1,"user_id"=>$this->userInfo['user_id']])
|
||
->order("create_time asc")
|
||
->field('*')
|
||
->select()
|
||
->toArray();
|
||
$data = array();
|
||
if(!empty($resultData)){
|
||
$inquiryPending = array();$OrderProgress = array();$ModifyPricePending = array();$SurveyWaitingList = array();$SurveyfollowUp = array();
|
||
$ReportProduced = array();$ReportReviewed = array();$WorkflowPending = array();$WorkflowProgress = array();
|
||
$inquiryPendingCount = $OrderProgressCount = $ModifyPricePendingCount = $SurveyWaitingListCount = $SurveyfollowUpCount = $ReportProducedCount = $ReportReviewedCount = $WorkflowPendingCount = $WorkflowProgressCount = 0;
|
||
$type_arr = array_unique(array_column($resultData,"type"));
|
||
if(!empty($type_arr)){
|
||
foreach ($type_arr as $k => $v){
|
||
foreach ($resultData as $kd => $vd){
|
||
$vd['create_time'] = date("Y-m-d H:i",strtotime($vd['create_time']));
|
||
if($v == $vd['type']){
|
||
if($v == 1){
|
||
$inquiryPending[] = $vd;
|
||
if($vd['issee'] == 2){
|
||
$inquiryPendingCount++;
|
||
}
|
||
}else if($v == 2){
|
||
if($vd['message_type'] == 11 || $vd['message_type'] == 31){ //报告已完成 报告完成时间不是当天的不显示
|
||
$completion_time = Db::name("report")
|
||
->where("quot_id",$vd['quot_id'])
|
||
->value("completion_time");
|
||
if($completion_time && date("Y-m-d",$completion_time) == date("Y-m-d",time())){
|
||
$OrderProgress[] = $vd;
|
||
if($vd['issee'] == 2){
|
||
$OrderProgressCount++;
|
||
}
|
||
}
|
||
}else{
|
||
$OrderProgress[] = $vd;
|
||
if($vd['issee'] == 2){
|
||
$OrderProgressCount++;
|
||
}
|
||
}
|
||
}else if($v == 3){
|
||
$ModifyPricePending[] = $vd;
|
||
if($vd['issee'] == 2){
|
||
$ModifyPricePendingCount++;
|
||
}
|
||
}else if($v == 4){
|
||
$SurveyWaitingList[] = $vd;
|
||
if($vd['issee'] == 2){
|
||
$SurveyWaitingListCount++;
|
||
}
|
||
}else if($v == 5){
|
||
$SurveyfollowUp[] = $vd;
|
||
if($vd['issee'] == 2){
|
||
$SurveyfollowUpCount++;
|
||
}
|
||
}else if($v == 6){
|
||
$ReportProduced[] = $vd;
|
||
if($vd['issee'] == 2){
|
||
$ReportProducedCount++;
|
||
}
|
||
}else if($v == 7){
|
||
$ReportReviewed[] = $vd;
|
||
if($vd['issee'] == 2){
|
||
$ReportReviewedCount++;
|
||
}
|
||
}else if($v == 8){
|
||
$WorkflowPending[] = $vd;
|
||
if($vd['issee'] == 2){
|
||
$WorkflowPendingCount++;
|
||
}
|
||
}else if($v == 9){
|
||
$WorkflowProgress[] = $vd;
|
||
if($vd['issee'] == 2){
|
||
$WorkflowProgressCount++;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$data['inquiryPending'] = $inquiryPending;
|
||
$data['OrderProgress'] = array_merge($this->arraySort(array_merge($OrderProgress),"create_time","desc"));
|
||
$data['ModifyPricePending'] = $ModifyPricePending;
|
||
$data['SurveyWaitingList'] = $SurveyWaitingList;
|
||
$data['SurveyfollowUp'] = $SurveyfollowUp;
|
||
$data['ReportProduced'] = $ReportProduced;
|
||
$data['ReportReviewed'] = $ReportReviewed;
|
||
$data['WorkflowPending'] = $WorkflowPending;
|
||
$data['WorkflowProgress'] = $WorkflowProgress;
|
||
$data['inquiryPendingCount'] = $inquiryPendingCount;
|
||
$data['OrderProgressCount'] = $OrderProgressCount;
|
||
$data['ModifyPricePendingCount'] = $ModifyPricePendingCount;
|
||
$data['SurveyWaitingListCount'] = $SurveyWaitingListCount;
|
||
$data['SurveyfollowUpCount'] = $SurveyfollowUpCount;
|
||
$data['ReportProducedCount'] = $ReportProducedCount;
|
||
$data['ReportReviewedCount'] = $ReportReviewedCount;
|
||
$data['WorkflowPendingCount'] = $WorkflowPendingCount;
|
||
$data['WorkflowProgressCount'] = $WorkflowProgressCount;
|
||
}
|
||
|
||
return $this->buildSuccess($data);
|
||
}
|
||
|
||
/**
|
||
* 消息已读调用方法
|
||
*
|
||
* @author cavan
|
||
*
|
||
* @param ids //信息表id字符串
|
||
*/
|
||
public function MessageRead(){
|
||
$ids = $this->request->post('ids', '', 'trim'); //信息表id
|
||
$relsut = array();
|
||
if(!$ids){
|
||
$Mdb = new Message();
|
||
$resultData=$Mdb->where(["status"=>1,"issee"=>2,"user_id"=>$this->userInfo['user_id']])
|
||
->field('id')
|
||
->select()
|
||
->toArray();
|
||
if(!empty($resultData)){
|
||
foreach ($resultData as $k => $v){
|
||
$relsut = MessageRead($v['id']);
|
||
}
|
||
}else{
|
||
return $this->buildSuccess();
|
||
}
|
||
}else{
|
||
$relsut = MessageRead($ids);
|
||
}
|
||
if($relsut && $relsut['code'] == 1){
|
||
return $this->buildSuccess();
|
||
}else {
|
||
return $this->buildFailed("操作成功");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* app消息写入方法
|
||
*
|
||
* @author cavan
|
||
*
|
||
* @param quot_id //询价主表id
|
||
* @param type //消息归属
|
||
* @param message_type //消息类型
|
||
* @param property_cert_info_id //物业表id
|
||
*/
|
||
public function publicMessage(){
|
||
$quot_id = $this->request->post('quot_id', '', 'trim'); //询价主表id
|
||
$type = $this->request->post('type', '', 'trim'); //消息归属
|
||
$message_type = $this->request->post('message_type', '', 'trim'); //消息类型
|
||
$property_cert_info_id = $this->request->post('property_cert_info_id', '', 'trim'); //物业表id
|
||
|
||
$relsut = PublicMessage($quot_id,$type,$message_type,$property_cert_info_id);
|
||
if($relsut['code'] == 1){
|
||
return $this->buildSuccess();
|
||
}else {
|
||
return $this->buildFailed($relsut['msg']);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 公告 / 传阅
|
||
*
|
||
* @author cavan
|
||
*
|
||
*/
|
||
public function Notice(){
|
||
if(empty($this->userInfo)){
|
||
return $this->buildFailed("登录已失效");
|
||
}
|
||
$Ndb = new Notice();
|
||
$Attachment = new Attachment(); //获取图片信息
|
||
|
||
$resultData1=$Ndb->where(["type"=>1])
|
||
->where("status",1)
|
||
->order(['update_time'=>'desc','create_time'=>'desc'])
|
||
->field('*')
|
||
->limit(5)
|
||
->select()
|
||
->toArray();
|
||
|
||
if(!empty($resultData1)){
|
||
foreach ($resultData1 as $k => $v){
|
||
//图片列表
|
||
$resultData1[$k]['fileslist'] = !empty($v['files'])?$Attachment->getUrls($v['files']):array();
|
||
}
|
||
}
|
||
|
||
$user_id = $this->userInfo['user_id'];
|
||
$resultData2=$Ndb->where(["type"=>2])
|
||
->where('FIND_IN_SET(:uid,relevant_personnel_ids)',['uid' => $user_id])
|
||
->where("status",1)
|
||
->order(['update_time'=>'desc','create_time'=>'desc'])
|
||
->field('*')
|
||
->limit(5)
|
||
->select()
|
||
->toArray();
|
||
|
||
if(!empty($resultData2)){
|
||
foreach ($resultData2 as $k => $v){
|
||
//图片列表
|
||
$resultData2[$k]['fileslist'] = !empty($v['files'])?$Attachment->getUrls($v['files']):array();
|
||
$resultData2[$k]['propertyDetails'] = Db::name("notice_reply")->where("notice_id",$v['id'])->field("*")->select();
|
||
}
|
||
}
|
||
|
||
$data['Notice'] = $resultData1;
|
||
$data['Circulation'] = $resultData2;
|
||
|
||
return $this->buildSuccess($data);
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取信息列表最新 10条
|
||
* @author cavan
|
||
*/
|
||
public function MessageRemindAll()
|
||
{
|
||
$min_id = $this->request->post('min_id', '', 'trim'); //分页
|
||
if(empty($this->userInfo)){
|
||
return $this->buildFailed("登录已失效");
|
||
}
|
||
$Mdb = new Message();
|
||
$where = array();
|
||
$where[] = ["status","=",1];
|
||
$where[] = ["user_id","=",$this->userInfo['user_id']];
|
||
if($min_id){
|
||
$where[] = ["id","<",$min_id];
|
||
}
|
||
$resultData=$Mdb->where($where)
|
||
->order(['issee'=>'desc','id'=>'desc'])
|
||
->field('*')
|
||
->limit(10)
|
||
->select()
|
||
->toArray();
|
||
$issee_num = $Mdb->where(["status"=>1,'issee'=>2,"user_id"=>$this->userInfo['user_id']])->count();
|
||
if(!empty($resultData)){
|
||
foreach ($resultData as $kd => $vd){
|
||
$resultData[$kd]['create_time'] = date("Y-m-d H:i",strtotime($vd['create_time']));
|
||
if($vd['type'] == 1){
|
||
$resultData[$kd]['messageType'] = "inquiryPending";
|
||
}else if($vd['type'] == 2){
|
||
if($vd['message_type'] == 11 || $vd['message_type'] == 31){ //报告已完成 报告完成时间不是当天的不显示
|
||
$completion_time = Db::name("report")
|
||
->where("quot_id",$vd['quot_id'])
|
||
->value("completion_time");
|
||
if(!$completion_time || ($completion_time && date("Y-m-d",$completion_time) != date("Y-m-d",time()))){
|
||
unset($resultData[$kd]);
|
||
}else{
|
||
$resultData[$kd]['messageType'] = "OrderProgress";
|
||
}
|
||
}else{
|
||
$resultData[$kd]['messageType'] = "OrderProgress";
|
||
}
|
||
}else if($vd['type'] == 3){
|
||
$resultData[$kd]['messageType'] = "ModifyPricePending";
|
||
}else if($vd['type'] == 4){
|
||
$resultData[$kd]['messageType'] = "SurveyWaitingList";
|
||
}else if($vd['type'] == 5){
|
||
$resultData[$kd]['messageType'] = "SurveyfollowUp";
|
||
}else if($vd['type'] == 6){
|
||
$resultData[$kd]['messageType'] = "ReportProduced";
|
||
}else if($vd['type'] == 7){
|
||
$resultData[$kd]['messageType'] = "ReportReviewed";
|
||
}else if($vd['type'] == 8){
|
||
$resultData[$kd]['messageType'] = "WorkflowPending";
|
||
}else if($vd['type'] == 9){
|
||
$resultData[$kd]['messageType'] = "WorkflowProgress";
|
||
}
|
||
}
|
||
}
|
||
$data = array();
|
||
$data['issee_num'] = $issee_num;
|
||
$data['list'] = array_merge($resultData);
|
||
|
||
return $this->buildSuccess($data);
|
||
}
|
||
|
||
/**
|
||
* 消息推送
|
||
*
|
||
*/
|
||
public function messagePush(){
|
||
ignore_user_abort(TRUE); //如果客户端断开连接,不会引起脚本abort
|
||
set_time_limit(0); //取消脚本执行延时上限
|
||
|
||
$request = Request::instance();
|
||
$par = $request->param();
|
||
$par = json_decode(urldecode($par['query']), true);
|
||
if(!empty($par)){
|
||
$res = sendMessage($par['user_id'],$par['message_content']);
|
||
Log::write("参数:".json_encode($par)."--返回:".$res,'workermanmsg');
|
||
}
|
||
}
|
||
|
||
//数组排序
|
||
function arraySort($array,$keys,$sort='asc') {
|
||
$newArr = $valArr = array();
|
||
foreach ($array as $key=>$value) {
|
||
$valArr[$key] = $value[$keys];
|
||
}
|
||
($sort == 'asc') ? asort($valArr) : arsort($valArr);
|
||
reset($valArr);
|
||
foreach($valArr as $key=>$value) {
|
||
$newArr[$key] = $array[$key];
|
||
}
|
||
return $newArr;
|
||
}
|
||
}
|