Notice.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\model\web;
  11. use think\facade\Cache;
  12. use app\model\BaseModel;
  13. /**
  14. * 公告管理
  15. * @author Administrator
  16. *
  17. */
  18. class Notice extends BaseModel
  19. {
  20. /**
  21. * 添加公告
  22. * @param unknown $data
  23. */
  24. public function addNotice($data)
  25. {
  26. $data[ 'create_time' ] = time();
  27. $res = model('notice')->add($data);
  28. Cache::tag("notice")->clear();
  29. return $this->success($res);
  30. }
  31. /**
  32. * 修改公告
  33. * @param $data
  34. * @param $condition
  35. * @return array
  36. */
  37. public function editNotice($data, $condition)
  38. {
  39. $data[ 'modify_time' ] = time();
  40. $res = model('notice')->update($data, $condition);
  41. Cache::tag("notice")->clear();
  42. return $this->success($res);
  43. }
  44. /**
  45. * 删除公告
  46. * @param array $condition
  47. */
  48. public function deleteNotice($condition)
  49. {
  50. $res = model('notice')->delete($condition);
  51. Cache::tag("notice")->clear();
  52. return $this->success($res);
  53. }
  54. /**
  55. * 获取公告数量
  56. * @param $condition
  57. * @return array
  58. */
  59. public function getNoticeCount($condition)
  60. {
  61. $count = model('notice')->getCount($condition);
  62. return $this->success($count);
  63. }
  64. /**
  65. * 获取公告信息
  66. * @param array $condition
  67. * @param string $field
  68. */
  69. public function getNoticeInfo($condition, $field = 'id, title, content, create_time, modify_time, is_top,receiving_type,receiving_name')
  70. {
  71. $data = json_encode([ $condition, $field ]);
  72. $cache = Cache::get("notice_getNoticeInfo_" . $data);
  73. if (!empty($cache)) {
  74. return $this->success($cache);
  75. }
  76. $res = model('notice')->getInfo($condition, $field);
  77. Cache::tag("notice")->set("notice_getNoticeInfo_" . $data, $res);
  78. return $this->success($res);
  79. }
  80. /**
  81. * 获取公告列表
  82. * @param array $condition
  83. * @param string $field
  84. * @param string $order
  85. * @param string $limit
  86. */
  87. public function getNoticeList($condition = [], $field = 'id, title, content, create_time, modify_time, is_top,receiving_type,receiving_name', $order = '', $limit = null)
  88. {
  89. $data = json_encode([ $condition, $field, $order, $limit ]);
  90. $cache = Cache::get("notice_getNoticeList_" . $data);
  91. if (!empty($cache)) {
  92. return $this->success($cache);
  93. }
  94. $list = model('notice')->getList($condition, $field, $order, '', '', '', $limit);
  95. Cache::tag("notice")->set("notice_getNoticeList_" . $data, $list);
  96. return $this->success($list);
  97. }
  98. /**
  99. * 获取公告分页列表
  100. * @param array $condition
  101. * @param number $page
  102. * @param string $page_size
  103. * @param string $order
  104. * @param string $field
  105. */
  106. public function getNoticePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'is_top desc,create_time desc', $field = 'id, title,content, create_time, is_top,receiving_type,receiving_name,sort')
  107. {
  108. $data = json_encode([ $condition, $field, $order, $page, $page_size ]);
  109. $cache = Cache::get("notice_getNoticePageList_" . $data);
  110. if (!empty($cache)) {
  111. return $this->success($cache);
  112. }
  113. $list = model('notice')->pageList($condition, $field, $order, $page, $page_size);
  114. Cache::tag("notice")->set("notice_getNoticePageList_" . $data, $list);
  115. return $this->success($list);
  116. }
  117. /**
  118. * 修改标签排序
  119. * @param $sort
  120. * @param $id
  121. * @return array
  122. */
  123. public function modifyNoticeSort($sort, $id)
  124. {
  125. $res = model('notice')->update([ 'sort' => $sort ], [ [ 'id', '=', $id ] ]);
  126. Cache::tag("notice")->clear();
  127. return $this->success($res);
  128. }
  129. /**
  130. * 生成推广二维码链接
  131. * @param $qrcode_param
  132. * @param $site_id
  133. * @return array
  134. */
  135. public function urlQrcode($qrcode_param, $site_id)
  136. {
  137. $h5_page = '/pages_tool/notice/detail';
  138. $pc_page = '/cms/notice/detail';
  139. $params = [
  140. 'site_id' => $site_id,
  141. 'data' => $qrcode_param,
  142. 'pc_data' => [ 'id' => $qrcode_param[ 'notice_id' ] ],
  143. 'page' => $h5_page,
  144. 'h5_path' => $h5_page . '?notice_id=' . $qrcode_param[ 'notice_id' ],
  145. 'pc_page' => $pc_page,
  146. 'pc_path' => $pc_page . '?id=' . $qrcode_param[ 'notice_id' ],
  147. 'qrcode_path' => 'upload/qrcode/notice',
  148. 'qrcode_name' => [
  149. 'h5_name' => 'notice_qrcode' . '_h5_' . $qrcode_param[ 'notice_id' ] . '_' . $site_id,
  150. 'weapp_name' => 'notice_qrcode' . '_weapp_' . $qrcode_param[ 'notice_id' ] . '_' . $site_id,
  151. 'pc_name' => 'notice_qrcode' . '_pc_' . $qrcode_param[ 'notice_id' ] . '_' . $site_id
  152. ]
  153. ];
  154. $solitaire = event('ExtensionInformation', $params);
  155. return $this->success($solitaire[ 0 ]);
  156. }
  157. }