Document.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\model\system;
  13. use think\facade\Cache;
  14. use app\model\BaseModel;
  15. /**
  16. * 系统文章
  17. */
  18. class Document extends BaseModel
  19. {
  20. /**
  21. * 设置文章内容
  22. * @param unknown $title
  23. * @param unknown $content
  24. * @param unknown $condition
  25. * @return multitype:string
  26. */
  27. public function setDocument($title, $content, $condition)
  28. {
  29. $check_condition = array_column($condition, 2, 0);
  30. $site_id = isset($check_condition['site_id']) ? $check_condition['site_id'] : '';
  31. if ($site_id === '') {
  32. return $this->error('', 'REQUEST_SITE_ID');
  33. }
  34. $app_module = isset($check_condition['app_module']) ? $check_condition['app_module'] : '';
  35. if ($app_module === '') {
  36. return $this->error('', 'REQUEST_APP_MODULE');
  37. }
  38. $document_key = isset($check_condition['document_key']) ? $check_condition['document_key'] : '';
  39. if (empty($document_key)) {
  40. return $this->error('', 'REQUEST_DOCUMENT_KEY');
  41. }
  42. $data = $check_condition;
  43. $data['title'] = $title;
  44. $data['content'] = $content;
  45. $json_condition = json_encode($condition);
  46. $document_model = model('document');
  47. $info = $document_model->getInfo($condition, 'id');
  48. Cache::tag("document")->set("document_".$json_condition, "");
  49. if(empty($info))
  50. {
  51. $data['create_time'] = time();
  52. $res = $document_model->add($data);
  53. }else{
  54. $data['modify_time'] = time();
  55. $res = $document_model->update($data, $condition);
  56. }
  57. return $this->success($res);
  58. }
  59. /**
  60. * 获取系统文章
  61. * @param array $condition
  62. */
  63. public function getDocument($condition)
  64. {
  65. $json_condition = json_encode($condition);
  66. $cache = Cache::get("document_".$json_condition, "");
  67. if (!empty($cache)) {
  68. return $this->success($cache);
  69. }
  70. $check_condition = array_column($condition, 2, 0);
  71. $site_id = isset($check_condition['site_id']) ? $check_condition['site_id'] : '';
  72. if ($site_id === '') {
  73. return $this->error('', 'REQUEST_SITE_ID');
  74. }
  75. $app_module = isset($check_condition['app_module']) ? $check_condition['app_module'] : '';
  76. if ($app_module === '') {
  77. return $this->error('', 'REQUEST_APP_MODULE');
  78. }
  79. $document_key = isset($check_condition['document_key']) ? $check_condition['document_key'] : '';
  80. if (empty($document_key)) {
  81. return $this->error('', 'REQUEST_DOCUMENT_KEY');
  82. }
  83. $info = model('document')->getInfo($condition, 'site_id, app_module, document_key, title, content, create_time, modify_time');
  84. if(empty($info))
  85. {
  86. //默认初始值
  87. $info = [
  88. 'site_id' => $site_id,
  89. 'app_module' => $app_module,
  90. 'document_key' => $document_key,
  91. 'title' => '',
  92. 'content' => '',
  93. 'create_time' => 0,
  94. 'modify_time' => 0
  95. ];
  96. }
  97. Cache::tag("document")->set("document_".$json_condition, $info);
  98. return $this->success($info);
  99. }
  100. }