Storehelp.php 13 KB

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