Upload.php 6.2 KB

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