1
0

MasterWorkerMessageLogic.php 5.5 KB

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