Sellersetting.php 5.7 KB

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