Sellersetting.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace app\api\controller;
  3. use think\Image;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 卖家店铺控制器
  10. */
  11. class Sellersetting extends MobileSeller
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize(); // TODO: Change the autogenerated stub
  16. }
  17. /**
  18. * @api {POST} api/Sellersetting/store_info 获取店铺信息
  19. * @apiVersion 1.0.0
  20. * @apiGroup Sellersetting
  21. *
  22. * @apiHeader {String} X-DS-KEY 卖家授权token
  23. *
  24. * @apiSuccess {String} code 返回码,10000为成功
  25. * @apiSuccess {String} message 返回消息
  26. * @apiSuccess {Object} result 返回数据
  27. * @apiSuccess {Object} result.store_info 店铺信息 (返回字段参考store)
  28. */
  29. public function store_info()
  30. {
  31. $this->store_info['store_avatar_url'] = get_store_logo($this->store_info['store_avatar'], 'store_avatar');
  32. ds_json_encode(10000, '', array('store_info' => $this->store_info));
  33. }
  34. /**
  35. * @api {POST} api/Sellersetting/store_edit 编辑店铺信息
  36. * @apiVersion 1.0.0
  37. * @apiGroup Sellersetting
  38. *
  39. * @apiHeader {String} X-DS-KEY 卖家授权token
  40. *
  41. * @apiParam {String} store_qq QQ
  42. * @apiParam {String} store_ww 旺旺
  43. * @apiParam {String} store_phone 手机
  44. * @apiParam {String} store_mainbusiness 主营商品
  45. * @apiParam {String} store_keywords SEO关键词
  46. * @apiParam {String} store_description SEO店铺描述
  47. *
  48. * @apiSuccess {String} code 返回码,10000为成功
  49. * @apiSuccess {String} message 返回消息
  50. * @apiSuccess {Object} result 返回数据
  51. */
  52. public function store_edit()
  53. {
  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. {
  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. }