Message.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. namespace addons\qingdong\controller;
  3. use addons\qingdong\model\Event;
  4. use addons\qingdong\model\ExamineRecord;
  5. use addons\qingdong\model\Message as MessageModel;
  6. use addons\qingdong\model\Notice;
  7. use addons\qingdong\model\ReceivablesPlan;
  8. use addons\qingdong\model\Record;
  9. /**
  10. * 通知接口
  11. */
  12. class Message extends StaffApi
  13. {
  14. protected $noNeedLogin = [];
  15. protected $noNeedRight = [];
  16. /**
  17. * 获取通知列表
  18. */
  19. public function getList()
  20. {
  21. $limit = input("limit/d", 10);
  22. $where = ['to_staff_id' => $this->auth->id ,'relation_type'=>['neq',MessageModel::EXAMINE_TYPE]];
  23. $records = MessageModel::where($where)->with(['fromStaff', 'examine'])->order('status asc,id desc')->paginate($limit);
  24. $this->success('请求成功', $records);
  25. }
  26. /**
  27. * 获取审批列表
  28. */
  29. public function getExamineRecord()
  30. {
  31. $limit = input("limit/d", 10);
  32. //合同审批,回款审批、业绩目标审批、办公审批 费用
  33. $relation_type = input('type');
  34. $status = input('status',0);
  35. if($status == 1){
  36. $status = array('in','2,3');
  37. }
  38. $ids = ExamineRecord::where(['relation_type' => $relation_type,
  39. 'status' => $status,
  40. 'check_staff_id' => $this->auth->id])->column('id');
  41. $where = ['to_staff_id' => $this->auth->id, 'relation_id' => ['in', $ids], 'relation_type' => MessageModel::EXAMINE_TYPE];
  42. $records = MessageModel::where($where)->with(['fromStaff', 'examine'])->order('status asc,id desc')->paginate($limit);
  43. $this->success('请求成功', $records);
  44. }
  45. /**
  46. * 获取审批通知详情
  47. */
  48. public function getExamineInfo()
  49. {
  50. $data = [
  51. ExamineRecord::CONTRACT_TYPE => ['count' => 0, 'msg' => '暂无消息'],
  52. ExamineRecord::CONSUME_TYPE => ['count' => 0, 'msg' => '暂无消息'],
  53. ExamineRecord::RECEIVABLES_TYPE => ['count' => 0, 'msg' => '暂无消息'],
  54. ExamineRecord::APPROVAL_TYPE => ['count' => 0, 'msg' => '暂无消息'],
  55. ExamineRecord::ACHIEVEMENT_TYPE => ['count' => 0, 'msg' => '暂无消息'],
  56. ExamineRecord::CARD_TYPE => ['count' => 0, 'msg' => '暂无消息'],
  57. ExamineRecord::LEAVE_TYPE => ['count' => 0, 'msg' => '暂无消息'],
  58. ];
  59. foreach ($data as $type=>$v) {
  60. $ids = ExamineRecord::where(['status' => 0, 'check_staff_id' => $this->auth->id,
  61. 'relation_type' => $type
  62. ])->column('id');
  63. $count = MessageModel::where(['to_staff_id' => $this->auth->id,'relation_id' => ['in', $ids],
  64. 'relation_type' => MessageModel::EXAMINE_TYPE])
  65. ->count();
  66. if ($count) {
  67. $msg = MessageModel::where(['to_staff_id' => $this->auth->id, 'relation_id' => ['in', $ids],
  68. 'relation_type' => MessageModel::EXAMINE_TYPE])
  69. ->order('id desc')
  70. ->value('content');
  71. $data[$type] = ['count' => $count, 'msg' => $msg];
  72. }
  73. }
  74. $this->success('请求成功', $data);
  75. }
  76. /**
  77. * 获取通知详情
  78. */
  79. public function getInfo()
  80. {
  81. $leadsCount = MessageModel::where(['to_staff_id' => $this->auth->id,
  82. 'relation_type' => ['neq', MessageModel::EXAMINE_TYPE], 'status' => 0])->count();
  83. if ($leadsCount > 0) {//其他提醒消息
  84. $leadsDetail = MessageModel::where([
  85. 'relation_type' => ['neq', MessageModel::EXAMINE_TYPE],
  86. 'to_staff_id' => $this->auth->id,
  87. 'status' => 0
  88. ])->order('id desc')->find();
  89. }
  90. $noticeWhere['read_staff_ids'] = ['not like', "%,{$this->auth->id},%"];
  91. $noticeCount = Notice::where($noticeWhere)->count();
  92. if ($noticeCount > 0) {
  93. $noticeDetail = Notice::where(['read_staff_ids' => ['not like', "%,{$this->auth->id},%"]])->order('id desc')->find();
  94. }
  95. $eventOne = Event::where([
  96. 'type' => 1,
  97. 'status' => ['in', [0, 1]],
  98. 'start_time' => ['lt', date('Y-m-d', strtotime('+1 day'))],
  99. 'staff_id|owner_staff_id' => $this->auth->id
  100. ])->count();
  101. //合同审批
  102. $contract = ExamineRecord::where([
  103. 'relation_type' => ExamineRecord::CONTRACT_TYPE,
  104. 'status' => 0,
  105. 'check_staff_id' => $this->auth->id
  106. ])->count();
  107. //回款审批
  108. $receivables = ExamineRecord::where([
  109. 'relation_type' => ExamineRecord::RECEIVABLES_TYPE,
  110. 'status' => 0,
  111. 'check_staff_id' => $this->auth->id
  112. ])->count();
  113. //费用审批
  114. $consume = ExamineRecord::where([
  115. 'relation_type' => ExamineRecord::CONSUME_TYPE,
  116. 'status' => 0,
  117. 'check_staff_id' => $this->auth->id
  118. ])->count();
  119. //业绩目标审批
  120. $achievement = ExamineRecord::where([
  121. 'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE,
  122. 'status' => 0,
  123. 'check_staff_id' => $this->auth->id
  124. ])->count();
  125. //办公审批
  126. $approval = ExamineRecord::where([
  127. 'relation_type' => ExamineRecord::APPROVAL_TYPE,
  128. 'status' => 0,
  129. 'check_staff_id' => $this->auth->id
  130. ])->count();
  131. //补卡审批
  132. $card = ExamineRecord::where([
  133. 'relation_type' => ExamineRecord::CARD_TYPE,
  134. 'status' => 0,
  135. 'check_staff_id' => $this->auth->id
  136. ])->count();
  137. //请假审批
  138. $leave = ExamineRecord::where([
  139. 'relation_type' => ExamineRecord::LEAVE_TYPE,
  140. 'status' => 0,
  141. 'check_staff_id' => $this->auth->id
  142. ])->count();
  143. $receivablesPlan = ReceivablesPlan::where([
  144. 'remind_date' => ['elt', date('Y-m-d')],
  145. 'status' => 0,
  146. 'owner_staff_id' => $this->auth->id
  147. ])->count();
  148. $eventsCount = Event::where([
  149. 'start_time' => ['lt', date('Y-m-d', strtotime('+1 day'))],
  150. 'end_time' => ['lt', date('Y-m-d', strtotime('+1 day'))],
  151. 'status' => ['in', [0, 1]],
  152. 'staff_id' => $this->auth->id,
  153. ])->count();
  154. $where['create_staff_id'] = $this->auth->id;
  155. $where['next_time'] = array(array('egt',date('Y-m-d 00:00:00')),array('lt',date('Y-m-d 23:59:59')));
  156. $where['follow_type'] = ['neq', '其它'];
  157. $where['status'] = 0;
  158. // 待跟进客户
  159. $where1['relation_type'] = 1;
  160. $customerlist = Record::where($where)->where($where1)->column('id');
  161. $customerlist1 = 0;
  162. if($customerlist){
  163. $whereExit['id'] = array('in',$customerlist);
  164. $whereExit['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  165. $customerlist1 = Record::where($whereExit)->count();
  166. }
  167. $customer = count($customerlist) - $customerlist1;
  168. //待跟进合同
  169. $where2['relation_type'] = 3;
  170. $contractlist = Record::where($where)->where($where2)->column('id');
  171. $contractlist1 = 0;
  172. if($contractlist){
  173. $whereExitC['id'] = array('in',$contractlist);
  174. $whereExitC['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  175. $contractlist1 = Record::where($whereExitC)->count();
  176. }
  177. $contracts = count($contractlist)-$contractlist1;
  178. //待跟进线索
  179. $where3['relation_type'] = 4;
  180. $leadlist = Record::where($where)->where($where3)->column('id');
  181. $leadlist1 = 0;
  182. if($leadlist){
  183. $whereExitL['id'] = array('in',$leadlist);
  184. $whereExitL['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  185. $leadlist1 = Record::where($whereExitL)->count();
  186. }
  187. $lead = count($leadlist)-$leadlist1;
  188. //待跟进联系人
  189. $where4['relation_type'] = 2;
  190. $contactslist = Record::where($where)->where($where4)->column('id');
  191. $contactslist1 = 0;
  192. if($contactslist1){
  193. $whereExitCs['id'] = array('in',$contactslist);
  194. $whereExitCs['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  195. $contactslist1 = Record::where($whereExitCs)->count();
  196. }
  197. $contacts = count($contactslist)-$contactslist1;
  198. //待跟进商机
  199. $where5['relation_type'] = 5;
  200. $businesslist = Record::where($where)->where($where5)->column('id');
  201. $businesslist1 = 0;
  202. if($businesslist1){
  203. $whereExitB['id'] = array('in',$businesslist);
  204. $whereExitB['next_time'] = array('gt',date('Y-m-d 23:59:59'));
  205. $businesslist1 = Record::where($whereExitB)->count();
  206. }
  207. $business = count($businesslist)-$businesslist1;
  208. //提醒消息
  209. $data = [
  210. 'leads' => ['count' => $leadsCount, 'msg' => $leadsDetail['content'] ?? '暂无消息'],//提醒消息
  211. 'examine' => ['count' => $contract + $receivables+$consume+$achievement+$approval+$card+$leave,
  212. 'msg' => '审批消息提醒'],//提醒消息
  213. 'notice' => ['count' => $noticeCount, 'msg' => $noticeDetail['title'] ?? '暂无消息'],//系统公告
  214. 'agent' => [
  215. 'count' => $eventOne + $receivablesPlan+ $customer + $contracts + $lead + $contacts + $business,
  216. 'msg' => '您有新的待办事项需要处理!'
  217. ],//待办事项
  218. 'task' => [
  219. 'count' => $eventsCount,
  220. 'msg' => '即将超时的任务提醒!'
  221. ],//超时任务
  222. 'total' => $leadsCount + $noticeCount + $eventOne + $contract + $receivables + $receivablesPlan + $eventsCount+ $customer + $contracts + $lead + $contacts + $business+$consume+$achievement+$approval+$card+$leave,
  223. 'userinfo' => $this->auth->getUserinfo()
  224. ];
  225. $this->success('请求成功', $data);
  226. }
  227. }