Sellersetting.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\api\controller;
  3. use think\Image;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 卖家店铺控制器
  15. */
  16. class Sellersetting extends MobileSeller {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. }
  20. /**
  21. * @api {POST} api/Sellersetting/store_info 获取店铺信息
  22. * @apiVersion 1.0.0
  23. * @apiGroup Sellersetting
  24. *
  25. * @apiHeader {String} X-DS-KEY 卖家授权token
  26. *
  27. * @apiSuccess {String} code 返回码,10000为成功
  28. * @apiSuccess {String} message 返回消息
  29. * @apiSuccess {Object} result 返回数据
  30. * @apiSuccess {Object} result.store_info 店铺信息 (返回字段参考store)
  31. */
  32. public function store_info() {
  33. $this->store_info['store_avatar_url'] = get_store_logo($this->store_info['store_avatar'], 'store_avatar');
  34. ds_json_encode(10000, '', array('store_info' => $this->store_info));
  35. }
  36. /**
  37. * @api {POST} api/Sellersetting/store_edit 编辑店铺信息
  38. * @apiVersion 1.0.0
  39. * @apiGroup Sellersetting
  40. *
  41. * @apiHeader {String} X-DS-KEY 卖家授权token
  42. *
  43. * @apiParam {String} store_qq QQ
  44. * @apiParam {String} store_ww 旺旺
  45. * @apiParam {String} store_phone 手机
  46. * @apiParam {String} store_mainbusiness 主营商品
  47. * @apiParam {String} store_keywords SEO关键词
  48. * @apiParam {String} store_description SEO店铺描述
  49. *
  50. * @apiSuccess {String} code 返回码,10000为成功
  51. * @apiSuccess {String} message 返回消息
  52. * @apiSuccess {Object} result 返回数据
  53. */
  54. public function store_edit() {
  55. /**
  56. * 更新入库
  57. */
  58. $param = array(
  59. 'store_qq' => input('post.store_qq'), 'store_ww' => input('post.store_ww'), 'store_phone' => input('post.store_phone'),
  60. 'store_mainbusiness' => input('post.store_mainbusiness'), 'store_keywords' => input('post.seo_keywords'),
  61. 'store_description' => input('post.seo_description'),
  62. 'store_avatar' => input('post.store_avatar')
  63. );
  64. $result = model('store')->editStore($param, array('store_id' => $this->store_info['store_id']));
  65. if (!$result) {
  66. ds_json_encode(10001, lang('ds_common_op_fail'));
  67. }
  68. if ($param['store_avatar'] != $this->store_info['store_avatar']) {
  69. //删除原图
  70. $store_id = $this->store_info['store_id'];
  71. $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE . DIRECTORY_SEPARATOR . $store_id;
  72. @unlink($upload_file . DIRECTORY_SEPARATOR . $this->store_info['store_avatar']);
  73. }
  74. ds_json_encode(10000, lang('ds_common_op_succ'), 1);
  75. }
  76. /**
  77. * @api {POST} api/Sellersetting/store_image_upload 更新店铺图片
  78. * @apiVersion 1.0.0
  79. * @apiGroup Sellersetting
  80. *
  81. * @apiHeader {String} X-DS-KEY 卖家授权token
  82. *
  83. * @apiParam {File} file 店铺图片
  84. *
  85. * @apiSuccess {String} code 返回码,10000为成功
  86. * @apiSuccess {String} message 返回消息
  87. * @apiSuccess {String} result 店铺图片
  88. */
  89. public function store_image_upload() {
  90. $store_id = $this->store_info['store_id'];
  91. $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE . DIRECTORY_SEPARATOR . $store_id;
  92. $file_name = $this->store_info['store_id'] . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  93. $store_image_name = input('param.id');
  94. if (!in_array($store_image_name, array('store_logo', 'store_banner', 'store_avatar'))) {
  95. ds_json_encode(10001, lang('param_error'));
  96. }
  97. if (!empty($_FILES[$store_image_name]['name'])) {
  98. $res = ds_upload_pic(ATTACH_STORE . DIRECTORY_SEPARATOR . $store_id, $store_image_name, $file_name);
  99. if ($res['code']) {
  100. $file_name = $res['data']['file_name'];
  101. if(file_exists($upload_file . DIRECTORY_SEPARATOR . $file_name)){
  102. /* 处理图片 */
  103. $image = Image::open($upload_file . DIRECTORY_SEPARATOR . $file_name);
  104. switch ($store_image_name) {
  105. case 'store_logo':
  106. $image->thumb(200, 60, \think\Image::THUMB_CENTER)->save($upload_file . DIRECTORY_SEPARATOR . $file_name);
  107. break;
  108. case 'store_banner':
  109. $image->thumb(1920, 150, \think\Image::THUMB_CENTER)->save($upload_file . DIRECTORY_SEPARATOR . $file_name);
  110. break;
  111. case 'store_avatar':
  112. $image->thumb(100, 100, \think\Image::THUMB_CENTER)->save($upload_file . DIRECTORY_SEPARATOR . $file_name);
  113. break;
  114. default:
  115. break;
  116. }
  117. }
  118. } else {
  119. ds_json_encode(10001, $res['msg']);
  120. }
  121. }
  122. $data = array();
  123. $data['file_name'] = $file_name;
  124. $data['file_path'] = ds_get_pic( ATTACH_STORE . '/' . $store_id , $file_name);
  125. ds_json_encode(10000, '', $data);
  126. }
  127. }