1
0

MasterWorkerMessageLogic.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\workerapi\logic;
  3. use app\common\enum\YesNoEnum;
  4. use app\common\logic\BaseLogic;
  5. use app\common\model\article\Article;
  6. use app\common\model\dict\DictData;
  7. use app\common\model\dict\DictType;
  8. use app\common\model\master_worker\MasterWorkerAccountLog;
  9. use app\common\model\master_worker_message\MasterWorkerMessage;
  10. use app\common\model\works\ServiceWorkLog;
  11. /**
  12. * @author 林海涛
  13. * @date 2024/7/11 下午5:39
  14. */
  15. class MasterWorkerMessageLogic extends BaseLogic
  16. {
  17. public static $msgConfigArr = [
  18. //工单
  19. ['img_url' => 'https://weixiu.zhongdunzhizhao.com/static/wxapp/master_image/1.png', 'value' => 1],
  20. //资金
  21. ['img_url' => 'https://weixiu.zhongdunzhizhao.com/static/wxapp/master_image/3.png', 'value' => 3],
  22. //重要公告
  23. ['img_url' => 'https://weixiu.zhongdunzhizhao.com/static/wxapp/master_image/4.png', 'value' => 4],
  24. ];
  25. /**
  26. * 统计各种类型的未读消息总数
  27. * @return array
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. * @author 林海涛
  32. * @date 2024/7/11 下午5:43
  33. */
  34. public static function msgStatistics($userId)
  35. {
  36. $msgConfigArr = array_column(self::$msgConfigArr,null,'value');
  37. //查询字典值
  38. $dictData = DictData::where('type_value','worker_notify_message_type')
  39. ->field('id,value,name')
  40. ->where('status',YesNoEnum::YES)
  41. ->order(['sort'=>'desc'])
  42. ->select()
  43. ->toArray();
  44. foreach($dictData as &$val){
  45. $val['date'] = date('Y-m-d');
  46. $val['title'] = '';
  47. $val['total'] = 0;
  48. if(isset($msgConfigArr[$val['value']])){
  49. $val['img_url'] = $msgConfigArr[$val['value']]['img_url'];
  50. switch ($val['value']){
  51. case 1:
  52. $val['total'] = ServiceWorkLog::where(['master_worker_id'=>$userId,'show_type'=>YesNoEnum::NO])->count();
  53. if($val['total']){
  54. $log = ServiceWorkLog::where(['master_worker_id'=>$userId,'show_type'=>YesNoEnum::NO])->order(['id'=>'desc'])->find()->toArray();
  55. $log = self::formatMsg($log,1);
  56. $val['title'] = $log['title'];
  57. $val['date'] = $log['date'];
  58. }
  59. break;
  60. case 3:
  61. $val['total'] = MasterWorkerAccountLog::where(['worker_id'=>$userId,'show_type'=>YesNoEnum::NO ] )->count();
  62. if($val['total']){
  63. $log = MasterWorkerAccountLog::where(['worker_id'=>$userId,'show_type'=>YesNoEnum::NO])->append(['action_text'])->order(['id'=>'desc'])->find()->toArray();
  64. $log = self::formatMsg($log,3);
  65. $val['title'] = $log['title'];
  66. $val['date'] = $log['date'];
  67. }
  68. break;
  69. case 4:
  70. $val['total'] = Article::where(['is_show'=>YesNoEnum::YES])->count();
  71. if($val['total']){
  72. $log = Article::where('is_show',YesNoEnum::YES)->order(['id'=>'desc'])->find()->toArray();
  73. $log = self::formatMsg($log,4);
  74. $val['title'] = $log['title'];
  75. $val['date'] = $log['date'];
  76. }
  77. break;
  78. }
  79. }
  80. }
  81. return $dictData;
  82. }
  83. /**
  84. * 格式化描述信息
  85. * @param $item
  86. * @param $type
  87. * @return mixed
  88. */
  89. public static function formatMsg($item,$type){
  90. switch ($type){
  91. case 1:
  92. $item['title'] = $item['opera_log'];
  93. $item['describe'] = $item['opera_log'];
  94. $item['date'] =date("Y-m-d", is_string($item['create_time']) ? strtotime($item['create_time']): $item['create_time']);
  95. break;
  96. case 3:
  97. $item['describe'] = $item['title'] . ' ' . $item['action_text'] . ' '. $item['change_amount'];
  98. $item['title'] = $item['describe'];
  99. $item['date'] =date("Y-m-d", is_string($item['create_time']) ? strtotime($item['create_time']): $item['create_time']);
  100. break;
  101. case 4:
  102. $item['describe'] = $item['desc'];
  103. $item['date'] =date("Y-m-d", is_string($item['create_time']) ? strtotime($item['create_time']): $item['create_time']);
  104. break;
  105. }
  106. return $item;
  107. }
  108. public static function showMsg($params,$userId)
  109. {
  110. switch($params['msg_type']){
  111. case 1:
  112. ServiceWorkLog::where(['master_worker_id'=>$userId,'show_type'=>YesNoEnum::NO])->whereIn('id',$params['ids'])->update(['show_type'=>YesNoEnum::YES]);
  113. break;
  114. case 3:
  115. MasterWorkerAccountLog::where(['worker_id'=>$userId,'show_type'=>YesNoEnum::NO ] )->whereIn('id',$params['ids'])->update(['show_type'=>YesNoEnum::YES]);
  116. break;
  117. }
  118. return true;
  119. }
  120. }