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