quanwei
2025-11-21 2d9362ae6f528f57e6133d5d80f0b633c24e8eb6
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
<?php
 
namespace app\api\controller\user;
 
use app\api\controller\Controller;
use app\api\model\plus\agent\Setting;
use app\api\model\user\User as UserModel;
use app\api\model\order\Order as OrderModel;
use app\api\model\settings\Setting as SettingModel;
use app\api\model\plus\coupon\UserCoupon as UserCouponModel;
use app\common\enum\settings\GetPhoneTypeEnum;
use think\facade\Cache;
use app\api\model\supplier\Supplier as SupplierModel;
use app\api\model\plus\chat\Chat as ChatModel;
use app\common\model\app\AppWx as AppWxModel; //by lyzflash
use app\api\model\user\UserAuth as UserAuthModel; //by lyzflash
use app\api\model\user\CardRecord as CardRecordModel; //by lyzflash
use app\api\model\user\Card as CardModel; //by lyzflash
use app\api\model\supplier\Balance as SupplierBalanceModel;
use app\common\model\branch\User as BranchUserModel; //by lyzflash
 
/**
 * 个人中心主页
 */
class Index extends Controller
{
    /**
     * 获取当前用户信息
     */
    public function detail($source = 'wx')
    {
        // 当前用户信息
        $user = $this->getUser();
 
        //付呗分账相关 by lyzflash
        // $wxConfig = AppWxModel::getAppWxCache($user['app_id']);
        // $user['isFbpay'] = $wxConfig["apitype"] == 1; //付呗支付
        // $user['auth_status'] = UserAuthModel::authStatus($user['user_id']);
 
        // 同步瑞和购物旧系统积分 by lyzflsh
        if ($user['app_id'] == 10027) {
            (new UserModel)->syncPoints($user['open_id']);
        }
        //店铺信息
        $user['is_recycle'] = $user['supplierUser']?SupplierModel::detail($user['supplierUser']['shop_supplier_id'])['is_recycle']:'';
        $coupon_model = new UserCouponModel();
        $coupon = count($coupon_model->getList($user['user_id'], -1, false, false));
        // 订单总数
        $model = new OrderModel;
 
        // 分销商基本设置
        $setting = Setting::getItem('basic');
        // 是否开启分销功能
        $agent_open = $setting['is_open'];
        //商城设置
        $store = SettingModel::getItem('store');
        //供应商入住背景图
        $supplier_image = isset($store['supplier_image'])?$store['supplier_image']:'';
        // 充值功能是否开启
        $balance_setting = SettingModel::getItem('balance');
        $balance_open = intval($balance_setting['is_open']);
        $cardDetail = CardRecordModel::getCardDetail($user['user_id']); // 会员卡 by lyzflash
        $cardCount = (new CardModel)->getCount($user);
 
        //商户是否独立收款 by yj 2024.3.14
        $is_independent = SettingModel::getIndependentOpen();
        if(!empty($is_independent) && $is_independent == 1){
            //获取每个商户加起来的余额
            $user["balance"] = SupplierBalanceModel::getTotalBalance($user['user_id']);
        }
 
        // 判断用户是不是分会管理员 by lyzflash
        $user['is_branch_manager'] = BranchUserModel::isManager($user['user_id']);
 
        return $this->renderSuccess('', [
            'coupon' => $coupon,
            'userInfo' => $user,
            'orderCount' => [
                'payment' => $model->getCount($user, 'payment'),
                'delivery' => $model->getCount($user, 'delivery'),
                'received' => $model->getCount($user, 'received'),
                'comment' => $model->getCount($user, 'comment'),
            ],
            'setting' => [
                'points_name' => SettingModel::getPointsName(),
                'agent_open' => $agent_open,
                'supplier_image' => $supplier_image,
                'balance_open' => $balance_open
            ],
            'sign' => SettingModel::getItem('sign'),
            'getPhone' => $this->isGetPhone(),
            'msgcount' => (new ChatModel)->mCount($user),
            'menus' => UserModel::getMenus($user, $source),   // 个人中心菜单列表
            'cardDetail' => $cardDetail,//会员卡信息 by lyzflash
            'card_total' => empty($cardCount) ? "" : $cardCount['cardCount'],
            //是否显示店铺信息
            'store_open' => SettingModel::getStoreOpen(),
        'supplierStatus' => SupplierModel::getStatus($user),
        ]);
    }
 
    /**
     * 当前用户设置
     */
    public function setting()
    {
        // 当前用户信息
        $user = $this->getUser();
 
        //by lyzflash
        $wxConfig = AppWxModel::getAppWxCache($user['app_id']);
        $user['isFbpay'] = $wxConfig["apitype"] == 1; //付呗支付
        $user['auth_status'] = UserAuthModel::authStatus($user['user_id']);
 
        return $this->renderSuccess('', [
            'userInfo' => $user
        ]);
    }
 
    private function isGetPhone()
    {
        $user = $this->getUser();
        if($user['mobile'] != ''){
            return false;
        }
        $settings = SettingModel::getItem('getPhone');
        if(in_array(GetPhoneTypeEnum::USER, $settings['area_type'])){
            // 缓存时间
            $key = 'get_phone_' . $user['user_id'];
            if (!$data = Cache::get($key)) {
                $settings['send_day'] > 0 && Cache::set($key, '1', 86400 * $settings['send_day']);
                return true;
            }
        }
        return false;
    }
}