106 lines
2.9 KiB
PHP
106 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace member\modules\v1\controllers;
|
|
|
|
use common\core\BaseAppController;
|
|
use common\enums\UserRoleEnum;
|
|
use common\enums\UserStatusEnum;
|
|
use common\models\oldDb\ImMessageSession;
|
|
use common\models\oldDb\LeadInfo;
|
|
use common\models\oldDb\ReplayTemplateGroup;
|
|
use common\models\oldDb\ServiceUser;
|
|
use yii\db\Exception;
|
|
|
|
/**
|
|
* @doc-module 导医咨询
|
|
*/
|
|
class LeadConsultController extends BaseAppController
|
|
{
|
|
// public $optional=['default-info'];
|
|
/**
|
|
* @doc-name 导医默认回复信息
|
|
*/
|
|
public function actionDefaultInfo()
|
|
{
|
|
|
|
$lead_ids=ServiceUser::find()->select('id')->where([
|
|
'role'=>UserRoleEnum::LEADER,
|
|
'is_delete'=>0,
|
|
'status'=>UserStatusEnum::OK
|
|
])->orderBy('id desc')->column();
|
|
$count=ServiceUser::find()->where([
|
|
'role'=>UserRoleEnum::LEADER,
|
|
'is_delete'=>0,
|
|
'status'=>UserStatusEnum::OK
|
|
])->count();
|
|
|
|
$ids=ReplayTemplateGroup::find()->where([
|
|
'in','su_id',$lead_ids,
|
|
])->with(['templates'=>function($t){
|
|
$t->orderBy('sort asc');
|
|
}])->asArray()->all();
|
|
|
|
$cache_key='user_id:'.\Yii::$app->user->identity->getId();
|
|
$cacheData =\Yii::$app->cache->get($cache_key);
|
|
|
|
$several=$cacheData?$cacheData-1:$count;
|
|
\Yii::$app->cache->set($cache_key,$several);
|
|
|
|
if ($several>0){
|
|
return $ids[$several-1];
|
|
}else{
|
|
return ['欢迎进行导医咨询'];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @doc-name 导医聊天创建会话
|
|
* @doc-return int ims_id 会话id
|
|
*/
|
|
public function actionGetLead()
|
|
{
|
|
$lead_id=LeadInfo::getLastLeadUserId();//空闲导医
|
|
|
|
$ims = new ImMessageSession();
|
|
$ims->user_id = \Yii::$app->user->identity->id;
|
|
$ims->type = 3;//用户导医
|
|
$ims->service_id=$lead_id['id'];
|
|
$ims->saveOrFail();
|
|
|
|
$lead= \Yii::$app->db->getLastInsertID();
|
|
return ['ims_id'=>$lead];
|
|
}
|
|
|
|
/**
|
|
* @doc-name 结束导医会话
|
|
* @doc-param int ims_id 会话id
|
|
* @doc-param int service_id 导医id
|
|
*/
|
|
public function actionOverIms()
|
|
{
|
|
$post=\Yii::$app->request->post();
|
|
$this->requestValidate($post,[
|
|
[['ims_id','service_id'],'required']
|
|
]);
|
|
|
|
$Ims=ImMessageSession::find()->where([
|
|
'id'=>$post['ims_id'],
|
|
'user_id'=>\Yii::$app->user->identity->id,
|
|
'service_id'=>$post['service_id'],
|
|
'type'=>3,
|
|
'status'=>0,
|
|
'is_delete'=>0
|
|
])->one();
|
|
if (!$Ims) throw new Exception('会话不存在或会话已结束');
|
|
|
|
ImMessageSession::updateAll(['status'=>10],[
|
|
'id'=>$post['ims_id'],
|
|
'user_id'=>\Yii::$app->user->identity->id,
|
|
'service_id'=>$post['service_id'],
|
|
'is_delete'=>0
|
|
]);
|
|
|
|
return ['会话已结束'];
|
|
}
|
|
|
|
} |