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