Upload.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 Upload extends AdminControl
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/upload.lang.php');
  18. }
  19. function default_thumb()
  20. {
  21. $config_model = model('config');
  22. $list_config = rkcache('config', true);
  23. if (!request()->isPost()) {
  24. //模板输出
  25. View::assign('list_config', $list_config);
  26. //输出子菜单
  27. $this->setAdminCurItem('default_thumb');
  28. return View::fetch('default_thumb');
  29. } else {
  30. //上传文件保存路径
  31. $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_COMMON;
  32. $update_array = array();
  33. //默认商品图片
  34. if (!empty($_FILES['default_goods_image']['name'])) {
  35. $res = ds_upload_pic(ATTACH_COMMON, 'default_goods_image', 'default_goods_image.png');
  36. if ($res['code']) {
  37. $file_name = $res['data']['file_name'];
  38. $upload['default_goods_image'] = $file_name;
  39. //生成缩略图 覆盖原有图片
  40. ds_create_thumb($upload_file, $file_name, '240,480,1280', '240,480,1280', '_240,_480,_1280');
  41. } else {
  42. $this->error($res['msg']);
  43. }
  44. }
  45. if (!empty($upload['default_goods_image'])) {
  46. $update_array['default_goods_image'] = $upload['default_goods_image'];
  47. }
  48. //默认店铺标志
  49. if (!empty($_FILES['default_store_logo']['name'])) {
  50. $res = ds_upload_pic(ATTACH_COMMON, 'default_store_logo', 'default_store_logo.png');
  51. if ($res['code']) {
  52. $file_name = $res['data']['file_name'];
  53. $upload['default_store_logo'] = $file_name;
  54. //生成缩略图 覆盖原有图片
  55. ds_create_thumb($upload_file, $file_name, '200', '200');
  56. } else {
  57. $this->error($res['msg']);
  58. }
  59. }
  60. if (!empty($upload['default_store_logo'])) {
  61. $update_array['default_store_logo'] = $upload['default_store_logo'];
  62. }
  63. //默认店铺头像
  64. if (!empty($_FILES['default_store_avatar']['name'])) {
  65. $res = ds_upload_pic(ATTACH_COMMON, 'default_store_avatar', 'default_store_avatar.png');
  66. if ($res['code']) {
  67. $file_name = $res['data']['file_name'];
  68. $upload['default_store_avatar'] = $file_name;
  69. //生成缩略图 覆盖原有图片
  70. ds_create_thumb($upload_file, $file_name, '100', '100');
  71. } else {
  72. $this->error($res['msg']);
  73. }
  74. }
  75. if (!empty($upload['default_store_avatar'])) {
  76. $update_array['default_store_avatar'] = $upload['default_store_avatar'];
  77. }
  78. //默认会员头像
  79. if (!empty($_FILES['default_user_portrait']['name'])) {
  80. $res = ds_upload_pic(ATTACH_COMMON, 'default_user_portrait', 'default_user_portrait.png');
  81. if ($res['code']) {
  82. $file_name = $res['data']['file_name'];
  83. $upload['default_user_portrait'] = $file_name;
  84. //生成缩略图 覆盖原有图片
  85. ds_create_thumb($upload_file, $file_name, '128', '128');
  86. } else {
  87. $this->error($res['msg']);
  88. }
  89. }
  90. if (!empty($upload['default_user_portrait'])) {
  91. $update_array['default_user_portrait'] = $upload['default_user_portrait'];
  92. }
  93. if (!empty($update_array)) {
  94. $result = $config_model->editConfig($update_array);
  95. } else {
  96. $result = true;
  97. }
  98. if ($result === true) {
  99. $this->log(lang('ds_edit') . lang('default_thumb'), 1);
  100. $this->success(lang('ds_common_save_succ'));
  101. } else {
  102. $this->log(lang('ds_edit') . lang('default_thumb'), 0);
  103. $this->error(lang('ds_common_save_fail'));
  104. }
  105. }
  106. }
  107. public function upload_type()
  108. {
  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. {
  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. }