Storejoin.php 7.0 KB

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