Log.php 16KB

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