Files
xk-api-yii/member/modules/v1/controllers/SystemNoticeController.php

409 lines
16 KiB
PHP

<?php
namespace member\modules\v1\controllers;
use common\core\BaseAppController;
use common\enums\OrderAcceptEnum;
use common\enums\SystemNoticeTypeEnum;
use common\helpers\FuncHelper;
use common\models\oldDb\DoctorInfo;
use common\models\oldDb\ImMessage;
use common\models\oldDb\Order;
use common\models\oldDb\SystemNotice;
use yii\base\Exception;
use yii\helpers\Json;
/**
* @doc-module 系统通知
*/
class SystemNoticeController extends BaseAppController
{
/**
* @doc-name 消息
*/
public function actionIndex(){
$systemNotice = SystemNotice::find()->where([
'or',
[
'and',
['store_id' => \Yii::$app->request->get()['store_id']],
['scene_type' => 1],
['user_id' => \Yii::$app->user->identity->id],
['in','base_type',[3,4,5]],
['read_status' => 0]
],
[
'and',
['scene_type' => 1],
['base_type' => 99],
// ['user_id' => \Yii::$app->user->identity->id],
['read_status' => 0]
]
])->select('notice_at')->orderBy('notice_at DESC')->asArray()->all();
$orderNotice = SystemNotice::find()->where([
'store_id' => \Yii::$app->request->get()['store_id'],
'scene_type' => 1,
'user_id' => \Yii::$app->user->identity->id,
'base_type' => 1,
'read_status' => 0
])->select('notice_at')->orderBy('notice_at DESC')->asArray()->all();
$doctorNews = SystemNotice::find()->where([
'store_id' => \Yii::$app->request->get()['store_id'],
'scene_type' => 1,
'user_id' => \Yii::$app->user->identity->id,
'base_type' => 6,
'read_status' => 0
])->select('notice_at')->groupBy('notice_at')->orderBy('notice_at DESC')->asArray()->all();
$data = [];
if($systemNotice){
$data['system'] = [
'num' => count($systemNotice),
'time' =>$systemNotice[0]['notice_at']
];
}
if($orderNotice){
$data['order'] = [
'num' => count($orderNotice),
'time' => $orderNotice[0]['notice_at']
];
}
if($doctorNews){
$data['doctor_news'] = [
'num' => count($doctorNews),
'time' => $doctorNews[0]['notice_at']
];
}
return $data;
}
public function actionSystem(){
$query = SystemNotice::find()->where([
'or',
[
'and',
['store_id' => \Yii::$app->request->get()['store_id']],
['scene_type' => 1],
['user_id' => \Yii::$app->user->identity->id],
['in','base_type',[3,4,5,7]],
],
[
'and',
['scene_type' => 1],
['base_type' => 99],
// ['user_id' => \Yii::$app->user->identity->id]
]
])->select('id,data,content,url,url_type,read_status,base_type,notice_at')->orderBy('notice_at DESC');
return $this->create($query, \Yii::$app->request->get());
}
/**
* @doc-name 订单消息
*/
public function actionOrder(){
$query = SystemNotice::find()->where([
'store_id' => \Yii::$app->request->get()['store_id'],
'scene_type' => 1,
'user_id' => \Yii::$app->user->identity->id,
'base_type' => 1
])->select('id,data,content,url,url_type,read_status,base_type,notice_at')->orderBy('notice_at DESC');
return $this->create($query, \Yii::$app->request->get());
}
/**
* @doc-name 医生群发消息
*/
public function actionDoctorNews(){
$get=\Yii::$app->request->get();
$query = SystemNotice::find()->where([
'store_id' =>$get['store_id'],
'scene_type' => 1,
'user_id' => \Yii::$app->user->identity->id,
'base_type' => 6
])->orderBy('notice_at DESC');
$this->field = [
SystemNotice::class => [
'id','data','content'=>function($s){
$is_json= FuncHelper::is_not_null($s->content);
if (!$is_json){
return Json::decode($s->content);
}else{
return $s->content;
}
},'url_type','url','read_status','read_status','base_type','notice_at'
],
];
return $this->create($query, $get);
}
/**
* @doc-name 消息详情
*/
public function actionNewInfo()
{
$get = \Yii::$app->request->get();
$this->requestValidate($get,[
['id','required'],
]);
$SystemNotice=SystemNotice::find()->select('id,data,content,url,url_type,read_status,base_type,notice_at')->where(['id'=>$get['id']])->asArray()->one();
if (!$SystemNotice){
throw new \yii\db\Exception('消息不存在');
}
$is_json= FuncHelper::is_not_null($SystemNotice['content']);
if (!$is_json){
$SystemNotice['content']= Json::decode($SystemNotice['content']);
}
return $SystemNotice;
}
public function actionRead(){
$post = \Yii::$app->request->post();
$this->requestValidate($post,[
['type','required'],
['store_id','required']
]);
$type = $post['type'];
switch ($type) {
case 'all':
\Yii::$app->db->createCommand()->update(SystemNotice::tableName(), ['read_status' => '1'], 'read_status=0 AND scene_type=1 AND user_id='.\Yii::$app->user->identity->id/*.' AND store_id='.$post['store_id']*/)->execute();
\Yii::$app->db->createCommand()->update(SystemNotice::tableName(), ['read_status' => '1'], 'read_status=0 AND scene_type=1 AND base_type=99 AND user_id='.\Yii::$app->user->identity->id)->execute();
break;
case 'system':
\Yii::$app->db->createCommand()->update(SystemNotice::tableName(), ['read_status' => '1'], 'read_status=0 AND scene_type=1 AND (base_type=3 or base_type=4 or base_type=5 or base_type=7) AND user_id='.\Yii::$app->user->identity->id/*.' AND store_id='.$post['store_id']*/)->execute();
\Yii::$app->db->createCommand()->update(SystemNotice::tableName(), ['read_status' => '1'], 'read_status=0 AND scene_type=1 AND base_type=99 AND user_id='.\Yii::$app->user->identity->id)->execute();
break;
case 'order':
\Yii::$app->db->createCommand()->update(SystemNotice::tableName(), ['read_status' => '1'], 'read_status=0 AND scene_type=1 AND base_type=1 AND user_id='.\Yii::$app->user->identity->id/*.' AND store_id='.$post['store_id']*/)->execute();
break;
case 'doctor_news':
\Yii::$app->db->createCommand()->update(SystemNotice::tableName(), ['read_status' => '1'], 'read_status=0 AND scene_type=1 AND base_type=6 AND user_id='.\Yii::$app->user->identity->id/*.' AND store_id='.$post['store_id']*/)->execute();
break;
default:
throw new Exception('错误的type');
break;
}
return ['success'];
}
/**
* @doc-name 系统消息列表
* @doc-return mixed @Accept{text-string-主题,msg-string-消息,num-int-未读数量} 已接诊
* @doc-return mixed @Reminder{text-string-主题,msg-string-消息,num-int-未读数量} 温馨提示
* @doc-return mixed @OrderCancel{text-string-主题,msg-string-消息,num-int-未读数量} 订单取消
* @doc-return mixed @Refuse{text-string-主题,msg-string-消息,num-int-未读数量} 已拒诊
*/
public function actionList()
{
$doctor_accept='\u5df2\u63a5\u8bca';//已接诊
//最新一条内容
$order_cancel_content=SystemNotice::find()->select('content')->where([
'scene_type'=>1,//用户端
'user_id'=>\Yii::$app->user->identity->getId(),
'base_type'=>SystemNoticeTypeEnum::ORDER_CANCEL,
'read_status'=>0
])->orderBy('id desc')->one();
$reminder_content=SystemNotice::find()->select('content')->where([
'scene_type'=>1,//用户端
'user_id'=>\Yii::$app->user->identity->getId(),
'base_type'=>SystemNoticeTypeEnum::REMINDER,
'read_status'=>0
])->orderBy('id desc')->one();
$refuse_content=SystemNotice::find()->select('content')->where([
'scene_type'=>1,//用户端
'user_id'=>\Yii::$app->user->identity->getId(),
'base_type'=>SystemNoticeTypeEnum::REFUSE,
'read_status'=>0
])->orderBy('id desc')->one();
$refund_refuse_content=SystemNotice::find()->select('content')->where([
'scene_type'=>1,//用户端
'user_id'=>\Yii::$app->user->identity->getId(),
'base_type'=>SystemNoticeTypeEnum::REFUND_REFUSE,
'read_status'=>0
])->orderBy('id desc')->one();
//未读数量
$ORDER_CANCEL=SystemNotice::find()->where([
'scene_type'=>1,//用户端
'user_id'=>\Yii::$app->user->identity->getId(),
'base_type'=>SystemNoticeTypeEnum::ORDER_CANCEL,
'read_status'=>0
])->count();
$REFUSE=SystemNotice::find()->where([
'scene_type'=>1,//用户端
'user_id'=>\Yii::$app->user->identity->getId(),
'base_type'=>SystemNoticeTypeEnum::REFUSE,
'read_status'=>0
])->count();
$REMINDER=SystemNotice::find()->where([
'scene_type'=>1,//用户端
'user_id'=>\Yii::$app->user->identity->getId(),
'base_type'=>SystemNoticeTypeEnum::REMINDER,
'read_status'=>0
])->count();
$ImMessage= ImMessage::find()->select('content')->where([
'user_id'=>\Yii::$app->user->identity->getId(),//id 8
'read_status'=>0,
'type'=>1,
])->andWhere(['like','content',$doctor_accept])->count();
$REFUND_REFUSE=SystemNotice::find()->where([
'scene_type'=>1,//用户端
'user_id'=>\Yii::$app->user->identity->getId(),
'base_type'=>SystemNoticeTypeEnum::REFUND_REFUSE,
'read_status'=>0
])->count();
return [
'accept'=>[
'text'=>'医生已接诊',
'msg'=>'您好,医生已接诊了',
'num'=>$ImMessage
],
'reminder'=>[
'text'=>'温馨提示',
'msg'=>$reminder_content??'',
'num'=>$REMINDER
],
'orderCancel'=>[
'text'=>'订单已取消',
'msg'=>$order_cancel_content??'',
'num'=>$ORDER_CANCEL
],
'refuse'=>[
'text'=>'拒诊通知',
'msg'=>$refuse_content??'',
'num'=>$REFUSE
],
'refund_refuse'=>[
'text'=>'拒绝退款通知',
'msg'=>$refund_refuse_content??'',
'num'=>$REFUND_REFUSE
]
];
}
/**
* @doc-name 订单取消
* @doc-return mixed @List{name-string-店铺名,pic-string-图片,order-string-订单,cancel_time-int-取消时间} 信息
* @doc-return mixed @Pagination{total-int-总共数据,totalPage-int-总页数,pageSize-int-每页数据} 分页信息
*/
public function actionOrderCancel()
{
$post= \Yii::$app->request->post();
SystemNotice::updateAll(['read_status'=>1],[
'user_id'=>\Yii::$app->user->identity->getId(),
'scene_type'=>1,
'base_type'=>SystemNoticeTypeEnum::ORDER_CANCEL
]);
$query= Order::find()->where([
'user_id'=>\Yii::$app->user->identity->getId(),//id 18
'is_pay'=>1,
'cancel_status'=>1,
]);
$this->field=[
Order::class=>[
'name'=>function($m){
return '萧康医院';
},
'pic'=>function($q){
return 'https://yanydy.oss-cn-hangzhou.aliyuncs.com/uploads/20230216/0f2603ce881c9e25330d8b2d8bc0e36b.jpg';
},
'cancel_time',
'order'=>function($m){
$name= DoctorInfo::find()->select('name')->where([
'su_id'=>$m->su_id
])->one();
return $name['name'].'医生的药方订单';
},
]
];
return $this->create($query,$post);
}
/**
* @doc-name 已接诊
* @doc-return mixed @List{name-string-医生,avatar-string-头像,accept_status-int-是否接诊默认0无状态1待接诊2已接诊3已拒绝结束4正常结束5超时未接诊结束6未接诊主动取消结束,accept_time-int-接诊时间} 信息
* @doc-return mixed @Pagination{total-int-总共数据,totalPage-int-总页数,pageSize-int-每页数据} 分页信息
*/
public function actionAccept()
{
$post= \Yii::$app->request->post();
SystemNotice::updateAll(['read_status'=>1],[
'user_id'=>\Yii::$app->user->identity->getId(),
'scene_type'=>1,
'base_type'=>SystemNoticeTypeEnum::ACCEPT
]);
$query= Order::find()->where([
'user_id'=>\Yii::$app->user->identity->getId(),//id 18
'is_pay'=>1,
'cancel_status'=>0,
'accept_status'=>OrderAcceptEnum::ACCEPTING
]);
$this->field=[
Order::class=>[
'name'=>'serviceUser.docInfo.name',
'avatar'=>'serviceUser.docInfo.avatar',
'accept_time','accept_status',
]
];
return $this->create($query,$post);
}
/**
* @doc-name 已拒诊
* @doc-return mixed @List{name-string-医生,avatar-string-头像,accept_status-int-是否接诊默认0无状态1待接诊2已接诊3已拒绝结束4正常结束5超时未接诊结束6未接诊主动取消结束,refuse_time-int-拒诊时间} 信息
* @doc-return mixed @Pagination{total-int-总共数据,totalPage-int-总页数,pageSize-int-每页数据} 分页信息
*/
public function actionRefuse()
{
$post= \Yii::$app->request->post();
SystemNotice::updateAll(['read_status'=>1],[
'user_id'=>\Yii::$app->user->identity->getId(),
'scene_type'=>1,
'base_type'=>SystemNoticeTypeEnum::REFUSE
]);
$query= Order::find()->where([
'user_id'=>\Yii::$app->user->identity->getId(),//id 8
'is_pay'=>1,
'cancel_status'=>0,
'accept_status'=>OrderAcceptEnum::REFUSED
]);
$this->field=[
Order::class=>[
'name'=>'serviceUser.docInfo.name',
'avatar'=>'serviceUser.docInfo.avatar',
'accept_status','refuse_time',
]
];
return $this->create($query,$post);
}
/**
* @doc-name 温馨提示列表
* @doc-return mixed @SystemNotice{*} 详细信息
*/
public function actionReminder()
{
//已读
SystemNotice::updateAll(['read_status'=>1],[
'user_id'=>\Yii::$app->user->identity->getId(),
'scene_type'=>1,
'base_type'=>SystemNoticeTypeEnum::REMINDER
]);
return SystemNotice::find()->where([
'user_id'=>\Yii::$app->user->identity->getId(),//id 8
'scene_type'=>1,
'base_type'=>SystemNoticeTypeEnum::REMINDER
])->orderBy('id desc')->all();
}
}