Log.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 工作日志
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\oa\controller;
  8. use app\admin\controller\ApiCommon;
  9. use app\oa\logic\LogLogic;
  10. use app\crm\logic\IndexLogic;
  11. use think\Hook;
  12. use think\Request;
  13. use app\admin\model\Message;
  14. use app\admin\model\Comment as CommentModel;
  15. use think\Db;
  16. class Log extends ApiCommon
  17. {
  18. /**
  19. * 用于判断权限
  20. * @permission 无限制
  21. * @allow 登录用户可访问
  22. * @other 其他根据系统设置
  23. **/
  24. public function _initialize()
  25. {
  26. $action = [
  27. 'permission' => [''],
  28. 'allow' => ['index', 'save', 'read', 'update', 'delete', 'commentsave',
  29. 'commentdel', 'setread', 'excelexport', 'newbulletin', 'overlog', 'activity', 'incompletelog',
  30. 'completelog',
  31. 'completestats',
  32. 'logbulletin',
  33. 'logwelcomespeech',
  34. 'commentlist',
  35. 'activitycount',
  36. 'activitylist',
  37. 'querylog',
  38. 'onebulletin',
  39. 'favourupdate'
  40. ]
  41. ];
  42. Hook::listen('check_auth', $action);
  43. $request = Request::instance();
  44. $a = strtolower($request->action());
  45. if (!in_array($a, $action['permission'])) {
  46. parent::_initialize();
  47. }
  48. $param = $this->param;
  49. $userInfo = $this->userInfo;
  50. $checkAction = ['update', 'delete'];
  51. if (in_array($a, $checkAction) && $param['log_id']) {
  52. $det = Db::name('OaLog')->where('log_id = ' . $param['log_id'])->find();
  53. $auth_user_ids = getSubUserId();
  54. if (($det['create_user_id'] != $userInfo['id']) && in_array($v['create_user_id'], $auth_user_ids)) {
  55. header('Content-Type:application/json; charset=utf-8');
  56. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  57. }
  58. }
  59. }
  60. /**commentSave
  61. * 日志列表
  62. * @return
  63. * @author Michael_xu
  64. */
  65. public function index()
  66. {
  67. $param = $this->param;
  68. $userInfo = $this->userInfo;
  69. $param['read_user_id'] = $userInfo['id'];
  70. $param['structure_ids'] = $param['structure_id'];
  71. $param['structure_id'] = $userInfo['structure_id'];
  72. $data = model('Log')->getDataList($param);
  73. return resultArray(['data' => $data]);
  74. }
  75. /**
  76. * 日志回复列表
  77. * @return \think\response\Json
  78. */
  79. public function commentList()
  80. {
  81. $param = $this->param;
  82. $TaskLogic = new LogLogic();
  83. $data = $TaskLogic->CommentList($param);
  84. return resultArray(['data' => $data]);
  85. }
  86. /**
  87. * 欢迎语
  88. * @return \think\response\Json
  89. */
  90. public function logWelcomeSpeech()
  91. {
  92. $TaskLogic = new LogLogic();
  93. $data = $TaskLogic->LogWelcomeSpeech();
  94. return resultArray(['data' => $data]);
  95. }
  96. /**
  97. * 日报完成情况
  98. * @return \think\response\Json
  99. */
  100. public function completeStats()
  101. {
  102. $param = $this->param;
  103. $userInfo = $this->userInfo;
  104. $param['user_id'] = $userInfo['id'];
  105. $param['read_user_id'] = $userInfo['id'];
  106. $param['structure_id'] = $userInfo['structure_id'];
  107. $TaskLogic = new LogLogic();
  108. $data = $TaskLogic->completeStats($param);
  109. return resultArray(['data' => $data]);
  110. }
  111. /**
  112. * 月完成情况
  113. * @return \think\response\Json
  114. */
  115. public function logBulletin()
  116. {
  117. $param = $this->param;
  118. $userInfo = $this->userInfo;
  119. $param['user_id'] = $userInfo['id'];
  120. $param['read_user_id'] = $userInfo['id'];
  121. $param['structure_id'] = $userInfo['structure_id'];
  122. $TaskLogic = new LogLogic();
  123. $data = $TaskLogic->logBulletin($param);
  124. return resultArray(['data' => $data]);
  125. }
  126. /**
  127. * 任务列表导出
  128. * @return \think\response\Json|void
  129. */
  130. public function excelExport()
  131. {
  132. $param = $this->param;
  133. $userInfo = $this->userInfo;
  134. $param['read_user_id'] = $userInfo['id'];
  135. $param['structure_id'] = $userInfo['structure_id'];
  136. $TaskLogic = new LogLogic();
  137. $data = $TaskLogic->excelExport($param);
  138. return $data;
  139. }
  140. /**
  141. * 跟进记录
  142. * @return \think\response\Json
  143. */
  144. public function activity()
  145. {
  146. $param = $this->param;
  147. $userInfo = $this->userInfo;
  148. $param['user_id'] = $userInfo['id'];
  149. $TaskLogic = new LogLogic();
  150. $data = $TaskLogic->activity($param);
  151. return resultArray(['data' => $data]);
  152. }
  153. /**
  154. * 已完成日志员工
  155. * @return \think\response\Json
  156. */
  157. public function completeLog()
  158. {
  159. $param = $this->param;
  160. $userInfo = $this->userInfo;
  161. $param['user_id'] = $userInfo['id'];
  162. $TaskLogic = new LogLogic();
  163. $data = $TaskLogic->completeLog($param);
  164. return resultArray(['data' => $data]);
  165. }
  166. /**
  167. * 未完成日志员工
  168. * @return \think\response\Json
  169. */
  170. public function inCompleteLog()
  171. {
  172. $param = $this->param;
  173. $userInfo = $this->userInfo;
  174. $param['user_id'] = $userInfo['id'];
  175. $TaskLogic = new LogLogic();
  176. $data = $TaskLogic->inCompleteLog($param);
  177. return resultArray(['data' => $data]);
  178. }
  179. /**
  180. * 未完成日志员工
  181. * @return \think\response\Json
  182. */
  183. public function oneBulletin()
  184. {
  185. $param = $this->param;
  186. $userInfo = $this->userInfo;
  187. $param['user_id'] = $userInfo['id'];
  188. $TaskLogic = new LogLogic();
  189. $data = $TaskLogic->oneBulletin($param);
  190. return resultArray(['data' => $data]);
  191. }
  192. /**
  193. * 标记已读
  194. * @return
  195. * @author Michael_xu
  196. */
  197. public function setread()
  198. {
  199. $param = $this->param;
  200. $userInfo = $this->userInfo;
  201. $user_id = $userInfo['id'];
  202. if (!$param['log_id']) {
  203. return resultArray(['error' => '参数错误']);
  204. }
  205. $where = [];
  206. $where['log_id'] = $param['log_id'];
  207. $resData = Db::name('OaLog')->where($where)->find();
  208. $read_user_ids = stringToArray($resData['read_user_ids']) ? array_merge(stringToArray($resData['read_user_ids']), array($user_id)) : array($user_id);
  209. $res = Db::name('OaLog')->where(['log_id' => $param['log_id']])->update(['read_user_ids' => arrayToString($read_user_ids)]);
  210. return resultArray(['data' => '操作成功']);
  211. }
  212. /**
  213. * 添加日志
  214. * @param
  215. * @return
  216. * @author Michael_xu
  217. */
  218. public function save()
  219. {
  220. $param = $this->param;
  221. $userInfo = $this->userInfo;
  222. $logModel = model('Log');
  223. $param['create_user_id'] = $userInfo['id'];
  224. $param['user_id']=$userInfo['id'];
  225. $param['create_user_name'] = $userInfo['realname'];
  226. $indexLogic = new LogLogic();
  227. $save = $indexLogic->oneBulletin($param);
  228. $param['save_customer'] = $save['data']['customerNum'];
  229. $param['save_business'] = $save['data']['businessNum'];
  230. $param['save_contract'] = $save['data']['contractNum'];
  231. $param['save_receivables'] = $save['data']['receivablesMoneyNum'];
  232. $param['save_activity'] = $save['data']['recordNum'];
  233. $res = $logModel->createData($param);
  234. if ($res) {
  235. $res['realname'] = $userInfo['realname'];
  236. $res['thumb_img'] = $userInfo['thumb_img'] ? getFullPath($userInfo['thumb_img']) : '';
  237. $data[] = $res;
  238. return resultArray(['data' => $data]);
  239. } else {
  240. return resultArray(['error' => $logModel->getError()]);
  241. }
  242. }
  243. /**
  244. * 日志详情
  245. * @param
  246. * @return
  247. * @author Michael_xu
  248. */
  249. public function read()
  250. {
  251. $param = $this->param;
  252. $userInfo = $this->userInfo;
  253. $logModel = model('Log');
  254. $data = $logModel->getDataById($param['id']);
  255. //权限判断
  256. $auth_user_ids = getSubUserId();
  257. if (!in_array($userInfo['id'], $auth_user_ids) && $data['create_user_id'] !== $userInfo['id'] && !in_array($userInfo['id'], stringToArray($data['send_user_ids']))) {
  258. header('Content-Type:application/json; charset=utf-8');
  259. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  260. }
  261. if (!$data) {
  262. return resultArray(['error' => $logModel->getError()]);
  263. }
  264. return resultArray(['data' => $data]);
  265. }
  266. /**
  267. * 编辑日志
  268. * @param
  269. * @return
  270. * @author Michael_xu
  271. */
  272. public function update()
  273. {
  274. $param = $this->param;
  275. $userInfo = $this->userInfo;
  276. $log_id = $param['log_id'];
  277. $param['user_id']=$userInfo['id'];
  278. $logModel = model('Log');
  279. if(!empty($param['is_relation'])){
  280. $indexLogic = new LogLogic();
  281. $save = $indexLogic->oneBulletin($param);
  282. $param['save_customer'] = $save['data']['customerNum'];
  283. $param['save_business'] = $save['data']['businessNum'];
  284. $param['save_contract'] = $save['data']['contractNum'];
  285. $param['save_receivables'] = $save['data']['receivablesMoneyNum'];
  286. $param['save_activity'] = $save['data']['recordNum'];
  287. }
  288. if ($log_id) {
  289. $dataInfo = db('oa_log')->where(['log_id' => $log_id])->find();
  290. //权限判断
  291. if ($dataInfo['create_user_id'] !== $userInfo['id']) {
  292. header('Content-Type:application/json; charset=utf-8');
  293. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  294. }
  295. $res = $logModel->updateDataById($param, $log_id);
  296. if ($res) {
  297. return resultArray(['data' => '编辑成功']);
  298. } else {
  299. return resultArray(['error' => $logModel->getError()]);
  300. }
  301. } else {
  302. return resultArray(['error' => '参数错误']);
  303. }
  304. }
  305. /**
  306. * 删除日志
  307. * @param
  308. * @return
  309. * @author Michael_xu
  310. */
  311. public function delete()
  312. {
  313. $param = $this->param;
  314. $userInfo = $this->userInfo;
  315. $log_id = $param['log_id'];
  316. $param['user_id']=$userInfo['id'];
  317. if ($log_id) {
  318. $dataInfo = db('oa_log')->where(['log_id' => $log_id])->find();
  319. $adminTypes = adminGroupTypes($userInfo['id']);
  320. //3天内的日志可删
  321. if (date('Ymd', $dataInfo['create_time']) < date('Ymd', (strtotime(date('Ymd', time())) - 86400 * 3)) && !in_array(1, $adminTypes)) {
  322. return resultArray(['error' => '已超3天,不能删除']);
  323. }
  324. //权限判断
  325. if ($dataInfo['create_user_id'] !== $userInfo['id'] && !in_array(1, $adminTypes)) {
  326. header('Content-Type:application/json; charset=utf-8');
  327. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  328. }
  329. $res = model('Log')->delDataById($param);
  330. if (!$res) {
  331. return resultArray(['error' => model('Log')->getError()]);
  332. }
  333. return resultArray(['data' => '删除成功']);
  334. } else {
  335. return resultArray(['error' => '参数错误']);
  336. }
  337. }
  338. /**
  339. * 日志评论添加
  340. * @param
  341. * @return
  342. * @author
  343. */
  344. public function commentSave()
  345. {
  346. $param = $this->param;
  347. $logmodel = model('Log');
  348. $commentmodel = new CommentModel();
  349. if ($param['log_id'] && $param['content']) {
  350. $userInfo = $this->userInfo;
  351. $param['user_id'] = $userInfo['id'];
  352. $param['type'] = 'oa_log';
  353. $param['type_id'] = $param['log_id'];
  354. $flag = $commentmodel->createData($param);
  355. $flag['create_time']=date('Y-m-d H:i:s',$flag['create_time']);
  356. if ($flag) {
  357. $logInfo = $logmodel->getDataById($param['log_id']);
  358. (new Message())->send(
  359. Message::LOG_REPLAY,
  360. [
  361. 'title' => $logInfo['title'],
  362. 'action_id' => $param['log_id']
  363. ],
  364. $logInfo['create_user_id']
  365. );
  366. // actionLog($param['log_id'],$logInfo['send_user_ids'],$logInfo['send_structure_ids'],'评论了日志');
  367. return resultArray(['data' => $flag]);
  368. } else {
  369. return resultArray(['error' => $commentmodel->getError()]);
  370. }
  371. } else {
  372. return resultArray(['error' => '参数错误']);
  373. }
  374. }
  375. /**
  376. * 日志评论删除 comment_id删除单个
  377. * @param
  378. * @return
  379. * @author
  380. */
  381. public function commentDel()
  382. {
  383. $param = $this->param;
  384. $logmodel = model('Log');
  385. if ($param['comment_id'] && $param['log_id']) {
  386. $det = Db::name('AdminComment')->where('comment_id = ' . $param['comment_id'])->find();
  387. $userInfo = $this->userInfo;
  388. if ($det) {
  389. if ($det['user_id'] != $userInfo['id']) {
  390. return resultArray(['error' => '没有删除权限']);
  391. }
  392. } else {
  393. return resultArray(['error' => '不存在或已删除']);
  394. }
  395. $model = new CommentModel();
  396. $temp['type'] = 2;
  397. $temp['type_id'] = $param['log_id'];
  398. $temp['comment_id'] = $param['comment_id'];
  399. $ret = $model->delDataById($param);
  400. if ($ret) {
  401. $logInfo = $logmodel->getDataById($param['log_id']);
  402. //actionLog($param['log_id'],$logInfo['send_user_ids'],$logInfo['send_structure_ids'],'删除了日志评论');
  403. return resultArray(['data' => '删除成功']);
  404. } else {
  405. return resultArray(['error' => $model->getError()]);
  406. }
  407. } else {
  408. return resultArray(['error' => '参数错误']);
  409. }
  410. }
  411. /**
  412. * 今日新增
  413. * @return \think\response\Json
  414. */
  415. public function newBulletin()
  416. {
  417. $param = $this->param;
  418. $userInfo = $this->userInfo;
  419. $param['user_id'] = $userInfo['id'];
  420. $TaskLogic = new LogLogic();
  421. $data = $TaskLogic->Bulletin($param);
  422. return resultArray(['data' => $data]);
  423. }
  424. /**
  425. * 查看以往日志
  426. * @return \think\response\Json
  427. */
  428. public function overLog()
  429. {
  430. $param = $this->param;
  431. $TaskLogic = new LogLogic();
  432. $data = $TaskLogic->lastLog($param);
  433. return resultArray(['data' => $data]);
  434. }
  435. /**
  436. * 销售简报跟进数量统计
  437. * @return \think\response\Json
  438. */
  439. public function activityCount()
  440. {
  441. $param = $this->param;
  442. $userInfo = $this->userInfo;
  443. $param['user_id'] = $userInfo['id'];
  444. $TaskLogic = new LogLogic();
  445. $data = $TaskLogic->activityCount($param);
  446. return resultArray(['data' => $data]);
  447. }
  448. /**
  449. * 销售简报跟进详情
  450. * @return \think\response\Json
  451. */
  452. public function activityList()
  453. {
  454. $param = $this->param;
  455. $userInfo = $this->userInfo;
  456. $param['user_id'] = $userInfo['id'];
  457. $TaskLogic = new LogLogic();
  458. $data = $TaskLogic->activityList($param);
  459. return resultArray(['data' => $data]);
  460. }
  461. /**
  462. * 日志详情
  463. * @return \think\response\Json
  464. */
  465. public function queryLog(){
  466. $param = $this->param;
  467. $userInfo = $this->userInfo;
  468. $param['user_id'] = $userInfo['id'];
  469. $TaskLogic = new LogLogic();
  470. $data = $TaskLogic->queryLog($param);
  471. return resultArray(['data' => $data]);
  472. }
  473. /**
  474. * 点赞取消点赞
  475. *
  476. * @author alvin guogaobo
  477. * @version 1.0 版本号
  478. * @since 2021/5/17 0017 10:00
  479. */
  480. public function favourUpdate(){
  481. $param = $this->param;
  482. $userInfo = $this->userInfo;
  483. $param['user_id'] = $userInfo['id'];
  484. $TaskLogic = new LogLogic();
  485. $data = $TaskLogic->favourUpdate($param);
  486. return resultArray(['data' => $data]);
  487. }
  488. }