UserController.php 5.2 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace api\portal\controller;

use cmf\controller\RestBaseController;
use think\Db;

/**
 * @title 我的
 * @description 个人中心相关接口
 */
class UserController extends RestBaseController
{
    
    /**
     * @title 我的健康档案
     * @description 健康档案页渲染
     * @author panhaowen
     * @url /portal/User/info
     * @method POST
     * @header name:XX-Token require:1 default: desc:token
     */
    public function info()
    {
        $data=Db::name('user')->where('id',$this->getUserId())->field('age,height,before_weight,last_yuejin_time,pregnant_week,weight_level,now_weight')->find();
        $data['last_yuejin_time']=date('Y-m-d',$data['last_yuejin_time']);
        $re=Db::name('user_week_sign')->where('user_id',$this->getUserId())->order('create_time','desc')->find();
        if($re){
            $data['now_weight']=$re['weight'];
        }
        $this->success('我的健康档案',$data);
    }
    /**
     * @title 我的积分管理
     * @description 积分记录接口
     * @author panhaowen
     * @url /portal/User/scoreLog
     * @method POST
     * @header name:XX-Token require:1 default: desc:token
     */
    public function  scoreLog(){
        $data=Db::name('user_score_log')->where('user_id',$this->getUserId())->select();
        $this->success('我的积分管理',$data);
    }
    /**
     * @title 注册信息提交
     * @description 注册信息提交接口
     * @author panhaowen
     * @url /portal/User/registerPost
     * @method POST
     * @header name:XX-Token require:1 default: desc:token
     * @param name:age require:1 desc:年龄(岁)
     * @param name:height require:1 desc:身高(cm)
     * @param name:before_weight require:1 desc:孕前体重(kg)
     * @param name:last_yuejin_time require:1 desc:末次月经第一天
     * @param name:pregnant_week require:1 desc:孕周
     * @param name:now_weight require:1 desc:当前体重
     * @param name:weight_level require:1 desc:体力活动水平(休息状态,轻体力,中体力,重体力)
     */
    public function  registerPost(){
        $param=$this->request->param();
        $param['user_status']=1;
        $param['register_time']=time();
        $param['last_yuejin_time']=strtotime($param['last_yuejin_time']);
        Db::name('user')->where('id',$this->getUserId())->update($param);
        $this->success('注册信息提交成功');
    }

    /**
     * @title 手机号注册
     * @description 手机号注册提交接口
     * @author panhaowen
     * @url /portal/User/mobile
     * @method POST
     * @header name:XX-Token require:1 default: desc:token
     * @param name:mobile require:1
     * @param name:code require:1
     */
    public function  mobile(){
        $param=$this->request->param();
        $re = cmf_check_verification_code($param['mobile'], $param['code'], true);
        if ($re == "") {
            Db::name('user')->where('id',$this->getUserId())->update(['mobile'=>$param['mobile']]);
            $this->success('手机号注册提交成功');
        } else {
            $this->error($re);
        }
    }

    /**
     * @title 获取验证码
     * @description 获取验证码接口
     * @author panhaowen
     * @url /portal/User/getCode
     * @method POST
     * @header name:XX-Token require:1 default: desc:token
     * @param name:mobile require:1
     */
    public function  getCode(){
        require_once VENDOR_PATH . "sms/lib/Ucpaas.class.php";
        $param=$this->request->param();
        $options['accountsid']='d63e23ab657c95babad1681133dbabdc';
//填写在开发者控制台首页上的Auth Token
        $options['token']='1fc7377f48edb5bf1659284210f16418';


        $code = cmf_get_verification_code($param['mobile'], 4);
        $appid = "78950d10e37b4ae5bd9b9c08f3720db3";	//应用的ID,可在开发者控制台内的短信产品下查看
        $templateid = "41494";    //可在后台短信产品→选择接入的应用→短信模板-模板ID,查看该模板ID
        $uid = "";
//70字内(含70字)计一条,超过70字,按67字/条计费,超过长度短信平台将会自动分割为多条发送。分割后的多条短信将按照具体占用条数计费。

        $send=new \Ucpaas($options);
        $re=$send->SendSms($appid,$templateid,$code,$param['mobile'],$uid);
        cmf_verification_code_log($param['mobile'], $code, 180);
        $this->success('',$re);
    }

    /**
     * @title 我的页面
     * @description 我的页面渲染接口
     * @author panhaowen
     * @url /portal/User/my
     * @method POST
     * @header name:XX-Token require:1 default: desc:token
     * @return user_status:1:普通会员,2:vip
     */
    public function  my(){
        $user=Db::name('user')->where('id',$this->getUserId())->field('user_nickname,user_status,avatar')->find();
        $user['avatar']=cmf_get_image_preview_url( $user['avatar']);
        $this->success('获取成功',$user);
    }
}