Help.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 Help extends BaseModel
  19. {
  20. /****************************************************************帮助文章******************************************/
  21. /**
  22. * 添加帮助文章
  23. * @param array $data
  24. */
  25. public function addHelp($data)
  26. {
  27. $help_id = model('help')->add($data);
  28. Cache::tag("help")->clear();
  29. return $this->success($help_id);
  30. }
  31. /**
  32. * 修改帮助文章
  33. * @param array $data
  34. */
  35. public function editHelp($data, $condition)
  36. {
  37. $res = model('help')->update($data, $condition);
  38. Cache::tag("help")->clear();
  39. return $this->success($res);
  40. }
  41. /**
  42. * 删除文章
  43. * @param unknown $coupon_type_id
  44. */
  45. public function deleteHelp($condition)
  46. {
  47. $res = model('help')->delete($condition);
  48. Cache::tag("help")->clear();
  49. return $this->success($res);
  50. }
  51. /**
  52. * 获取帮助文章详情
  53. * @param int $help_id
  54. * @return multitype:string mixed
  55. */
  56. public function getHelpInfo($help_id)
  57. {
  58. $cache = Cache::get("help_getHelpInfo_" . $help_id);
  59. if (!empty($cache)) {
  60. return $this->success($cache);
  61. }
  62. $res = model('help')->getInfo([ [ 'id', '=', $help_id ] ], 'id, title, content, class_id, class_name, sort, link_address, create_time, modify_time');
  63. Cache::tag("help")->set("help_getHelpInfo_" . $help_id, $res);
  64. return $this->success($res);
  65. }
  66. /**
  67. * 获取菜单列表
  68. * @param array $condition
  69. * @param string $field
  70. * @param string $order
  71. * @param string $limit
  72. */
  73. public function getHelpList($condition = [], $field = 'id, title, content, class_id, class_name, sort, create_time', $order = '', $limit = null)
  74. {
  75. $data = json_encode([ $condition, $field, $order, $limit ]);
  76. $cache = Cache::get("help_getHelpList_" . $data);
  77. if (!empty($cache)) {
  78. return $this->success($cache);
  79. }
  80. $list = model('help')->getList($condition, $field, $order, '', '', '', $limit);
  81. Cache::tag("help")->set("help_getHelpList_" . $data, $list);
  82. return $this->success($list);
  83. }
  84. /**
  85. * 获取帮助文章分页列表
  86. * @param array $condition
  87. * @param number $page
  88. * @param string $page_size
  89. * @param string $order
  90. * @param string $field
  91. */
  92. public function getHelpPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'sort asc,create_time desc', $field = 'id, title, content, class_id, class_name, sort, link_address, create_time')
  93. {
  94. $data = json_encode([ $condition, $field, $order, $page, $page_size ]);
  95. $cache = Cache::get("help_getHelpPageList_" . $data);
  96. if (!empty($cache)) {
  97. return $this->success($cache);
  98. }
  99. $list = model('help')->pageList($condition, $field, $order, $page, $page_size);
  100. Cache::tag("help")->set("help_getHelpList_" . $data, $list);
  101. return $this->success($list);
  102. }
  103. /**
  104. * 修改排序
  105. * @param int $sort
  106. * @param int $help_id
  107. */
  108. public function modifyHelpSort($sort, $help_id)
  109. {
  110. $res = model('help')->update([ 'sort' => $sort ], [ [ 'id', '=', $help_id ] ]);
  111. Cache::tag('help')->clear();
  112. return $this->success($res);
  113. }
  114. /****************************************************************帮助文章表******************************************/
  115. /**
  116. * 添加帮助类型
  117. * @param array $data
  118. */
  119. public function addHelpClass($data)
  120. {
  121. $model = model('help_class');
  122. $res = $model->add($data);
  123. if ($res) {
  124. Cache::tag("help_class")->clear();
  125. return $this->success($res);
  126. } else {
  127. return $this->error($res);
  128. }
  129. }
  130. /**
  131. * 修改帮助类型(主键修改,不修改排序)
  132. * @param array $data
  133. * @param int $class_id
  134. */
  135. public function editHelpClass($data, $class_id)
  136. {
  137. $res = model('help_class')->update($data, [ [ 'class_id', '=', $class_id ] ]);
  138. if ($res !== false) {
  139. Cache::tag("help_class")->clear();
  140. model('help')->update([ 'class_name' => $data[ 'class_name' ] ], [ [ 'class_id', '=', $class_id ] ]);
  141. Cache::tag("help")->clear();
  142. return $this->success($res);
  143. } else {
  144. return $this->error($res);
  145. }
  146. }
  147. /**
  148. * 获取帮助文章分类详情
  149. * @param array $condition
  150. * @param string $field
  151. */
  152. public function getHelpClassInfo($condition, $field = 'class_id, class_name, sort')
  153. {
  154. $data = json_encode([ $condition, $field ]);
  155. $cache = Cache::get("help_class_getHelpClassInfo_" . $data);
  156. if (!empty($cache)) {
  157. return $this->success($cache);
  158. }
  159. $res = model('help_class')->getInfo($condition, $field);
  160. Cache::tag("help_class")->set("help_class_getHelpClassInfo_" . $data, $res);
  161. return $this->success($res);
  162. }
  163. /**
  164. * 获取帮助文章分类分页列表
  165. * @param array $condition
  166. * @param number $page
  167. * @param number $page_size
  168. * @param string $order
  169. * @param string $field
  170. */
  171. public function getHelpClassPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'sort asc,create_time desc', $field = 'class_id, class_name, sort')
  172. {
  173. $data = json_encode([ $condition, $field, $order, $page, $page_size ]);
  174. $cache = Cache::get("help_class_getHelpClassInfo_" . $data);
  175. if (!empty($cache)) {
  176. return $this->success($cache);
  177. }
  178. $res = model('help_class')->pageList($condition, $field, $order, $page, $page_size);
  179. $check_condition = array_column($condition, 2, 0);
  180. if ($check_condition) {
  181. unset($check_condition[ 'class_name' ]);
  182. }
  183. $help_data = model('help')->getList($check_condition, 'class_id');
  184. $arr = [];
  185. if ($help_data) {
  186. $arr = array_column($help_data, 'class_id');
  187. $arr = array_unique($arr);
  188. }
  189. if ($res[ 'list' ]) {
  190. foreach ($res[ 'list' ] as $k => $v) {
  191. if (in_array($v[ 'class_id' ], $arr)) {
  192. $res[ 'list' ][ $k ][ 'child' ] = 1;
  193. } else {
  194. $res[ 'list' ][ $k ][ 'child' ] = 0;
  195. }
  196. }
  197. }
  198. Cache::tag("help_class")->set("help_class_getHelpClassPageList_" . $data, $res);
  199. return $this->success($res);
  200. }
  201. /**
  202. * 获取帮助文章分类列表
  203. * @param array $condition
  204. * @param string $field
  205. * @param string $order
  206. * @param number $limit
  207. */
  208. public function getHelpClassList($condition = [], $field = 'class_id, class_name, sort', $order = '', $limit = null)
  209. {
  210. $data = json_encode([ $condition, $field, $order, $limit ]);
  211. $cache = Cache::get("help_class_getHelpClassList_" . $data);
  212. if (!empty($cache)) {
  213. return $this->success($cache);
  214. }
  215. $res = model('help_class')->getList($condition, $field, $order, $alias = 'a', $join = [], $group = '', $limit);
  216. Cache::tag("help_class")->set("help_class_getHelpClassList_" . $data, $res);
  217. return $this->success($res);
  218. }
  219. /**
  220. * 删除帮助文章分类
  221. * @param array $condition
  222. */
  223. public function deleteHelpClass($condition)
  224. {
  225. $model = model('help_class');
  226. $res = $model->delete($condition);
  227. Cache::tag("help_class")->clear();
  228. if ($res) {
  229. return $this->success($res);
  230. } else {
  231. return $this->error($res);
  232. }
  233. }
  234. /**
  235. * 修改排序
  236. * @param int $sort
  237. * @param int $class_id
  238. */
  239. public function modifyHelpClassSort($sort, $class_id)
  240. {
  241. $res = model('help_class')->update([ 'sort' => $sort ], [ [ 'class_id', '=', $class_id ] ]);
  242. Cache::tag('help_class')->clear();
  243. return $this->success($res);
  244. }
  245. /**
  246. * 生成推广二维码链接
  247. * @param $qrcode_param
  248. * @param $site_id
  249. * @return array
  250. */
  251. public function urlQrcode($qrcode_param, $site_id)
  252. {
  253. $h5_page = '/pages_tool/help/detail';
  254. $pc_page = '/cms/help/detail';
  255. $params = [
  256. 'site_id' => $site_id,
  257. 'data' => $qrcode_param,
  258. 'pc_data' => $qrcode_param,
  259. 'page' => $h5_page,
  260. 'h5_path' => $h5_page . '?id=' . $qrcode_param[ 'id' ],
  261. 'pc_page' => $pc_page,
  262. 'pc_path' => $pc_page . '?id=' . $qrcode_param[ 'id' ],
  263. 'qrcode_path' => 'upload/qrcode/help',
  264. 'qrcode_name' => [
  265. 'h5_name' => 'help_qrcode' . '_h5_' . $qrcode_param[ 'id' ] . '_' . $site_id,
  266. 'weapp_name' => 'help_qrcode' . '_weapp_' . $qrcode_param[ 'id' ] . '_' . $site_id,
  267. 'pc_name' => 'help_qrcode' . '_pc_' . $qrcode_param[ 'id' ] . '_' . $site_id
  268. ]
  269. ];
  270. $solitaire = event('ExtensionInformation', $params);
  271. return $this->success($solitaire[ 0 ]);
  272. }
  273. }