Storehelp.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Storehelp extends AdminControl
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); //
  17. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/storehelp.lang.php');
  18. }
  19. /**
  20. * 帮助列表
  21. */
  22. public function index()
  23. {
  24. $help_model = model('help');
  25. $condition = array();
  26. $condition[] = array('help_id', '>', '99'); //内容列表不显示系统自动添加的数据
  27. $key = trim(input('param.key'));
  28. if ($key != '') {
  29. $condition[] = array('help_title', 'like', '%' . $key . '%');
  30. }
  31. $helptype_id = intval(input('param.helptype_id'));
  32. if ($helptype_id > 0) {
  33. $condition[] = array('helptype_id', '=', $helptype_id);
  34. }
  35. //获取帮助类型
  36. $helptype_list = $help_model->getStoreHelptypeList();
  37. View::assign('helptype_list', $helptype_list);
  38. $tmp_type_name = array();
  39. if (is_array($helptype_list)) {
  40. foreach ($helptype_list as $k => $v) {
  41. $tmp_type_name[$v['helptype_id']] = $v['helptype_name'];
  42. }
  43. }
  44. $help_list = $help_model->getStoreHelpList($condition, 10);
  45. if (is_array($help_list)) {
  46. foreach ($help_list as $k => $v) {
  47. // 所属类型
  48. if (@array_key_exists($v['helptype_id'], $tmp_type_name)) {
  49. $help_list[$k]['helptype_name'] = $tmp_type_name[$v['helptype_id']];
  50. }
  51. }
  52. }
  53. View::assign('help_list', $help_list);
  54. View::assign('show_page', $help_model->page_info->render());
  55. $this->setAdminCurItem('index');
  56. return View::fetch();
  57. }
  58. /**
  59. * 帮助类型
  60. */
  61. public function help_type()
  62. {
  63. $help_model = model('help');
  64. $condition = array();
  65. $helptype_list = $help_model->getStoreHelptypeList($condition, 10);
  66. View::assign('helptype_list', $helptype_list);
  67. View::assign('show_page', $help_model->page_info->render());
  68. $this->setAdminCurItem('help_type');
  69. return View::fetch();
  70. }
  71. /**
  72. * 新增帮助
  73. *
  74. */
  75. public function add_help()
  76. {
  77. $help_model = model('help');
  78. $help = array(
  79. 'help_title' => '',
  80. 'helptype_id' => '',
  81. 'help_sort' => '',
  82. 'help_url' => '',
  83. 'help_info' => '',
  84. 'help_id' => '',
  85. );
  86. View::assign('help', $help);
  87. if (request()->isPost()) {
  88. $help_array = array();
  89. $help_array['help_title'] = input('post.help_title');
  90. $help_array['help_url'] = input('post.help_url');
  91. $help_array['help_info'] = input('post.help_info');
  92. $help_array['help_sort'] = intval(input('post.help_sort'));
  93. $help_array['helptype_id'] = intval(input('post.helptype_id'));
  94. $help_array['help_updatetime'] = TIMESTAMP;
  95. $help_array['page_show'] = '1'; //页面类型:1为店铺,2为会员
  96. $state = $help_model->addHelp($help_array);
  97. if ($state) {
  98. $file_id_array = input('post.file_id/a');
  99. if (!empty($file_id_array) && is_array($file_id_array)) {
  100. $help_model->editHelpPic($state, $file_id_array);
  101. }
  102. $this->log('新增店铺帮助,编号' . $state);
  103. $this->success(lang('ds_common_op_succ'), 'storehelp/index');
  104. } else {
  105. $this->errot(lang('ds_common_op_fail'));
  106. }
  107. } else {
  108. $helptype_list = $help_model->getStoreHelptypeList();
  109. View::assign('helptype_list', $helptype_list);
  110. $condition = array();
  111. $condition[] = array('item_id', '=', '0');
  112. $pic_list = $help_model->getHelpPicList($condition);
  113. View::assign('pic_list', $pic_list);
  114. $this->setAdminCurItem('add_help');
  115. return View::fetch('edit_help');
  116. }
  117. }
  118. /**
  119. * 编辑帮助
  120. *
  121. */
  122. public function edit_help()
  123. {
  124. $help_model = model('help');
  125. $condition = array();
  126. $help_id = intval(input('param.help_id'));
  127. $condition[] = array('help_id', '=', $help_id);
  128. $help_list = $help_model->getStoreHelpList($condition);
  129. //halt($help_list);
  130. $help = $help_list[0];
  131. View::assign('help', $help);
  132. if (request()->isPost()) {
  133. $help_array = array();
  134. $help_array['help_title'] = input('post.help_title');
  135. $help_array['help_url'] = input('post.help_url');
  136. $help_array['help_info'] = input('post.help_info');
  137. $help_array['help_sort'] = intval(input('post.help_sort'));
  138. $help_array['helptype_id'] = intval(input('post.helptype_id'));
  139. $help_array['help_updatetime'] = TIMESTAMP;
  140. $state = $help_model->editHelp($condition, $help_array);
  141. if ($state) {
  142. $this->log('编辑店铺帮助,编号' . $help_id);
  143. $this->success(lang('ds_common_op_succ'), 'storehelp/index');
  144. } else {
  145. $this->error(lang('ds_common_op_fail'));
  146. }
  147. } else {
  148. $helptype_list = $help_model->getStoreHelptypeList();
  149. View::assign('helptype_list', $helptype_list);
  150. $condition = array();
  151. $condition[] = array('item_id', '=', $help_id);
  152. $pic_list = $help_model->getHelpPicList($condition);
  153. View::assign('pic_list', $pic_list);
  154. $this->setAdminCurItem('edit');
  155. return View::fetch();
  156. }
  157. }
  158. /**
  159. * 删除帮助
  160. *
  161. */
  162. public function del_help()
  163. {
  164. $help_model = model('help');
  165. $condition = array();
  166. $help_id = intval(input('param.help_id'));
  167. $condition[] = array('help_id', '=', $help_id);
  168. $state = $help_model->delHelp($condition, array($help_id));
  169. if ($state) {
  170. $this->log('删除店铺帮助,编号' . $help_id);
  171. ds_json_encode(10000, lang('ds_common_del_succ'));
  172. } else {
  173. ds_json_encode(10001, lang('ds_common_del_fail'));
  174. }
  175. }
  176. /**
  177. * 新增帮助类型
  178. *
  179. */
  180. public function add_type()
  181. {
  182. $help_model = model('help');
  183. if (request()->isPost()) {
  184. $type_array = array();
  185. $type_array['helptype_name'] = input('post.helptype_name');
  186. $type_array['helptype_sort'] = intval(input('post.helptype_sort'));
  187. $type_array['helptype_show'] = intval(input('post.helptype_show')); //是否显示,0为否,1为是
  188. $type_array['page_show'] = '1'; //页面类型:1为店铺,2为会员
  189. $state = $help_model->addHelptype($type_array);
  190. if ($state) {
  191. $this->log('新增店铺帮助类型,编号' . $state);
  192. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  193. } else {
  194. $this->error(lang('ds_common_save_fail'));
  195. }
  196. } else {
  197. $type = array(
  198. 'helptype_name' => '',
  199. 'helptype_sort' => '255',
  200. 'helptype_show' => '1',
  201. );
  202. View::assign('type', $type);
  203. return View::fetch('edit_type');
  204. }
  205. }
  206. /**
  207. * 编辑帮助类型
  208. *
  209. */
  210. public function edit_type()
  211. {
  212. $help_model = model('help');
  213. $condition = array();
  214. $helptype_id = intval(input('param.helptype_id'));
  215. $condition[] = array('helptype_id', '=', $helptype_id);
  216. $helptype_list = $help_model->getHelptypeList($condition);
  217. $type = $helptype_list[0];
  218. if (request()->isPost()) {
  219. $type_array = array();
  220. $type_array['helptype_name'] = input('post.helptype_name');
  221. $type_array['helptype_sort'] = intval(input('post.helptype_sort'));
  222. $type_array['helptype_show'] = intval(input('post.helptype_show')); //是否显示,0为否,1为是
  223. $state = $help_model->editHelptype($condition, $type_array);
  224. if ($state >= 0) {
  225. $this->log('编辑店铺帮助类型,编号' . $helptype_id);
  226. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  227. } else {
  228. $this->error(lang('ds_common_op_fail'));
  229. }
  230. } else {
  231. View::assign('type', $type);
  232. return View::fetch();
  233. }
  234. }
  235. /**
  236. * 删除帮助类型
  237. *
  238. */
  239. public function del_type()
  240. {
  241. $helptype_id = intval(input('param.helptype_id'));
  242. $help_model = model('help');
  243. $condition = array();
  244. $condition[] = array('helptype_id', '=', $helptype_id);
  245. $state = $help_model->delHelptype($condition);
  246. if ($state) {
  247. $this->log('删除店铺帮助类型,编号' . $helptype_id);
  248. ds_json_encode(10000, lang('ds_common_del_succ'));
  249. } else {
  250. ds_json_encode(10001, lang('ds_common_del_fail'));
  251. }
  252. }
  253. /**
  254. * 上传图片
  255. */
  256. public function upload_pic()
  257. {
  258. $data = array();
  259. if (!empty($_FILES['fileupload']['name'])) { //上传图片
  260. $fprefix = 'admin/storehelp';
  261. $filename = $file_name = date('YmdHis') . rand(10000, 99999) . '.png';
  262. $res = ds_upload_pic($fprefix, 'fileupload', $filename);
  263. if ($res['code']) {
  264. $file_name = $res['data']['file_name'];
  265. } else {
  266. echo json_encode($data);
  267. exit;
  268. }
  269. $upload_model = model('upload');
  270. $insert_array = array();
  271. $insert_array['file_name'] = $file_name;
  272. $insert_array['file_size'] = $_FILES['fileupload']['size'];
  273. $insert_array['upload_time'] = TIMESTAMP;
  274. $insert_array['item_id'] = intval(input('param.item_id'));
  275. $insert_array['upload_type'] = '2';
  276. $result = $upload_model->addUpload($insert_array);
  277. if ($result) {
  278. $data['file_id'] = $result;
  279. $data['file_name'] = $file_name;
  280. $data['file_path'] = ds_get_pic($fprefix, $file_name);
  281. }
  282. }
  283. echo json_encode($data);
  284. exit;
  285. }
  286. /**
  287. * 删除图片
  288. */
  289. public function del_pic()
  290. {
  291. $condition = array();
  292. $condition[] = array('upload_id', '=', intval(input('param.file_id')));
  293. $help_model = model('help');
  294. $state = $help_model->delHelpPic($condition);
  295. if ($state) {
  296. echo 'true';
  297. exit;
  298. } else {
  299. echo 'false';
  300. exit;
  301. }
  302. }
  303. protected function getAdminItemList()
  304. {
  305. $menu_array = array(
  306. array(
  307. 'name' => 'index',
  308. 'text' => lang('help_info'),
  309. 'url' => (string) url('Storehelp/index')
  310. ), array(
  311. 'name' => 'help_type',
  312. 'text' => lang('helptype_id'),
  313. 'url' => (string) url('Storehelp/help_type')
  314. )
  315. );
  316. if (request()->action() == 'edit_help') {
  317. $menu_array[] = array(
  318. 'name' => 'edit',
  319. 'text' => lang('edit_help'),
  320. 'url' => (string) url('Storehelp/edit_help')
  321. );
  322. }
  323. if (request()->action() == 'index' || request()->action() == 'add_help') {
  324. $menu_array[] = array(
  325. 'name' => 'add_help',
  326. 'text' => lang('add_help'),
  327. 'url' => (string) url('Storehelp/add_help')
  328. );
  329. }
  330. if (request()->action() == 'help_type' || request()->action() == 'add_type') {
  331. $menu_array[] = array(
  332. 'name' => 'add_type',
  333. 'text' => lang('add_type'),
  334. 'url' => "javascript:dsLayerOpen('" . (string) url('Storehelp/add_type') . "','" . lang('add_type') . "')"
  335. );
  336. }
  337. return $menu_array;
  338. }
  339. }