MasterWorkerMessageLogic.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\workerapi\logic;
  3. use app\common\enum\YesNoEnum;
  4. use app\common\logic\BaseLogic;
  5. use app\common\model\dict\DictData;
  6. use app\common\model\dict\DictType;
  7. use app\common\model\master_worker_message\MasterWorkerMessage;
  8. /**
  9. * @author 林海涛
  10. * @date 2024/7/11 下午5:39
  11. */
  12. class MasterWorkerMessageLogic extends BaseLogic
  13. {
  14. /**
  15. * 统计各种类型的未读消息总数
  16. * @return array
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\DbException
  19. * @throws \think\db\exception\ModelNotFoundException
  20. * @author 林海涛
  21. * @date 2024/7/11 下午5:43
  22. */
  23. public static function msgStatistics($userId)
  24. {
  25. //查询字典值
  26. $dictData = DictData::where('type_value','worker_notify_message_type')
  27. ->field('id,value,name')
  28. ->where('status',YesNoEnum::YES)
  29. ->order(['sort'=>'desc'])
  30. ->select()
  31. ->toArray();
  32. $msgTypeArr = array_column($dictData,'value');
  33. $msgStatisTicsObj = MasterWorkerMessage::field('msg_type,count(*) as count')
  34. ->where('show_type',YesNoEnum::NO)
  35. ->whereIn('msg_type',$msgTypeArr)
  36. ->where('user_id',$userId)
  37. ->group('msg_type')
  38. ->select();
  39. foreach($dictData as $k => $v){
  40. $val = $msgStatisTicsObj->where('msg_type',$v['value'])->first();
  41. $v['total'] = $val->count?? 0;
  42. $dictData[$k] = $v;
  43. }
  44. return $dictData;
  45. }
  46. public static function showMsg($params,$userId)
  47. {
  48. return MasterWorkerMessage::whereIn('id',$params['ids'])
  49. ->where('user_id',$userId)
  50. ->update(['show_type'=>YesNoEnum::YES]);
  51. }
  52. }