Notes.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\notes\shop\controller;
  11. use app\shop\controller\BaseShop;
  12. use addon\notes\model\Notes as NotesModel;
  13. use addon\notes\model\Group as GroupModel;
  14. /**
  15. * 笔记控制器
  16. */
  17. class Notes extends BaseShop
  18. {
  19. public function __construct()
  20. {
  21. parent::__construct();
  22. $this->forthMenu();
  23. }
  24. /*
  25. * 笔记活动列表
  26. */
  27. public function lists()
  28. {
  29. $model = new NotesModel();
  30. //获取续签信息
  31. if (request()->isAjax()) {
  32. $condition[] = [ 'pn.site_id', '=', $this->site_id ];
  33. //笔记状态
  34. $status = input('status', '');
  35. if ($status !== '') {
  36. $condition[] = [ 'pn.status', '=', $status ];
  37. }
  38. //笔记标题
  39. $note_title = input('note_title', '');
  40. if ($note_title) {
  41. $condition[] = [ 'pn.note_title', 'like', '%' . $note_title . '%' ];
  42. }
  43. //笔记类型
  44. $note_type = input('note_type', '');
  45. if ($note_type) {
  46. $condition[] = [ 'pn.note_type', '=', $note_type ];
  47. }
  48. //分组
  49. $group_id = input('group_id', '');
  50. if ($group_id) {
  51. $condition[] = [ 'pn.group_id', '=', $group_id ];
  52. }
  53. //时间
  54. $start_time = input("start_time", '');
  55. $end_time = input("end_time", '');
  56. if (!empty($start_time) && empty($end_time)) {
  57. $condition[] = [ "pn.create_time", ">=", date_to_time($start_time) ];
  58. } elseif (empty($start_time) && !empty($end_time)) {
  59. $condition[] = [ "pn.create_time", "<=", date_to_time($end_time) ];
  60. } elseif (!empty($start_time) && !empty($end_time)) {
  61. $condition[] = [ 'pn.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  62. }
  63. $page = input('page', 1);
  64. $page_size = input('page_size', PAGE_LIST_ROWS);
  65. //排序
  66. // $order = input('order', 'sort');
  67. // $sort = input('sort', 'desc');
  68. // if($order == 'sort'){
  69. // $order_by = 'pn.'.$order . ' ' . $sort;
  70. // }else{
  71. // $order_by = 'pn.'.$order . ' ' . $sort.',pn.sort desc';
  72. // }
  73. $order_by = 'pn.create_time desc';
  74. $list = $model->getNotesPageList($condition, $page, $page_size, $order_by);
  75. return $list;
  76. } else {
  77. //笔记类型
  78. $note_type = $model->getNoteType();
  79. $this->assign('note_type', $note_type);
  80. //笔记分组
  81. $group_model = new GroupModel();
  82. $group_list = $group_model->getNotesGroupList([ [ 'site_id', '=', $this->site_id ] ], 'group_id,group_name');
  83. $this->assign('group_list', $group_list[ 'data' ]);
  84. return $this->fetch("notes/lists");
  85. }
  86. }
  87. /**
  88. * 添加活动
  89. */
  90. public function add()
  91. {
  92. $note_type = input('note_type', '');
  93. if (request()->isAjax()) {
  94. $notes_data = [
  95. 'site_id' => $this->site_id,
  96. 'note_type' => $note_type,
  97. 'note_title' => input('note_title', ''),
  98. 'note_abstract' => input('note_abstract', ''),
  99. 'group_id' => input('group_id', ''),
  100. 'cover_type' => input('cover_type', ''),
  101. 'cover_img' => input('cover_img', ''),
  102. 'goods_ids' => input('goods_ids', ''),
  103. 'goods_highlights' => input('goods_highlights', ''),
  104. 'note_content' => htmlspecialchars_decode(input('note_content', '')),
  105. 'status' => input('status', ''),
  106. 'sort' => input('sort', '0'),
  107. 'is_show_release_time' => input('is_show_release_time', ''),
  108. 'is_show_read_num' => input('is_show_read_num', ''),
  109. 'is_show_dianzan_num' => input('is_show_dianzan_num', ''),
  110. 'initial_read_num' => input('initial_read_num', ''),
  111. 'initial_dianzan_num' => input('initial_dianzan_num', ''),
  112. 'note_link' => input('note_link', ''),
  113. 'video_path' => input('video_path', ''),
  114. ];
  115. $notes_model = new NotesModel();
  116. return $notes_model->addNotes($notes_data);
  117. } else {
  118. $this->assign('note_type', $note_type);
  119. //笔记分组
  120. $group_model = new GroupModel();
  121. $group_list = $group_model->getNotesGroupList([ [ 'site_id', '=', $this->site_id ] ], 'group_id,group_name');
  122. $this->assign('group_list', $group_list[ 'data' ]);
  123. switch ( $note_type ) {
  124. case 'shop_said':
  125. return $this->fetch('notes/add_shop_said');
  126. case 'goods_item':
  127. return $this->fetch('notes/add_goods_item');
  128. case 'article':
  129. return $this->fetch('notes/add_article');
  130. case 'wechat_article':
  131. return $this->fetch('notes/add_wechat_article');
  132. case 'goods_video':
  133. return $this->fetch('notes/add_goods_video');
  134. default:
  135. $this->error("笔记类型不存在");
  136. }
  137. }
  138. }
  139. /*
  140. * 编辑活动
  141. */
  142. public function edit()
  143. {
  144. $notes_model = new NotesModel();
  145. $note_id = input('note_id', '');
  146. $note_type = input('note_type', '');
  147. if (request()->isAjax()) {
  148. $notes_data = [
  149. 'note_id' => $note_id,
  150. 'site_id' => $this->site_id,
  151. 'note_type' => $note_type,
  152. 'note_title' => input('note_title', ''),
  153. 'note_abstract' => input('note_abstract', ''),
  154. 'group_id' => input('group_id', ''),
  155. 'cover_type' => input('cover_type', ''),
  156. 'cover_img' => input('cover_img', ''),
  157. 'goods_ids' => input('goods_ids', ''),
  158. 'goods_highlights' => input('goods_highlights', ''),
  159. 'note_content' => htmlspecialchars_decode(input('note_content', '')),
  160. 'status' => input('status', ''),
  161. 'sort' => input('sort', '0'),
  162. 'is_show_release_time' => input('is_show_release_time', ''),
  163. 'is_show_read_num' => input('is_show_read_num', ''),
  164. 'is_show_dianzan_num' => input('is_show_dianzan_num', ''),
  165. 'initial_read_num' => input('initial_read_num', ''),
  166. 'initial_dianzan_num' => input('initial_dianzan_num', ''),
  167. 'note_link' => input('note_link', ''),
  168. 'video_path' => input('video_path', ''),
  169. ];
  170. return $notes_model->editNotes($notes_data);
  171. } else {
  172. $this->assign('note_id', $note_id);
  173. $this->assign('note_type', $note_type);
  174. //笔记分组
  175. $group_model = new GroupModel();
  176. $group_list = $group_model->getNotesGroupList([ [ 'site_id', '=', $this->site_id ] ], 'group_id,group_name');
  177. $this->assign('group_list', $group_list[ 'data' ]);
  178. //获取笔记信息
  179. $note_info = $notes_model->getNotesDetailInfo([ [ 'note_id', '=', $note_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ] ?? [];
  180. if (empty($note_info)) $this->error('未获取到笔记数据', addon_url('notes://shop/notes/lists'));
  181. $note_type = $note_info[ 'note_type' ];
  182. $this->assign('info', $note_info);
  183. switch ( $note_type ) {
  184. case 'shop_said':
  185. return $this->fetch('notes/edit_shop_said');
  186. case 'goods_item':
  187. return $this->fetch('notes/edit_goods_item');
  188. case 'article':
  189. return $this->fetch('notes/edit_article');
  190. case 'wechat_article':
  191. return $this->fetch('notes/edit_wechat_article');
  192. case 'goods_video':
  193. return $this->fetch('notes/edit_goods_video');
  194. default:
  195. $this->error("笔记类型不存在");
  196. }
  197. }
  198. }
  199. /*
  200. * 删除笔记活动
  201. */
  202. public function delete()
  203. {
  204. $note_id = input('note_id', '');
  205. $notes_model = new NotesModel();
  206. return $notes_model->deleteNotes([ [ 'note_id', '=', $note_id ], [ 'site_id', '=', $this->site_id ] ]);
  207. }
  208. /**
  209. * 草稿箱
  210. * @return mixed
  211. */
  212. public function drafts()
  213. {
  214. $model = new NotesModel();
  215. //笔记类型
  216. $note_type = $model->getNoteType();
  217. $this->assign('note_type', $note_type);
  218. //笔记分组
  219. $group_model = new GroupModel();
  220. $group_list = $group_model->getNotesGroupList([ [ 'site_id', '=', $this->site_id ] ], 'group_id,group_name');
  221. $this->assign('group_list', $group_list[ 'data' ]);
  222. return $this->fetch("notes/drafts");
  223. }
  224. /**
  225. * 发布或取消发布
  226. * @return array
  227. */
  228. public function releaseEvent()
  229. {
  230. if (request()->isAjax()) {
  231. $note_id = input('note_id', 0);
  232. $notes_model = new NotesModel();
  233. $data = array (
  234. 'note_id' => $note_id,
  235. 'site_id' => $this->site_id,
  236. 'status' => input('status', 0)
  237. );
  238. return $notes_model->releaseEvent($data);
  239. }
  240. }
  241. /**
  242. * 修改商品类型排序
  243. */
  244. public function modifySort()
  245. {
  246. if (request()->isAjax()) {
  247. $sort = input('sort', 0);
  248. $note_id = input('note_id', 0);
  249. $notes_model = new NotesModel();
  250. return $notes_model->modifyNotesSort($sort, $note_id, $this->site_id);
  251. }
  252. }
  253. /**
  254. * 笔记选择组件
  255. * @return \multitype
  256. */
  257. public function notesSelect()
  258. {
  259. $model = new NotesModel();
  260. if (request()->isAjax()) {
  261. $condition[] = [ 'pn.site_id', '=', $this->site_id ];
  262. //笔记状态
  263. $status = input('status', '');
  264. if ($status !== '') {
  265. $condition[] = [ 'pn.status', '=', $status ];
  266. }
  267. //笔记标题
  268. $note_title = input('note_title', '');
  269. if ($note_title) {
  270. $condition[] = [ 'pn.note_title', 'like', '%' . $note_title . '%' ];
  271. }
  272. //笔记类型
  273. $note_type = input('note_type', '');
  274. if ($note_type) {
  275. $condition[] = [ 'pn.note_type', '=', $note_type ];
  276. }
  277. //分组
  278. $group_id = input('group_id', '');
  279. if ($group_id) {
  280. $condition[] = [ 'pn.group_id', '=', $group_id ];
  281. }
  282. $page = input('page', 1);
  283. $page_size = input('page_size', PAGE_LIST_ROWS);
  284. $list = $model->getNotesPageList($condition, $page, $page_size, 'pn.sort asc');
  285. return $list;
  286. } else {
  287. //已经选择的商品sku数据
  288. $select_id = input('select_id', '');
  289. $max_num = input('max_num', 0);
  290. $min_num = input('min_num', 0);
  291. $this->assign('select_id', $select_id);
  292. $this->assign('max_num', $max_num);
  293. $this->assign('min_num', $min_num);
  294. //笔记类型
  295. $note_type = $model->getNoteType();
  296. $this->assign('note_type', $note_type);
  297. //笔记分组
  298. $group_model = new GroupModel();
  299. $group_list = $group_model->getNotesGroupList([ [ 'site_id', '=', $this->site_id ] ], 'group_id,group_name');
  300. $this->assign('group_list', $group_list[ 'data' ]);
  301. return $this->fetch("notes/notes_select");
  302. }
  303. }
  304. /**
  305. * 采集文章
  306. */
  307. public function pullArticle()
  308. {
  309. $note_model = new NotesModel();
  310. $url = input('wechat_url', 'https://mp.weixin.qq.com/s/uyocVJ4DSGqDbu_BR77XwQ');
  311. $result = $note_model->pullWechatArticle([ 'url' => $url ]);
  312. //['title' => '', 'content' => '']
  313. return $result;
  314. }
  315. }