Storehelp.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Storehelp extends AdminControl {
  18. public function initialize() {
  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. $help_model = model('help');
  27. $condition = array();
  28. $condition[] = array('help_id', '>', '99'); //内容列表不显示系统自动添加的数据
  29. $key = trim(input('param.key'));
  30. if ($key != '') {
  31. $condition[] = array('help_title', 'like', '%' . $key . '%');
  32. }
  33. $helptype_id = intval(input('param.helptype_id'));
  34. if ($helptype_id > 0) {
  35. $condition[] = array('helptype_id', '=', $helptype_id);
  36. }
  37. //获取帮助类型
  38. $helptype_list = $help_model->getStoreHelptypeList();
  39. View::assign('helptype_list', $helptype_list);
  40. $tmp_type_name = array();
  41. if (is_array($helptype_list)) {
  42. foreach ($helptype_list as $k => $v) {
  43. $tmp_type_name[$v['helptype_id']] = $v['helptype_name'];
  44. }
  45. }
  46. $help_list = $help_model->getStoreHelpList($condition, 10);
  47. if (is_array($help_list)) {
  48. foreach ($help_list as $k => $v) {
  49. // 所属类型
  50. if (@array_key_exists($v['helptype_id'], $tmp_type_name)) {
  51. $help_list[$k]['helptype_name'] = $tmp_type_name[$v['helptype_id']];
  52. }
  53. }
  54. }
  55. View::assign('help_list', $help_list);
  56. View::assign('show_page', $help_model->page_info->render());
  57. $this->setAdminCurItem('index');
  58. return View::fetch();
  59. }
  60. /**
  61. * 帮助类型
  62. */
  63. public function help_type() {
  64. $help_model = model('help');
  65. $condition = array();
  66. $helptype_list = $help_model->getStoreHelptypeList($condition, 10);
  67. View::assign('helptype_list', $helptype_list);
  68. View::assign('show_page', $help_model->page_info->render());
  69. $this->setAdminCurItem('help_type');
  70. return View::fetch();
  71. }
  72. /**
  73. * 新增帮助
  74. *
  75. */
  76. public function add_help() {
  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. $help_model = model('help');
  124. $condition = array();
  125. $help_id = intval(input('param.help_id'));
  126. $condition[] = array('help_id', '=', $help_id);
  127. $help_list = $help_model->getStoreHelpList($condition);
  128. //halt($help_list);
  129. $help = $help_list[0];
  130. View::assign('help', $help);
  131. if (request()->isPost()) {
  132. $help_array = array();
  133. $help_array['help_title'] = input('post.help_title');
  134. $help_array['help_url'] = input('post.help_url');
  135. $help_array['help_info'] = input('post.help_info');
  136. $help_array['help_sort'] = intval(input('post.help_sort'));
  137. $help_array['helptype_id'] = intval(input('post.helptype_id'));
  138. $help_array['help_updatetime'] = TIMESTAMP;
  139. $state = $help_model->editHelp($condition, $help_array);
  140. if ($state) {
  141. $this->log('编辑店铺帮助,编号' . $help_id);
  142. $this->success(lang('ds_common_op_succ'), 'storehelp/index');
  143. } else {
  144. $this->error(lang('ds_common_op_fail'));
  145. }
  146. } else {
  147. $helptype_list = $help_model->getStoreHelptypeList();
  148. View::assign('helptype_list', $helptype_list);
  149. $condition = array();
  150. $condition[] = array('item_id', '=', $help_id);
  151. $pic_list = $help_model->getHelpPicList($condition);
  152. View::assign('pic_list', $pic_list);
  153. $this->setAdminCurItem('edit');
  154. return View::fetch();
  155. }
  156. }
  157. /**
  158. * 删除帮助
  159. *
  160. */
  161. public function del_help() {
  162. $help_model = model('help');
  163. $condition = array();
  164. $help_id = intval(input('param.help_id'));
  165. $condition[] = array('help_id', '=', $help_id);
  166. $state = $help_model->delHelp($condition, array($help_id));
  167. if ($state) {
  168. $this->log('删除店铺帮助,编号' . $help_id);
  169. ds_json_encode(10000, lang('ds_common_del_succ'));
  170. } else {
  171. ds_json_encode(10001, lang('ds_common_del_fail'));
  172. }
  173. }
  174. /**
  175. * 新增帮助类型
  176. *
  177. */
  178. public function add_type() {
  179. $help_model = model('help');
  180. if (request()->isPost()) {
  181. $type_array = array();
  182. $type_array['helptype_name'] = input('post.helptype_name');
  183. $type_array['helptype_sort'] = intval(input('post.helptype_sort'));
  184. $type_array['helptype_show'] = intval(input('post.helptype_show')); //是否显示,0为否,1为是
  185. $type_array['page_show'] = '1'; //页面类型:1为店铺,2为会员
  186. $state = $help_model->addHelptype($type_array);
  187. if ($state) {
  188. $this->log('新增店铺帮助类型,编号' . $state);
  189. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  190. } else {
  191. $this->error(lang('ds_common_save_fail'));
  192. }
  193. } else {
  194. $type = array(
  195. 'helptype_name' => '',
  196. 'helptype_sort' => '255',
  197. 'helptype_show' => '1',
  198. );
  199. View::assign('type', $type);
  200. return View::fetch('edit_type');
  201. }
  202. }
  203. /**
  204. * 编辑帮助类型
  205. *
  206. */
  207. public function edit_type() {
  208. $help_model = model('help');
  209. $condition = array();
  210. $helptype_id = intval(input('param.helptype_id'));
  211. $condition[] = array('helptype_id', '=', $helptype_id);
  212. $helptype_list = $help_model->getHelptypeList($condition);
  213. $type = $helptype_list[0];
  214. if (request()->isPost()) {
  215. $type_array = array();
  216. $type_array['helptype_name'] = input('post.helptype_name');
  217. $type_array['helptype_sort'] = intval(input('post.helptype_sort'));
  218. $type_array['helptype_show'] = intval(input('post.helptype_show')); //是否显示,0为否,1为是
  219. $state = $help_model->editHelptype($condition, $type_array);
  220. if ($state >= 0) {
  221. $this->log('编辑店铺帮助类型,编号' . $helptype_id);
  222. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  223. } else {
  224. $this->error(lang('ds_common_op_fail'));
  225. }
  226. } else {
  227. View::assign('type', $type);
  228. return View::fetch();
  229. }
  230. }
  231. /**
  232. * 删除帮助类型
  233. *
  234. */
  235. public function del_type() {
  236. $helptype_id = intval(input('param.helptype_id'));
  237. $help_model = model('help');
  238. $condition = array();
  239. $condition[] = array('helptype_id', '=', $helptype_id);
  240. $state = $help_model->delHelptype($condition);
  241. if ($state) {
  242. $this->log('删除店铺帮助类型,编号' . $helptype_id);
  243. ds_json_encode(10000, lang('ds_common_del_succ'));
  244. } else {
  245. ds_json_encode(10001, lang('ds_common_del_fail'));
  246. }
  247. }
  248. /**
  249. * 上传图片
  250. */
  251. public function upload_pic() {
  252. $data = array();
  253. if (!empty($_FILES['fileupload']['name'])) {//上传图片
  254. $fprefix = 'admin/storehelp';
  255. $filename = $file_name = date('YmdHis') . rand(10000, 99999) . '.png';
  256. $res = ds_upload_pic($fprefix, 'fileupload', $filename);
  257. if ($res['code']) {
  258. $file_name = $res['data']['file_name'];
  259. } else {
  260. echo json_encode($data);
  261. exit;
  262. }
  263. $upload_model = model('upload');
  264. $insert_array = array();
  265. $insert_array['file_name'] = $file_name;
  266. $insert_array['file_size'] = $_FILES['fileupload']['size'];
  267. $insert_array['upload_time'] = TIMESTAMP;
  268. $insert_array['item_id'] = intval(input('param.item_id'));
  269. $insert_array['upload_type'] = '2';
  270. $result = $upload_model->addUpload($insert_array);
  271. if ($result) {
  272. $data['file_id'] = $result;
  273. $data['file_name'] = $file_name;
  274. $data['file_path'] = ds_get_pic( $fprefix , $file_name);
  275. }
  276. }
  277. echo json_encode($data);
  278. exit;
  279. }
  280. /**
  281. * 删除图片
  282. */
  283. public function del_pic() {
  284. $condition = array();
  285. $condition[] = array('upload_id', '=', intval(input('param.file_id')));
  286. $help_model = model('help');
  287. $state = $help_model->delHelpPic($condition);
  288. if ($state) {
  289. echo 'true';
  290. exit;
  291. } else {
  292. echo 'false';
  293. exit;
  294. }
  295. }
  296. protected function getAdminItemList() {
  297. $menu_array = array(
  298. array(
  299. 'name' => 'index',
  300. 'text' => lang('help_info'),
  301. 'url' => (string) url('Storehelp/index')
  302. ), array(
  303. 'name' => 'help_type',
  304. 'text' => lang('helptype_id'),
  305. 'url' => (string) url('Storehelp/help_type')
  306. )
  307. );
  308. if (request()->action() == 'edit_help') {
  309. $menu_array[] = array(
  310. 'name' => 'edit',
  311. 'text' => lang('edit_help'),
  312. 'url' => (string) url('Storehelp/edit_help')
  313. );
  314. }
  315. if (request()->action() == 'index' || request()->action() == 'add_help') {
  316. $menu_array[] = array(
  317. 'name' => 'add_help',
  318. 'text' => lang('add_help'),
  319. 'url' => (string) url('Storehelp/add_help')
  320. );
  321. }
  322. if (request()->action() == 'help_type' || request()->action() == 'add_type') {
  323. $menu_array[] = array(
  324. 'name' => 'add_type',
  325. 'text' => lang('add_type'),
  326. 'url' => "javascript:dsLayerOpen('" . (string) url('Storehelp/add_type') . "','" . lang('add_type') . "')");
  327. }
  328. return $menu_array;
  329. }
  330. }