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