Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

507 rader
14 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tianlionfire
  5. * Date: 2018/1/24
  6. * Time: 15:15
  7. */
  8. namespace backend\modules\zzcs\logic;
  9. use backend\modules\zzcs\models\BaseArea;
  10. use backend\modules\zzcs\models\BaseUser;
  11. use backend\modules\zzcs\models\OperaDocument;
  12. use Yii;
  13. class OperaDocumentManager
  14. {
  15. /**
  16. * Function Description:获取文件管理列表
  17. * Function Name: getDocumentList
  18. * @param $type
  19. * @param $module
  20. * @param $search_more
  21. * @param $page_size
  22. * @param $current
  23. *
  24. * @return array
  25. *
  26. * @author 李健
  27. */
  28. public function getDocumentList($type, $module, $search_more, $page_size, $current)
  29. {
  30. $opera_document = new OperaDocument();
  31. $doc_res = $opera_document->getDocumentList($type, $module, $search_more, $page_size, $current);
  32. foreach ($doc_res as $k => $v) {
  33. $doc_res[$k]['num'] = $k + 1 + ($current - 1) * $page_size;
  34. }
  35. // 获取总数
  36. $total_page = $opera_document->getDocumentListCount($type, $module, $search_more);
  37. $res = [];
  38. if ($total_page > 0) {
  39. $res['code'] = '0';
  40. $res['info'] = '返回文档管理列表成功';
  41. $res['list'] = $doc_res;
  42. $res['count'] = $total_page;
  43. $res['total_page'] = (string)ceil($total_page / $page_size);
  44. $res['current'] = $current;
  45. } else {
  46. $res['code'] = '0';
  47. $res['info'] = '没有符合条件的数据';
  48. $res['list'] = array();
  49. $res['count'] = '0';
  50. $res['total_page'] = '0';
  51. $res['current'] = $current;
  52. }
  53. return $res;
  54. }
  55. /**
  56. * Function Description:查询已发布的模块的功能说明和系统简介文档(首页)
  57. * Function Name: getInfo
  58. * @return array|\yii\db\ActiveRecord[]
  59. * @author 田玲菲
  60. */
  61. public function getInfo()
  62. {
  63. $operaDocument = new OperaDocument();
  64. $res = $operaDocument->getInfo();
  65. foreach ($res as $k => $v2) {
  66. if (isset($res[$k]['function'])) {
  67. foreach ($res[$k]['function'] as &$v) {
  68. $v['title'] = strip_tags($v['title']);
  69. $v['content'] = strip_tags($v['content']);
  70. if(isset($v['content']{200})){
  71. $v['content'] = mb_substr($v['content'],0,200,'UTF-8').'...';
  72. }
  73. }
  74. }
  75. if (isset($res[$k]['system'])) {
  76. foreach ($res[$k]['system'] as &$v) {
  77. $v['title'] = strip_tags($v['title']);
  78. $v['content'] = strip_tags($v['content']);
  79. }
  80. }
  81. }
  82. return $res;
  83. }
  84. /**
  85. * Function Description:关键字高亮,不区分大小写
  86. * Function Name: str_highlight
  87. * @param $subject
  88. * @param $keyword
  89. * @param string $pre
  90. * @param string $suf
  91. * @return string
  92. * @author 田玲菲
  93. */
  94. public function str_highlight($subject,$keyword,$pre = '<span style="color:red">',$suf = '</span>'){
  95. if(empty($subject) || empty($keyword)){
  96. return $subject;
  97. }
  98. $k_len = strlen($keyword);
  99. if($k_len > strlen($subject)){
  100. return $subject;
  101. }
  102. $keyword = strtolower($keyword);
  103. $offset=0;
  104. $return=array();
  105. while (1) {
  106. $sub = substr($subject, $offset, $k_len);
  107. if(strlen($sub)<$k_len){
  108. if($sub){
  109. $return[]=$sub;
  110. }
  111. break;
  112. }
  113. if(strtolower($sub) == $keyword){
  114. $return[]=$pre;
  115. $return[]=$sub;
  116. $return[]=$suf;
  117. $offset+=$k_len;
  118. }else{
  119. $return[]=substr($subject, $offset,1);
  120. $offset++;
  121. }
  122. }
  123. return join('', $return);
  124. }
  125. /**
  126. * Function Description:获取文章列表
  127. * Function Name: getArticleList
  128. * @param $type
  129. * @param $module
  130. * @param $search_more
  131. * @param $page_size
  132. * @param $current
  133. * @return array
  134. * @author 田玲菲
  135. */
  136. public function getArticleList($type, $module, $search_more, $page_size, $current)
  137. {
  138. $opera_document = new OperaDocument();
  139. //获取文档列表
  140. $doc_res = $opera_document->getDocumentListReleased($type, $module, $search_more, $page_size, $current);
  141. //剥去html和php标签
  142. foreach ($doc_res as &$v) {
  143. $v['content'] = strip_tags($v['content']);
  144. if(isset($v['content']{200})){
  145. $v['content'] = mb_substr($v['content'],0,200,'UTF-8').'...';
  146. }
  147. }
  148. //搜索关键字变红
  149. if (!empty($search_more)) {
  150. // $replace_str = '<span style="color:red">' . $search_more . '</span>';
  151. // foreach ($doc_res as &$v) {
  152. // $v['title'] = str_replace($search_more, $replace_str, $v['title']);
  153. // $v['content'] = str_replace($search_more, $replace_str, $v['content']);
  154. // }
  155. foreach ($doc_res as &$v){
  156. $v['title'] = $this->str_highlight($v['title'],$search_more);
  157. $v['content'] = $this->str_highlight($v['content'],$search_more);
  158. }
  159. }
  160. // 获取总数
  161. $total_page = $opera_document->getDocumentListReleaseCount($type, $module, $search_more);
  162. $res = [];
  163. $base_area = new BaseArea();
  164. $page_arr = $base_area->getPage($total_page, $page_size, $current);
  165. $res['page_size_arr'] = [10, 30, 50, 100];
  166. if ($total_page > 0) {
  167. $res['code'] = '0';
  168. $res['info'] = '返回文档列表成功';
  169. $res['list'] = $doc_res;
  170. $res['page']['current_page'] = $current;
  171. $res['page']['total_row'] = $total_page;
  172. $res['page']['page_size'] = $page_size;
  173. $res['count'] = $total_page;
  174. $res['total_page'] = (string)ceil($total_page / $page_size);
  175. $res['page_arr'] = $page_arr;
  176. $res['module'] = $module;
  177. } else {
  178. $res['code'] = '1';
  179. $res['info'] = '没有符合条件的数据';
  180. $res['list'] = array();
  181. $res['count'] = '0';
  182. $res['total_page'] = '0';
  183. $res['page']['current_page'] = $current;
  184. $res['page']['total_row'] = $total_page;
  185. $res['page']['page_size'] = $page_size;
  186. $res['count'] = $total_page;
  187. $res['total_page'] = (string)ceil($total_page / $page_size);
  188. $res['page_arr'] = $page_arr;
  189. $res['module'] = $module;
  190. }
  191. return $res;
  192. }
  193. /**
  194. * Function Description:根据id获取文章内容
  195. * Function Name: getDocumentContent
  196. * @param $id
  197. * @return array|\yii\db\ActiveRecord[]
  198. * @author 田玲菲
  199. */
  200. public function getDocumentContent($id)
  201. {
  202. $operaDocument = new OperaDocument();
  203. return $operaDocument->getDocumentContent($id);
  204. }
  205. /**
  206. * Function Description:获取常见问题列表和内容
  207. * Function Name: getCommonQuestion
  208. * @return array|\yii\db\ActiveRecord[]
  209. * @author 田玲菲
  210. */
  211. public function getCommonQuestion()
  212. {
  213. $operaDocument = new OperaDocument();
  214. $res = $operaDocument->getCommonQuestion();
  215. foreach ($res as $k => $v2) {
  216. if (isset($res[$k]['function'])) {
  217. foreach ($res[$k]['function'] as &$v) {
  218. $v['title'] = strip_tags($v['title']);
  219. $v['content'] = strip_tags($v['content']);
  220. }
  221. }
  222. if (isset($res[$k]['system'])) {
  223. foreach ($res[$k]['system'] as &$v) {
  224. $v['title'] = strip_tags($v['title']);
  225. $v['content'] = strip_tags($v['content']);
  226. }
  227. }
  228. }
  229. return $res;
  230. }
  231. /**
  232. * Function Description:增加文档的阅读次数
  233. * Function Name: addSeeCount
  234. * @param $id
  235. * @return mixed
  236. * @author 田玲菲
  237. */
  238. public function addSeeCounts($id)
  239. {
  240. $operaDocument = new OperaDocument();
  241. return $operaDocument->addSeeCount($id);
  242. }
  243. /**
  244. * Function Description:删除文档
  245. * Function Name: deleteDocument
  246. * @param $id
  247. * @return mixed
  248. * @author 李健
  249. */
  250. public function deleteDocument($id)
  251. {
  252. $operaDocument = new OperaDocument();
  253. $res = $operaDocument->deleteDocument($id);
  254. if (!$res) {
  255. $json['code'] = '1';
  256. $json['info'] = '删除文档失败';
  257. } else {
  258. $json['code'] = '0';
  259. $json['info'] = '删除文档成功';
  260. }
  261. return $json;
  262. }
  263. /**
  264. * Function Description:修改状态
  265. * Function Name: changeStatus
  266. * @param $id
  267. * @return mixed
  268. * @author 李健
  269. */
  270. public function changeStatus($id)
  271. {
  272. $operaDocument = new OperaDocument();
  273. $res = $operaDocument->changeStatus($id);
  274. if (!$res) {
  275. $json['code'] = '1';
  276. $json['info'] = '修改失败';
  277. } else {
  278. $json['code'] = '0';
  279. $json['info'] = '修改成功';
  280. }
  281. return $json;
  282. }
  283. /**
  284. * Function Description:上传图片
  285. * Function Name: uploadImg
  286. * @param $pic
  287. *
  288. * @return string|void
  289. *
  290. * @author 李健
  291. */
  292. public function uploadImg($pic)
  293. {
  294. // 允许的图片类型
  295. $allowedExts = array("gif", "jpeg", "jpg", "png");
  296. $extension = end(explode('.',$pic['name']));
  297. if(!in_array($extension,$allowedExts)){
  298. return;
  299. }
  300. if(!is_uploaded_file($pic['tmp_name'])) {
  301. return ;
  302. }
  303. $upload_path = "http://". CS1_DOMAIN. "/upload/image/";
  304. $name = sha1(microtime()) . "." . $extension;
  305. if(move_uploaded_file($pic["tmp_name"],'upload/image/' . $name)){
  306. $response['link'] = $upload_path.$name;
  307. return json_encode($response);
  308. }
  309. }
  310. /**
  311. * Function Description:保存文档
  312. * Function Name: saveDocument
  313. * @param $type
  314. * @param $module
  315. * @param $sort
  316. * @param $title
  317. * @param $content
  318. * @param $release_type
  319. *
  320. * @return mixed
  321. *
  322. * @author 李健
  323. */
  324. public function saveDocument($type,$module,$sort,$title,$content,$release_type)
  325. {
  326. // 校验模块
  327. if($type==3){
  328. $json = $this->checkFunction($type,$module);
  329. if($json['code']!=0){
  330. return $json;
  331. }
  332. }
  333. // 校验标题
  334. $json = $this->checkTitle($title);
  335. if($json['code']!=0){
  336. return $json;
  337. }
  338. $opera_document = new OperaDocument();
  339. $res = $opera_document->saveDocument($type,$module,$sort,$title,$content,$release_type);
  340. if(!$res){
  341. $json['code'] = 1;
  342. $json['info'] = '保存文档失败';
  343. } else {
  344. $json['code'] = 0;
  345. if($release_type==1){
  346. $json['info'] = '保存并发布文档成功';
  347. } else {
  348. $json['info'] = '保存文档成功';
  349. }
  350. }
  351. return $json;
  352. }
  353. /**
  354. * Function Description:修改文档
  355. * Function Name: updateDocument
  356. * @param $id
  357. * @param $type
  358. * @param $module
  359. * @param $sort
  360. * @param $title
  361. * @param $content
  362. * @param $release_type
  363. *
  364. * @return mixed
  365. *
  366. * @author 李健
  367. */
  368. public function updateDocument($id,$type,$module,$sort,$title,$content,$release_type)
  369. {
  370. // 校验模块
  371. if($type==3){
  372. $json = $this->checkFunction($type,$module,$id);
  373. if($json['code']!=0){
  374. return $json;
  375. }
  376. }
  377. // 校验标题
  378. $json = $this->checkTitle($title,$id);
  379. if($json['code']!=0){
  380. return $json;
  381. }
  382. $opera_document = new OperaDocument();
  383. $res = $opera_document->updateDocument($id,$type,$module,$sort,$title,$content,$release_type);
  384. if(!$res){
  385. $json['code'] = 1;
  386. $json['info'] = '修改保存文档失败';
  387. } else {
  388. $json['code'] = 0;
  389. if($release_type==1){
  390. $json['info'] = '修改并发布文档成功';
  391. } else {
  392. $json['info'] = '修改并保存文档成功';
  393. }
  394. }
  395. return $json;
  396. }
  397. /**
  398. * Function Description:检查功能说明是否存在
  399. * Function Name: checkFunction
  400. * @param $type
  401. * @param $module
  402. * @param $id
  403. *
  404. * @return array|null|\yii\db\ActiveRecord
  405. *
  406. * @author 李健
  407. */
  408. public function checkFunction($type,$module,$id=0)
  409. {
  410. $opera_document = new OperaDocument();
  411. $res = $opera_document->checkFunction($type,$module);
  412. if($res){
  413. if($id!=0 && $res['id'] == $id){
  414. $res['code'] = 0;
  415. } else {
  416. $res['code'] = 1;
  417. $res['info'] = '该模块功能说明已存在请勿重复添加';
  418. }
  419. } else {
  420. $res['code'] = 0;
  421. }
  422. return $res;
  423. }
  424. /**
  425. * Function Description:校验标题唯一性
  426. * Function Name: checkTitle
  427. * @param $title
  428. * @param int $id
  429. *
  430. * @return array|null|\yii\db\ActiveRecord
  431. *
  432. * @author 李健
  433. */
  434. public function checkTitle($title,$id=0)
  435. {
  436. $opera_document = new OperaDocument();
  437. $res = $opera_document->checkTitle($title);
  438. if($res){
  439. if($id!=0 && $res['id'] == $id){
  440. $res['code'] = 0;
  441. } else {
  442. $res['code'] = 1;
  443. $res['info'] = '该标题已存在请勿重复添加';
  444. }
  445. } else {
  446. $res['code'] = 0;
  447. }
  448. return $res;
  449. }
  450. /**
  451. * Function Description:更新排序
  452. * Function Name: updateSort
  453. * @param $sort
  454. * @param $id
  455. *
  456. * @return mixed
  457. *
  458. * @author 李健
  459. */
  460. public function updateSort($sort,$id)
  461. {
  462. $opera_document = new OperaDocument();
  463. $res = $opera_document->updateSort($sort,$id);
  464. if($res){
  465. $json['code'] = 0;
  466. $json['info'] = '排序更新成功';
  467. } else {
  468. $json['code'] = 1;
  469. $json['info'] = '排序更新失败';
  470. }
  471. return $json;
  472. }
  473. }