Storejoin.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 Storejoin extends AdminControl
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/storejoin.lang.php');
  18. }
  19. /**
  20. * 前台头部图片传
  21. */
  22. public function index()
  23. {
  24. $size = 3; //上传显示图片总数
  25. $i = 1;
  26. $info['pic'] = array();
  27. $info['show_txt'] = '';
  28. $config_model = model('config');
  29. $list_config = rkcache('config', true);
  30. $code_info = $list_config['store_joinin_pic'];
  31. if (!empty($code_info)) {
  32. $info = unserialize($code_info);
  33. }
  34. $post = input('post.'); #获取POST 数据
  35. if (request()->isPost()) {
  36. $store_joinin_open = input('post.store_joinin_open');
  37. if (!in_array($store_joinin_open, array(0, 1, 2, 3))) {
  38. $this->error(lang('param_error'));
  39. }
  40. $info['show_txt'] = input('post.show_txt');
  41. for ($i; $i <= $size; $i++) {
  42. $file = 'pic' . $i;
  43. $info['pic'][$i] = $post['show_pic' . $i];
  44. if (!empty($_FILES[$file]['name'])) { //上传图片
  45. $filename_tmparr = explode('.', $_FILES[$file]['name']);
  46. $ext = end($filename_tmparr);
  47. $file_name = 'store_joinin_' . $i . '.' . $ext;
  48. $res = ds_upload_pic('admin/Storejion', $file, $file_name);
  49. if ($res['code']) {
  50. $file_name = $res['data']['file_name'];
  51. $info['pic'][$i] = $file_name;
  52. } else {
  53. $this->error($res['msg']);
  54. }
  55. }
  56. }
  57. $code_info = serialize($info);
  58. $update_array = array();
  59. $update_array['store_joinin_pic'] = $code_info;
  60. $update_array['store_joinin_open'] = $store_joinin_open;
  61. $config_model->editConfig($update_array);
  62. $this->success(lang('ds_common_save_succ'), 'Storejoin/index');
  63. }
  64. View::assign('store_joinin_open', $list_config['store_joinin_open']);
  65. View::assign('size', $size);
  66. View::assign('pic', $info['pic']);
  67. View::assign('show_txt', $info['show_txt']);
  68. $this->setAdminCurItem('index');
  69. return View::fetch();
  70. }
  71. /**
  72. * 入驻指南
  73. *
  74. */
  75. public function help_list()
  76. {
  77. $help_model = model('help');
  78. $condition = array();
  79. $condition[] = array('helptype_id', '=', '1');
  80. $help_list = $help_model->getStoreHelpList($condition);
  81. View::assign('help_list', $help_list);
  82. $this->setAdminCurItem('help_list');
  83. return View::fetch();
  84. }
  85. /**
  86. * 编辑入驻指南
  87. *
  88. */
  89. public function edit_help()
  90. {
  91. $help_model = model('help');
  92. $condition = array();
  93. $help_id = intval(input('param.help_id'));
  94. $condition[] = array('help_id', '=', $help_id);
  95. $help_list = $help_model->getStoreHelpList($condition);
  96. $help = $help_list[0];
  97. $help['help_info'] = str_replace("\r\n", "", $help['help_info']);
  98. View::assign('help', $help);
  99. if (request()->isPost()) {
  100. $help_array = array();
  101. $help_array['help_title'] = input('post.help_title');
  102. $help_array['help_info'] = input('post.help_info');
  103. $help_array['help_sort'] = intval(input('post.help_sort'));
  104. $help_array['help_updatetime'] = TIMESTAMP;
  105. $state = $help_model->editHelp($condition, $help_array);
  106. if ($state) {
  107. $this->log('编辑店铺入驻指南,编号' . $help_id);
  108. $this->success(lang('ds_common_save_succ'), 'storejoin/help_list');
  109. } else {
  110. $this->error(lang('ds_common_save_fail'));
  111. }
  112. }
  113. $condition = array();
  114. $condition[] = array('item_id', '=', $help_id);
  115. $pic_list = $help_model->getHelpPicList($condition);
  116. View::assign('pic_list', $pic_list);
  117. $this->setAdminCurItem('edit');
  118. return View::fetch();
  119. }
  120. /**
  121. * 上传图片
  122. */
  123. public function upload_pic()
  124. {
  125. $data = array();
  126. if (!empty($_FILES['fileupload']['name'])) { //上传图片
  127. $fprefix = 'admin/storehelp';
  128. $res = ds_upload_pic($fprefix, 'fileupload');
  129. if ($res['code']) {
  130. $file_name = $res['data']['file_name'];
  131. } else {
  132. echo json_encode($data);
  133. exit;
  134. }
  135. $upload_model = model('upload');
  136. $insert_array = array();
  137. $insert_array['file_name'] = $file_name;
  138. $insert_array['file_size'] = $_FILES['fileupload']['size'];
  139. $insert_array['upload_time'] = TIMESTAMP;
  140. $insert_array['item_id'] = intval(input('param.item_id'));
  141. $insert_array['upload_type'] = '2';
  142. $result = $upload_model->addUpload($insert_array);
  143. if ($result) {
  144. $data['file_id'] = $result;
  145. $data['file_name'] = $file_name;
  146. $data['file_path'] = ds_get_pic($fprefix, $file_name);
  147. }
  148. }
  149. echo json_encode($data);
  150. exit;
  151. }
  152. /**
  153. * 删除图片
  154. */
  155. public function del_pic()
  156. {
  157. $condition = array();
  158. $condition[] = array('upload_id', '=', intval(input('param.file_id')));
  159. $help_model = model('help');
  160. $state = $help_model->delHelpPic($condition);
  161. if ($state) {
  162. echo 'true';
  163. exit;
  164. } else {
  165. echo 'false';
  166. exit;
  167. }
  168. }
  169. protected function getAdminItemList()
  170. {
  171. $menu_array = array(
  172. array(
  173. 'name' => 'index', 'text' => lang('image_and_notice'), 'url' => (string) url('Storejoin/index')
  174. ), array(
  175. 'name' => 'help_list', 'text' => lang('joinin_guide'), 'url' => (string) url('Storejoin/help_list')
  176. )
  177. );
  178. if (request()->action() == 'edit_help') {
  179. $menu_array[] = array('name' => 'edit', 'text' => lang('edit_content'), 'url' => 'javascript:void(0)');
  180. }
  181. return $menu_array;
  182. }
  183. }