Upload.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 Upload extends AdminControl {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/upload.lang.php');
  20. }
  21. function default_thumb() {
  22. $config_model = model('config');
  23. $list_config = rkcache('config', true);
  24. if (!request()->isPost()) {
  25. //模板输出
  26. View::assign('list_config', $list_config);
  27. //输出子菜单
  28. $this->setAdminCurItem('default_thumb');
  29. return View::fetch('default_thumb');
  30. } else {
  31. //上传文件保存路径
  32. $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_COMMON;
  33. $update_array = array();
  34. //默认商品图片
  35. if (!empty($_FILES['default_goods_image']['name'])) {
  36. $res = ds_upload_pic(ATTACH_COMMON, 'default_goods_image', 'default_goods_image.png');
  37. if ($res['code']) {
  38. $file_name = $res['data']['file_name'];
  39. $upload['default_goods_image'] = $file_name;
  40. //生成缩略图 覆盖原有图片
  41. ds_create_thumb($upload_file, $file_name, '240,480,1280', '240,480,1280', '_240,_480,_1280');
  42. } else {
  43. $this->error($res['msg']);
  44. }
  45. }
  46. if (!empty($upload['default_goods_image'])) {
  47. $update_array['default_goods_image'] = $upload['default_goods_image'];
  48. }
  49. //默认店铺标志
  50. if (!empty($_FILES['default_store_logo']['name'])) {
  51. $res = ds_upload_pic(ATTACH_COMMON, 'default_store_logo', 'default_store_logo.png');
  52. if ($res['code']) {
  53. $file_name = $res['data']['file_name'];
  54. $upload['default_store_logo'] = $file_name;
  55. //生成缩略图 覆盖原有图片
  56. ds_create_thumb($upload_file, $file_name, '200', '200');
  57. } else {
  58. $this->error($res['msg']);
  59. }
  60. }
  61. if (!empty($upload['default_store_logo'])) {
  62. $update_array['default_store_logo'] = $upload['default_store_logo'];
  63. }
  64. //默认店铺头像
  65. if (!empty($_FILES['default_store_avatar']['name'])) {
  66. $res = ds_upload_pic(ATTACH_COMMON, 'default_store_avatar', 'default_store_avatar.png');
  67. if ($res['code']) {
  68. $file_name = $res['data']['file_name'];
  69. $upload['default_store_avatar'] = $file_name;
  70. //生成缩略图 覆盖原有图片
  71. ds_create_thumb($upload_file, $file_name, '100', '100');
  72. } else {
  73. $this->error($res['msg']);
  74. }
  75. }
  76. if (!empty($upload['default_store_avatar'])) {
  77. $update_array['default_store_avatar'] = $upload['default_store_avatar'];
  78. }
  79. //默认会员头像
  80. if (!empty($_FILES['default_user_portrait']['name'])) {
  81. $res = ds_upload_pic(ATTACH_COMMON, 'default_user_portrait', 'default_user_portrait.png');
  82. if ($res['code']) {
  83. $file_name = $res['data']['file_name'];
  84. $upload['default_user_portrait'] = $file_name;
  85. //生成缩略图 覆盖原有图片
  86. ds_create_thumb($upload_file, $file_name, '128', '128');
  87. } else {
  88. $this->error($res['msg']);
  89. }
  90. }
  91. if (!empty($upload['default_user_portrait'])) {
  92. $update_array['default_user_portrait'] = $upload['default_user_portrait'];
  93. }
  94. if (!empty($update_array)) {
  95. $result = $config_model->editConfig($update_array);
  96. } else {
  97. $result = true;
  98. }
  99. if ($result === true) {
  100. $this->log(lang('ds_edit') . lang('default_thumb'), 1);
  101. $this->success(lang('ds_common_save_succ'));
  102. } else {
  103. $this->log(lang('ds_edit') . lang('default_thumb'), 0);
  104. $this->error(lang('ds_common_save_fail'));
  105. }
  106. }
  107. }
  108. public function upload_type() {
  109. if (!request()->isPost()) {
  110. $list_config = rkcache('config', true);
  111. View::assign('list_config', $list_config);
  112. $this->setAdminCurItem('upload_type');
  113. return View::fetch();
  114. } else {
  115. $update_array = input('param.');
  116. $result = model('config')->editConfig($update_array);
  117. if ($result) {
  118. $this->success(lang('ds_common_save_succ'));
  119. } else {
  120. $this->error(lang('ds_common_save_fail'));
  121. }
  122. }
  123. }
  124. /**
  125. * 获取卖家栏目列表,针对控制器下的栏目
  126. */
  127. protected function getAdminItemList() {
  128. $menu_array = array(
  129. array(
  130. 'name' => 'default_thumb', 'text' => lang('default_thumb'), 'url' => (string) url('Upload/default_thumb')
  131. ), array(
  132. 'name' => 'upload_type', 'text' => lang('upload_set'), 'url' => (string) url('Upload/upload_type')
  133. )
  134. );
  135. return $menu_array;
  136. }
  137. }
  138. ?>