Sellersetting.php 5.6 KB

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