'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 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 林海涛 * @date 2024/7/11 下午5:43 */ 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') ->where('status',YesNoEnum::YES) ->order(['sort'=>'desc']) ->select() ->toArray(); 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) { 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; } public static function orderPrompt($userId) { $count = ServiceWork::where(['master_worker_id'=>$userId,'work_status'=> 1] )->count('id'); return $count?:false; } }