MasterWorkerMessageLogic.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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();
  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();
  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,'cid'=>3])->order(['id'=>'desc'])->find();
  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'] = !empty($item['opera_log'])?$item['opera_log']:"";
  94. $item['describe'] = !empty($item['opera_log'])?$item['opera_log']:"";
  95. $item['date'] = !empty($item['create_time'])?date("Y-m-d", is_string($item['create_time']) ? strtotime($item['create_time']): $item['create_time']):date('Y-m-d');
  96. break;
  97. case 3:
  98. $item['describe'] = !empty($item['title'])?$item['title'] . ' ' . $item['action_text'] . ' '. $item['change_amount']:'';
  99. $item['title'] = !empty($item['describe'])?$item['describe']:'';
  100. $item['date'] =!empty($item['create_time'])?date("Y-m-d", is_string($item['create_time']) ? strtotime($item['create_time']): $item['create_time']):date('Y-m-d');
  101. break;
  102. case 4:
  103. $item['title'] = !empty($item['describe'])?$item['describe']:'';
  104. $item['describe'] = !empty($item['desc'])?$item['desc']:'';
  105. $item['date'] =!empty($item['create_time'])?date("Y-m-d", is_string($item['create_time']) ? strtotime($item['create_time']): $item['create_time']):date('Y-m-d');
  106. break;
  107. }
  108. return $item;
  109. }
  110. public static function showMsg($params,$userId)
  111. {
  112. switch($params['msg_type']){
  113. case 1:
  114. ServiceWorkLog::where(['master_worker_id'=>$userId,'show_type'=>YesNoEnum::NO])->whereIn('id',$params['ids'])->update(['show_type'=>YesNoEnum::YES]);
  115. break;
  116. case 3:
  117. MasterWorkerAccountLog::where(['worker_id'=>$userId,'show_type'=>YesNoEnum::NO ] )->whereIn('id',$params['ids'])->update(['show_type'=>YesNoEnum::YES]);
  118. break;
  119. }
  120. return true;
  121. }
  122. /**
  123. * @param $userId
  124. * @return array
  125. * @throws \think\db\exception\DataNotFoundException
  126. * @throws \think\db\exception\DbException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. */
  129. public static function orderPrompt($userId)
  130. {
  131. $where = [
  132. 'master_worker_id'=>$userId,
  133. 'approval'=>1,//派单的时候默认审核了
  134. 'work_status'=>1,
  135. ];
  136. return ServiceWork::where($where)
  137. ->where('work_pay_status','>',0)
  138. ->field(['id', 'work_sn','real_name','mobile', 'address', 'title', 'work_status', 'service_status','work_pay_status', 'appointment_time','receive_time','base_service_fee','service_fee'])
  139. ->append(['work_status_text','service_status_text'])
  140. ->order(['appointment_time' => 'asc'])//上门时间排序
  141. ->select()
  142. ->toArray();
  143. }
  144. }