123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace app\api\controller;
- use think\Image;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 卖家店铺控制器
- */
- class Sellersetting extends MobileSeller
- {
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- }
- /**
- * @api {POST} api/Sellersetting/store_info 获取店铺信息
- * @apiVersion 1.0.0
- * @apiGroup Sellersetting
- *
- * @apiHeader {String} X-DS-KEY 卖家授权token
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- * @apiSuccess {Object} result.store_info 店铺信息 (返回字段参考store)
- */
- public function store_info()
- {
- $this->store_info['store_avatar_url'] = get_store_logo($this->store_info['store_avatar'], 'store_avatar');
- ds_json_encode(10000, '', array('store_info' => $this->store_info));
- }
- /**
- * @api {POST} api/Sellersetting/store_edit 编辑店铺信息
- * @apiVersion 1.0.0
- * @apiGroup Sellersetting
- *
- * @apiHeader {String} X-DS-KEY 卖家授权token
- *
- * @apiParam {String} store_qq QQ
- * @apiParam {String} store_ww 旺旺
- * @apiParam {String} store_phone 手机
- * @apiParam {String} store_mainbusiness 主营商品
- * @apiParam {String} store_keywords SEO关键词
- * @apiParam {String} store_description SEO店铺描述
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- */
- public function store_edit()
- {
- /**
- * 更新入库
- */
- $param = array(
- 'store_qq' => input('post.store_qq'), 'store_ww' => input('post.store_ww'), 'store_phone' => input('post.store_phone'),
- 'store_mainbusiness' => input('post.store_mainbusiness'), 'store_keywords' => input('post.seo_keywords'),
- 'store_description' => input('post.seo_description'),
- 'store_avatar' => input('post.store_avatar')
- );
- $result = model('store')->editStore($param, array('store_id' => $this->store_info['store_id']));
- if (!$result) {
- ds_json_encode(10001, lang('ds_common_op_fail'));
- }
- if ($param['store_avatar'] != $this->store_info['store_avatar']) {
- //删除原图
- $store_id = $this->store_info['store_id'];
- $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE . DIRECTORY_SEPARATOR . $store_id;
- @unlink($upload_file . DIRECTORY_SEPARATOR . $this->store_info['store_avatar']);
- }
- ds_json_encode(10000, lang('ds_common_op_succ'), 1);
- }
- /**
- * @api {POST} api/Sellersetting/store_image_upload 更新店铺图片
- * @apiVersion 1.0.0
- * @apiGroup Sellersetting
- *
- * @apiHeader {String} X-DS-KEY 卖家授权token
- *
- * @apiParam {File} file 店铺图片
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {String} result 店铺图片
- */
- public function store_image_upload()
- {
- $store_id = $this->store_info['store_id'];
- $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_STORE . DIRECTORY_SEPARATOR . $store_id;
- $file_name = $this->store_info['store_id'] . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
- $store_image_name = input('param.id');
- if (!in_array($store_image_name, array('store_logo', 'store_banner', 'store_avatar'))) {
- ds_json_encode(10001, lang('param_error'));
- }
- if (!empty($_FILES[$store_image_name]['name'])) {
- $res = ds_upload_pic(ATTACH_STORE . DIRECTORY_SEPARATOR . $store_id, $store_image_name, $file_name);
- if ($res['code']) {
- $file_name = $res['data']['file_name'];
- if (file_exists($upload_file . DIRECTORY_SEPARATOR . $file_name)) {
- /* 处理图片 */
- $image = Image::open($upload_file . DIRECTORY_SEPARATOR . $file_name);
- switch ($store_image_name) {
- case 'store_logo':
- $image->thumb(200, 60, \think\Image::THUMB_CENTER)->save($upload_file . DIRECTORY_SEPARATOR . $file_name);
- break;
- case 'store_banner':
- $image->thumb(1920, 150, \think\Image::THUMB_CENTER)->save($upload_file . DIRECTORY_SEPARATOR . $file_name);
- break;
- case 'store_avatar':
- $image->thumb(100, 100, \think\Image::THUMB_CENTER)->save($upload_file . DIRECTORY_SEPARATOR . $file_name);
- break;
- default:
- break;
- }
- }
- } else {
- ds_json_encode(10001, $res['msg']);
- }
- }
- $data = array();
- $data['file_name'] = $file_name;
- $data['file_path'] = ds_get_pic(ATTACH_STORE . '/' . $store_id, $file_name);
- ds_json_encode(10000, '', $data);
- }
- }
|