User.php 25.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Sms;
use app\common\model\User as UserModel;
use app\common\model\UserAddress;
use app\common\model\UserSize;
use app\common\model\Area;
use app\common\controller\Wechat;
use think\Validate;

/**
 * 会员接口
 */
class User extends Api
{
    protected $noNeedLogin = ['index','login','measure'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('app\common\model\User');
        $this->user = $this->auth->getUser();
    }

    /**
     * 我的-首页
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function index()
    {
        // 当前用户信息
        $user = $this->user;
        $coupon_count = \app\common\model\UserCoupon::alias('uc')
            ->join('coupon c','c.id = uc.coupon_id')
            ->where('uc.user_id',$this->user['id'])
            ->where('uc.status','1')
            ->where('c.expiretime','>',time())
            ->count();
        return $this->success('成功',compact('user','coupon_count'));
    }

    /**
     * 我的-授权登录
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="code", type="string", required=true, description="重定向code")
     * @ApiParams   (name="user_info", type="object", required=true, description="用户信息", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}")
     * @ApiParams   (name="testopenid", type="string", description="测试openid")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function login()
    {
        $code = $this->request->post('code');
        $user_info = $this->request->post('user_info');
        $testopenid = $this->request->post('testopenid');
        $session = Wechat::miniProgram()->auth->session($code);
        // 自动注册用户
        $userInfo = json_decode(htmlspecialchars_decode($user_info), true);
        if (!$user = $this->model->get(['openid' => $session['openid']])) {
            $user = $this->model;
            $userInfo['openid'] = $session['openid'];
        }
        $userInfo['nickname'] = preg_replace('/[\xf0-\xf7].{3}/', '', $userInfo['nickName']);
        $userInfo['avatar'] = $userInfo['avatarUrl'];
        if (!$user->allowField(true)->save($userInfo)) {
            $this->error('用户登录失败');
        }
        // $session = [
        //     'openid' => $testopenid ?: 'test',
        // ];
        // $user = $this->model->get(['openid' => $session['openid']]);
        // 生成token (session3rd)
        $guid = guidv4();// 生成一个不会重复的随机字符串
        $timeStamp = microtime(true);// 当前时间戳 (精确到毫秒)
        $salt = 'token_salt';// 自定义一个盐
        $token = md5("{$timeStamp}_{$session['openid']}_{$guid}_{$salt}");
        $this->auth->direct($user['id'],$token);
        $this->success(__('登录成功'),[
            'token' => $token,
            'avatar' => $user['avatar']
        ]);
    }

    /**
     * 我的-成为会员(会员介绍)
     * @ApiMethod   (GET)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function memberIntro()
    {
        $member_intro = str_replace('src="/uploads/', 'src="'.cdnurl('/uploads/',true), config('site.member_intro'));
        $this->success(__('成功'),compact('member_intro'));
    }

    /**
     * 我的-成为会员(绑定手机号)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="mobile", type="string", required=true, description="手机号")
     * @ApiParams   (name="captcha", type="string", required=true, description="验证码")
     * @ApiParams   (name="area", type="string", required=true, description="所在地区", sample="广东省,广州市,海珠区")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function bindMobile()
    {
        $mobile = $this->request->post('mobile');
        $captcha = $this->request->post('captcha');
        $area = $this->request->post('area');
        if (!empty($this->user['mobile'])) {
            $this->error(__('您已经成为会员,请勿重复操作'));
        }
        if (!$mobile || !$captcha || !$area) {
            $this->error(__('Invalid parameters'));
        }
        if (!Validate::regex($mobile, "^1\d{10}$")) {
            $this->error(__('Mobile is incorrect'));
        }
        if ($this->model->where('mobile', $mobile)->where('id', '<>', $this->user['id'])->find()) {
            $this->error(__('Mobile already exists'));
        }
        // $result = Sms::check($mobile, $captcha, 'changemobile');
        $result = \app\api\controller\Sms::check($mobile, $captcha, 'changemobile');
        if (!$result) {
            $this->error(__('Captcha is incorrect'));
        }
        $area = explode(',', $area);
        $province_id = Area::getIdByName($area[0], 1);
        $city_id = Area::getIdByName($area[1], 2, $province_id);
        $district_id = Area::getIdByName($area[2], 3, $city_id);
        $this->user->allowField(true)->save(compact('mobile','province_id', 'city_id', 'district_id'));

        Sms::flush($mobile, 'changemobile');
        $this->success(__('注册成功'));
    }

    /**
     * 我的-积分记录
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="rows", type="integer", required=true, description="每页条数")
     * @ApiParams   (name="page", type="integer", required=true, description="页码")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function scoreLog(){
        $rows = $this->request->get('rows',null);// 每页条数
        $page = $this->request->get('page',1);// 页码
        $list = $this->model->scoreLog($this->user['id'],$page,$rows);
        $this->success(__('成功'),array_merge([
            'score' => $this->user['score']
        ],$list));
    }

    /**
     * 我的-优惠券
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="status", type="string", required=true, description="优惠券状态:all=全部,normal=正常,soon_expire=即将到期,expired=已到期,used=已使用")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="0", sample="返回成功", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function couponList(){
        $status = $this->request->get('status');
        $list = \app\common\model\UserCoupon::couponList($this->user, $status);
        $this->success(__('成功'),compact('list'));
    }

    /**
     * 我的地址-列表
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function addressList()
    {
        $list = UserAddress::addressList($this->user['id']);
        $this->success(__('成功'),compact('list'));
    }

    /**
     * @ApiTitle    (我的地址-添加)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="name", type="string", required=true, description="收货人")
     * @ApiParams   (name="phone", type="string", required=true, description="手机号码")
     * @ApiParams   (name="area", type="string", required=true, description="所在地区", sample="广东省,广州市,海珠区")
     * @ApiParams   (name="detail", type="string", description="详细地址")
     * @ApiParams   (name="isdefault", type="string", description="是否默认:0=否,1=是")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function addressAdd()
    {
        $post = $this->request->post();
        empty($post['name']) && $this->error(__('请填写收货人'));
        empty($post['phone']) && $this->error(__('请填写手机号码'));
        empty($post['area']) && $this->error(__('请选择所在地区'));
        empty($post['detail']) && $this->error(__('请填写详细地址'));
        if ((new UserAddress)->add($this->user, $post)) {
            $this->success(__('添加成功'));
        }
        $this->error(__('添加失败'));
    }

    /**
     * 我的地址-详情
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="user_address_id", type="integer", required=true, description="地址ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function addressDetail()
    {
        $user_address_id = $this->request->get('user_address_id');
        $detail = UserAddress::detail($this->user['id'],$user_address_id);
        $this->success(__('成功'),compact('detail'));
    }

    /**
     * 我的地址-编辑
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="user_address_id", type="integer", required=true, description="地址ID")
     * @ApiParams   (name="name", type="string", required=true, description="收货人")
     * @ApiParams   (name="phone", type="string", required=true, description="手机号码")
     * @ApiParams   (name="area", type="object", required=true, description="所在地区", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}")
     * @ApiParams   (name="detail", type="string", description="详细地址")
     * @ApiParams   (name="isdefault", type="string", description="是否默认:0=否,1=是")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function addressEdit()
    {
        $post = $this->request->post();
        $model = UserAddress::detail($this->user['id'], $post['user_address_id']);
        if(empty($model)){
            $this->error(__('地址不存在'));
        }
        empty($post['name']) && $this->error(__('请填写收货人'));
        empty($post['phone']) && $this->error(__('请填写手机号码'));
        empty($post['area']) && $this->error(__('请选择所在地区'));
        empty($post['detail']) && $this->error(__('请填写详细地址'));
        if ($model->edit($post)) {
            $this->success(__('更新成功'));
        }
        $this->error(__('更新失败'));
    }

    /**
     * 我的地址-删除
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="user_address_id", type="integer", required=true, description="地址ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function addressDelete()
    {
        $user_address_id = $this->request->get('user_address_id');
        $model = UserAddress::detail($this->user['id'], $user_address_id);
        if ($model->remove($this->user)) {
            $this->success(__('删除成功'));
        }
        $this->error(__('删除失败'));
    }

    /**
     * 我的地址-设为默认
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="user_address_id", type="integer", required=true, description="尺寸ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function addressDefault()
    {
        $user_address_id = $this->request->get('user_address_id');
        $model = UserAddress::detail($this->user['id'], $user_address_id);
        if ($model->setDefault()) {
            $this->success(__('设置成功'));
        }
        $this->error(__('设置失败'));
    }

    /**
     * 我的尺寸-列表
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function sizeList()
    {
        $list = UserSize::sizeList($this->user['id']);
        $this->success(__('成功'),compact('list'));
    }

    /**
     * 我的尺寸-身体信息
     * @ApiMethod   (GET)
     * @ApiParams   (name="gender", type="string", required=true, description="性别:1=男,2=女")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function bodyInfo()
    {
        $gender = $this->request->get('gender','1');
        $list = \app\common\model\Style::styleList($gender);
        $this->success(__('成功'),compact('list'));
    }

    /**
     * 我的尺寸-身材特征
     * @ApiMethod   (GET)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function bodyFeatures()
    {
        $list = \app\common\model\Style::styleList(3);
        $this->success(__('成功'),compact('list'));
    }

    /**
     * 我的尺寸-全身照或半身照
     * @ApiMethod   (GET)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function bodyImage()
    {
        $list = \app\common\model\Style::styleList(4);
        $this->success(__('成功'),compact('list'));
    }

    /**
     * @ApiTitle    (我的尺寸-添加)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="name", type="string", required=true, description="尺寸名称")
     * @ApiParams   (name="height", type="integer", required=true, description="身高(厘米)")
     * @ApiParams   (name="weight", type="integer", required=true, description="体重(公斤)")
     * @ApiParams   (name="collar", type="integer", description="领围(厘米)")
     * @ApiParams   (name="hipline", type="integer", description="臀围(厘米)")
     * @ApiParams   (name="arm_length", type="integer", description="臂长(厘米)")
     * @ApiParams   (name="bust", type="integer", description="胸围(厘米)")
     * @ApiParams   (name="shoulder_width", type="integer", description="肩宽(厘米)")
     * @ApiParams   (name="gender", type="string", required=true, description="性别:1=男,2=女")
     * @ApiParams   (name="body_info", type="object", required=true, description="身体信息")
     * @ApiParams   (name="body_features", type="string", description="身体特征,多个值用英文逗号分隔")
     * @ApiParams   (name="remark", type="string", description="备注")
     * @ApiParams   (name="body_images", type="file", description="身材照片,多文件")
     * @ApiParams   (name="isdefault", type="string", description="是否默认:0=否,1=是")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function sizeAdd()
    {
        $post = $this->request->post();
        empty($post['name']) && $this->error(__('请填写尺寸名称'));
        empty($post['height']) && $this->error(__('请填写身高'));
        empty($post['weight']) && $this->error(__('请填写体重'));
        empty($post['gender']) && $this->error(__('请选择性别'));
        empty($post['body_info']) && $this->error(__('请选择身体信息'));
        if ((new UserSize)->add($this->user, $post)) {
            $this->success(__('添加成功'));
        }
        $this->error(__('添加失败'));
    }

    /**
     * 我的尺寸-详情
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="user_size_id", type="integer", required=true, description="尺寸ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function sizeDetail()
    {
        $user_size_id = $this->request->get('user_size_id');
        $detail = UserSize::detail($this->user['id'],$user_size_id);
        $this->success(__('成功'),compact('detail'));
    }

    /**
     * 我的尺寸-编辑
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="user_size_id", type="integer", required=true, description="尺寸ID")
     * @ApiParams   (name="name", type="string", required=true, description="尺寸名称")
     * @ApiParams   (name="height", type="integer", required=true, description="身高(厘米)")
     * @ApiParams   (name="weight", type="integer", required=true, description="体重(公斤)")
     * @ApiParams   (name="collar", type="integer", description="领围(厘米)")
     * @ApiParams   (name="hipline", type="integer", description="臀围(厘米)")
     * @ApiParams   (name="arm_length", type="integer", description="臂长(厘米)")
     * @ApiParams   (name="bust", type="integer", description="胸围(厘米)")
     * @ApiParams   (name="shoulder_width", type="integer", description="肩宽(厘米)")
     * @ApiParams   (name="gender", type="string", required=true, description="性别:1=男,2=女")
     * @ApiParams   (name="body_info", type="object", required=true, description="身体信息")
     * @ApiParams   (name="body_features", type="string", description="身体特征,多个值用英文逗号分隔")
     * @ApiParams   (name="remark", type="string", description="备注")
     * @ApiParams   (name="body_images", type="file", description="身材照片,多文件")
     * @ApiParams   (name="isdefault", type="string", description="是否默认:0=否,1=是")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function sizeEdit()
    {
        $post = $this->request->post();
        $model = UserSize::detail($this->user['id'], $post['user_size_id']);
        if(empty($model)){
            $this->error(__('尺寸信息不存在'));
        }
        empty($post['name']) && $this->error(__('请填写尺寸名称'));
        empty($post['height']) && $this->error(__('请填写身高'));
        empty($post['weight']) && $this->error(__('请填写体重'));
        empty($post['gender']) && $this->error(__('请选择性别'));
        empty($post['body_info']) && $this->error(__('请选择身体信息'));
        if ($model->edit($post)) {
            $this->success(__('更新成功'));
        }
        $this->error(__('更新失败'));
    }

    /**
     * 我的尺寸-删除
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="user_size_id", type="integer", required=true, description="尺寸ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function sizeDelete()
    {
        $user_size_id = $this->request->get('user_size_id');
        $model = UserSize::detail($this->user['id'], $user_size_id);
        if ($model->remove($this->user)) {
            $this->success(__('删除成功'));
        }
        $this->error(__('删除失败'));
    }

    /**
     * 我的尺寸-设为默认
     * @ApiMethod   (GET)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="user_size_id", type="integer", required=true, description="尺寸ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function sizeDefault()
    {
        $user_size_id = $this->request->get('user_size_id');
        $model = UserSize::detail($this->user['id'], $user_size_id);
        if ($model->setDefault()) {
            $this->success(__('设置成功'));
        }
        $this->error(__('设置失败'));
    }

    /**
     * 我的尺寸-量体教程
     * @ApiMethod   (GET)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function measure()
    {
        $measure = str_replace('src="/uploads/', 'src="'.cdnurl('/uploads/',true), config('site.measure'));
        $this->success(__('成功'),compact('measure'));
    }
}