|
|
@@ -2,9 +2,12 @@
|
|
|
namespace app\workerapi\logic;
|
|
|
use app\common\enum\YesNoEnum;
|
|
|
use app\common\logic\BaseLogic;
|
|
|
+use app\common\model\article\Article;
|
|
|
use app\common\model\dict\DictData;
|
|
|
use app\common\model\dict\DictType;
|
|
|
+use app\common\model\master_worker\MasterWorkerAccountLog;
|
|
|
use app\common\model\master_worker_message\MasterWorkerMessage;
|
|
|
+use app\common\model\works\ServiceWorkLog;
|
|
|
|
|
|
/**
|
|
|
* @author 林海涛
|
|
|
@@ -12,6 +15,14 @@ use app\common\model\master_worker_message\MasterWorkerMessage;
|
|
|
*/
|
|
|
class MasterWorkerMessageLogic extends BaseLogic
|
|
|
{
|
|
|
+ public static $msgConfigArr = [
|
|
|
+ //工单
|
|
|
+ ['img_url' => 'https://weixiu.zhongdunzhizhao.com/static/wxapp/master_image/1.png', 'value' => 1],
|
|
|
+ //资金
|
|
|
+ ['img_url' => 'https://weixiu.zhongdunzhizhao.com/static/wxapp/master_image/3.png', 'value' => 3],
|
|
|
+ //重要公告
|
|
|
+ ['img_url' => 'https://weixiu.zhongdunzhizhao.com/static/wxapp/master_image/4.png', 'value' => 4],
|
|
|
+ ];
|
|
|
/**
|
|
|
* 统计各种类型的未读消息总数
|
|
|
* @return array
|
|
|
@@ -23,6 +34,8 @@ class MasterWorkerMessageLogic extends BaseLogic
|
|
|
*/
|
|
|
public static function msgStatistics($userId)
|
|
|
{
|
|
|
+
|
|
|
+ $msgConfigArr = array_column(self::$msgConfigArr,null,'value');
|
|
|
//查询字典值
|
|
|
$dictData = DictData::where('type_value','worker_notify_message_type')
|
|
|
->field('id,value,name')
|
|
|
@@ -30,25 +43,81 @@ class MasterWorkerMessageLogic extends BaseLogic
|
|
|
->order(['sort'=>'desc'])
|
|
|
->select()
|
|
|
->toArray();
|
|
|
- $msgTypeArr = array_column($dictData,'value');
|
|
|
- $msgStatisTicsObj = MasterWorkerMessage::field('msg_type,count(*) as count')
|
|
|
- ->where('show_type',YesNoEnum::NO)
|
|
|
- ->whereIn('msg_type',$msgTypeArr)
|
|
|
- ->where('worker_id',$userId)
|
|
|
- ->group('msg_type')
|
|
|
- ->select();
|
|
|
- foreach($dictData as $k => $v){
|
|
|
- $val = $msgStatisTicsObj->where('msg_type',$v['value'])->first();
|
|
|
- $v['total'] = $val->count?? 0;
|
|
|
- $dictData[$k] = $v;
|
|
|
- }
|
|
|
+ foreach($dictData as &$val){
|
|
|
+ $val['date'] = date('Y-m-d');
|
|
|
+ $val['title'] = '';
|
|
|
+ $val['total'] = 0;
|
|
|
+ if(isset($msgConfigArr[$val['value']])){
|
|
|
+ $val['img_url'] = $msgConfigArr[$val['value']]['img_url'];
|
|
|
+ switch ($val['value']){
|
|
|
+ case 1:
|
|
|
+ $val['total'] = ServiceWorkLog::where(['master_worker_id'=>$userId,'show_type'=>YesNoEnum::NO])->count();
|
|
|
+ if($val['total']){
|
|
|
+ $log = ServiceWorkLog::where(['master_worker_id'=>$userId,'show_type'=>YesNoEnum::NO])->order(['id'=>'desc'])->find()->toArray();
|
|
|
+ $log = self::formatMsg($log,1);
|
|
|
+ $val['title'] = $log['title'];
|
|
|
+ $val['date'] = $log['date'];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ $val['total'] = MasterWorkerAccountLog::where(['worker_id'=>$userId,'show_type'=>YesNoEnum::NO ] )->count();
|
|
|
+ if($val['total']){
|
|
|
+ $log = MasterWorkerAccountLog::where(['worker_id'=>$userId,'show_type'=>YesNoEnum::NO])->append(['action_text'])->order(['id'=>'desc'])->find()->toArray();
|
|
|
+ $log = self::formatMsg($log,3);
|
|
|
+ $val['title'] = $log['title'];
|
|
|
+ $val['date'] = $log['date'];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $val['total'] = Article::where(['is_show'=>YesNoEnum::YES])->count();
|
|
|
+ if($val['total']){
|
|
|
+ $log = Article::where('is_show',YesNoEnum::YES)->order(['id'=>'desc'])->find()->toArray();
|
|
|
+ $log = self::formatMsg($log,4);
|
|
|
+ $val['title'] = $log['title'];
|
|
|
+ $val['date'] = $log['date'];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return $dictData;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 格式化描述信息
|
|
|
+ * @param $item
|
|
|
+ * @param $type
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public static function formatMsg($item,$type){
|
|
|
+ switch ($type){
|
|
|
+ case 1:
|
|
|
+ $item['title'] = $item['opera_log'];
|
|
|
+ $item['describe'] = $item['opera_log'];
|
|
|
+ $item['date'] =date("Y-m-d", is_string($item['create_time']) ? strtotime($item['create_time']): $item['create_time']);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ $item['describe'] = $item['title'] . ' ' . $item['action_text'] . ' '. $item['change_amount'];
|
|
|
+ $item['title'] = $item['describe'];
|
|
|
+ $item['date'] =date("Y-m-d", is_string($item['create_time']) ? strtotime($item['create_time']): $item['create_time']);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $item['describe'] = $item['desc'];
|
|
|
+ $item['date'] =date("Y-m-d", is_string($item['create_time']) ? strtotime($item['create_time']): $item['create_time']);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return $item;
|
|
|
+ }
|
|
|
public static function showMsg($params,$userId)
|
|
|
{
|
|
|
- return MasterWorkerMessage::whereIn('id',$params['ids'])
|
|
|
- ->where('worker_id',$userId)
|
|
|
- ->update(['show_type'=>YesNoEnum::YES]);
|
|
|
+ switch($params['msg_type']){
|
|
|
+ case 1:
|
|
|
+ ServiceWorkLog::where(['master_worker_id'=>$userId,'show_type'=>YesNoEnum::NO])->whereIn('id',$params['ids'])->update(['show_type'=>YesNoEnum::YES]);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ MasterWorkerAccountLog::where(['worker_id'=>$userId,'show_type'=>YesNoEnum::NO ] )->whereIn('id',$params['ids'])->update(['show_type'=>YesNoEnum::YES]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|