quanwei
2025-10-30 204b4cb1fcf1234010f722e0c9d4e88d10e654b1
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
<?php
 
namespace app\api\controller\user;
 
use app\api\model\user\User as UserModel;
use app\api\controller\Controller;
use app\api\model\settings\Setting as SettingModel;
use app\common\library\easywechat\AppWx;
 
/**
 * 用户管理模型
 */
class User extends Controller
{
    /**
     * 用户自动登录,默认微信小程序
     */
    public function login()
    {
        $model = new UserModel;
        $user_id = $model->login($this->request->post());
        return $this->renderSuccess('', [
            'user_id' => $user_id,
            'token' => $model->getToken()
        ]);
    }
 
    /**
     * 企业微信
     */
    public function qyLogin()
    {
        $model = new UserModel;
        $is_exist = $model->qyLogin($this->request->post());
        return $this->renderSuccess('', [
            'is_exist' => $is_exist,
        ]);
    }
 
    /**
     * 当前用户详情
     */
    public function detail()
    {
        // 当前用户信息
        $userInfo = $this->getUser();
        $gift_name = SettingModel::getItem('live')['gift_name'];
        return $this->renderSuccess('', compact('userInfo', 'gift_name'));
    }
 
    public function getSession($code)
    {
        // 微信登录 获取session_key
        $app = AppWx::getApp();
        $session_key = null;
        $session = AppWx::sessionKey($app, $code);
        if($session != null){
            $session_key = $session['session_key'];
        }
        return $this->renderSuccess('', compact('session_key'));
    }
 
    /**
     * 绑定手机号
     */
    public function bindMobile()
    {
        $model = $this->getUser();
        if ($model->bindMobile($this->request->post())) {
            return $this->renderSuccess('');
        }
        return $this->renderError('绑定失败');
    }
 
    /**
     * 修改用户信息
     */
    public function updateInfo()
    {
        // 当前用户信息
        $model = $this->getUser();
        if ($model->edit($this->request->post())) {
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError($model->getError() ?: '修改失败');
    }
 
    /**
     * 积分转换余额
     */
    public function transPoints($points = 0)
    {
        // 当前用户信息
        $model = $this->getUser();
        if ($model->transPoints($points)) {
            return $this->renderSuccess('转换成功');
        }
        return $this->renderError($model->getError() ?: '转换失败');
    }
}