UserData.php 18.8 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 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
<?php

namespace LibModels\Web\Home;

use Api\Yohobuy;
use Api\Sign;
use WebPlugin\Helpers;

class UserData
{

    /**
     * 根据手机号获取用户信息[TODO +cache]
     *
     * @param string $area
     * @param string $mobile
     * @return array
     */
    public static function getUserInfoByMobile($area, $mobile)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.getProfileByMobile';
        $param['mobile'] = $mobile;
        $param['area'] = $area;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 根据email获取用户信息
     * 
     * @param string $email
     * @return array
     */
    public static function getUserInfoByEmail($email)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.getProfileByEmail';
        $param['email'] = $email;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 查询个人信息
     *
     * @param int $uid 用户ID
     * @return array 个人详情接口返回的数据
     */
    public static function getUserInfo($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.profile';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 修改个人详情数据
     *
     * @param array $params 需要修改的参数集合
     * uid:用户ID
     * username:真实姓名
     * nick_name:昵称
     * gender:性别
     * birthday:生日
     * headIco:头像
     * income:收入
     * profession:职位
     */
    public static function editUserInfo($params)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.modifyBase';
        $param['uid'] = $params['uid'];
        $param['nick_name'] = $params['nickname'];
        $param['username'] = $params['username'];
        $param['gender'] = $params['gender'];
        $param['profession'] = $params['profession'];
        $param['income'] = $params['income'];
        $param['birthday'] = $params['birthday'];
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 查询用户联系信息
     *
     * @param int $uid 用户ID
     * @return array 返回的数据
     */
    public static function getUserContactInfo($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'web.passport.getUserContacts';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 修改用户联系信息
     * @param array $params 需要修改的参数集合
     * uid:用户ID
     * area_code:区域code 2-4-6 取最后一位地区
     * phone:固定电话
     * mobile:手机号码
     * qq
     * full_address:联系地址
     * zip_code:邮编
     */
    public static function editUserContactInfo($params)
    {
        $param = Yohobuy::param();
        $param['method'] = 'web.passport.modifyUserContacts';
        $param['uid'] = $params['uid'];
        $param['area_code'] = $params['areaCode'];
        $param['phone'] = $params['phone'];
        $param['mobile'] = $params['mobile'];
        $param['qq'] = $params['qq'];
        $param['full_address'] = $params['fullAddress'];
        $param['zip_code'] = $params['zipCode'];
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 查询用户购物习惯&着装信息
     *
     * @param int $uid 用户ID
     * @return array 返回的数据
     */
    public static function getUserHabitsInfo($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'web.passport.getUserHabits';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 修改用户习惯信息
     * @param array $params 需要修改的参数集合
     * uid:用户ID
     * shopping:购物习惯 字符串 1 
     * dress:着装习惯 字符串 1,2
     */
    public static function editUserHabitsInfo($params)
    {
        $param = Yohobuy::param();
        $param['method'] = 'web.passport.modifyUserHabits';
        $param['uid'] = $params['uid'];
        $param['shopping'] = $params['shopping'];
        $param['dress'] = $params['dress'];
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 查询用户喜欢的品牌
     *
     * @param int $uid 用户ID
     */
    public static function getUserLikeBrand($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'web.passport.getLikeBrand';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 修改用户喜欢品牌
     * @param array $params 需要修改的参数集合
     * uid:用户ID
     * brand:喜爱品牌 字符串1,2
     */
    public static function editUserLikeBrand($params)
    {
        $param = Yohobuy::param();
        $param['method'] = 'web.passport.modifyLikeBrand';
        $param['uid'] = $params['uid'];
        $param['brand'] = $params['brand'];
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 个人中心页面优惠券,收藏的商品等的数目数据
     *
     * @param int $uid 用户ID
     * @return array 接口返回的数据
     */
    public static function infoNum($uid, $udid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.home.getInfoNum';
        $param['uid'] = $uid;
        $param['udid'] = $udid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 个人中心页面优选新品数据
     *
     * @param int $channel 频道,1代表男生,2代表女生,3代表潮童,4代表创意生活
     * @return array 接口返回的数据
     */
    public static function preference($channel)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.home.preference';
        $param['yh_channel'] = $channel;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 订单数据
     *
     * @param int $uid 用户ID
     * @param int $type 订单类型,1表示全部,2表示待付款,3表示待发货,4表示待收货,5表示待评价
     * @param int $page 第几页,默认1
     * @param int $limit 限制读取的数目,默认10
     * @return array 订单接口返回的数据
     */
    public static function orderData($uid, $type, $page = 1, $limit = 10)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.get';
        $param['uid'] = $uid;
        $param['type'] = $type;
        $param['page'] = $page;
        $param['limit'] = $limit;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 收藏的商品数据
     *
     * @param int $uid 用户ID
     * @param int $page 第几页,默认1
     * @param int $limit 限制读取的数目,默认10
     * @return array 收藏的商品接口返回的数据
     */
    public static function favoriteProductData($uid, $page = 1, $limit = 10)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.favorite.product';
        $param['uid'] = $uid;
        $param['page'] = $page;
        $param['limit'] = $limit;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 收藏的品牌数据
     *
     * @param int $uid 用户ID
     * @param string $gender 性别 1,3表示男,2,3表示女,1,2,3表示全部
     * @param int $page 第几页,默认1
     * @param int $limit 限制读取的数目,默认10
     * @return array 收藏的品牌接口返回的数据
     */
    public static function favoriteBrandData($uid, $gender, $page = 1, $limit = 10)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.favorite.brand';
        $param['uid'] = $uid;
        $param['gender'] = $gender;
        $param['page'] = $page;
        $param['limit'] = $limit;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 取消收藏的商品数据
     *
     * @param int $uid 用户ID
     * @param int $fav_id 要取消的收藏id
     * @return array 接口返回的数据
     */
    public static function favoriteDelete($uid, $fav_id)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.favorite.cancel';
        $param['type'] = 'product';
        $param['uid'] = $uid;
        $param['fav_id'] = $fav_id;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 浏览记录数据
     *
     * @param int $uid 用户ID
     * @param int $udid 客户端唯一标识
     * @param int $page 第几页,默认为1
     * @param int $limit 限制多少条,默认100
     * @return array 接口返回的数据
     */
    public static function browseRecord($uid, $udid, $page = 1, $limit = 10)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.browse.product';
        $param['uid'] = $uid;
        $param['udid'] = $udid;
        $param['page'] = $page;
        $param['limit'] = $limit;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 删除浏览记录
     *
     * @param int $uid 用户ID
     * @param int $skn 商品SKN
     * @return array 接口返回的数据
     */
    public static function delRecord($uid, $skn)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.browse.delete';
        $param['uid'] = $uid;
        $param['skn'] = $skn;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * YOHO币总数
     *
     * @param int $uid 用户ID
     * @return array YOHO币接口返回的数据
     */
    public static function yohoCoinTotal($uid)
    {
//        $param = Yohobuy::param();
//        $param['method'] = 'app.yohocoin.total';
//        $param['uid'] = $uid;
//        $param['client_secret'] = Sign::getSign($param);
//
//        return Yohobuy::get(API_URL, $param);

        $param = Yohobuy::param();
        $param['method'] = 'app.yoho.yohocoin';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * YOHO币列表数据
     *
     * @param int $uid 用户ID
     * @param int $page 第几页,默认1
     * @param int $limit 限制读取的数目,默认10
     * @param string $type 请求类型 get,post
     * @return array YOHO币接口返回的数据
     */
    public static function yohoCoinData($uid, $page = 1, $limit = 10, $type = 'get')
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.yohocoin.lists';
        $param['uid'] = $uid;
        $param['page'] = $page;
        $param['limit'] = $limit;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::$type(API_URL, $param);
    }

    /**
     * 优惠券数据
     *
     * @param int $uid 用户ID
     * @param int $status 优惠券状态,0表示未使用,1表示已使用
     * @param int $page 第几页,默认1
     * @param int $limit 限制读取的数目,默认10
     * @return array 优惠券接口返回的数据
     */
    public static function couponData($uid, $status, $page = 1, $limit = 10)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.coupons.li';
        $param['uid'] = $uid;
        $param['status'] = $status;
        $param['page'] = $page;
        $param['limit'] = $limit;

        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 地址数据
     *
     * @param int $uid 用户ID
     * @return array 地址接口返回的数据
     */
    public static function addressData($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.address.get';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 获取三级地址列表数据
     *
     * @param int $uid 用户ID
     * @return array 地址接口返回的数据
     */
    public static function addressListData($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.address.getlist';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 获取省市区县的列表数据
     * 
     * @param int $id ID
     * @return array
     */
    public static function provinceData($id)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.address.provinces';
        $param['id'] = $id;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 保存地址数据
     *
     * @param int $uid 用户ID
     * @param string $address 地址信息
     * @param int $areaCode 城市码
     * @param string $consignee 收货人
     * @param string $email 邮箱地址
     * @param int $id 地址唯一标识符id
     * @param string $mobile 手机号码
     * @param string $zipCode 邮编
     * @param string $phone 固定电话
     * @return array 地址接口返回的数据
     */
    public static function saveAddressData($uid, $address, $areaCode, $consignee, $email, $id, $mobile, $zipCode, $phone)
    {
        $param = Yohobuy::param();
        $param['address'] = $address;
        $param['area_code'] = $areaCode;
        $param['consignee'] = $consignee;
        $param['email'] = $email;

        if (!empty($id)) { // 修改
            $param['id'] = $id;
            $param['method'] = 'app.address.update';
        }
        else { // 添加
            $param['method'] = 'app.address.add';
        }

        if (!empty($phone)) {
            $param['phone'] = $phone;
        }
        $param['mobile'] = $mobile;
        $param['zip_code'] = $zipCode;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 设置默认地址
     *
     * @param int $uid 用户ID
     * @param int $id 地址唯一标识符id
     * @return array 接口返回的数据
     */
    public static function setDefaultAddress($uid, $id)
    {
        $param = Yohobuy::param();
        $param['id'] = $id;
        $param['method'] = 'app.address.setdefault';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 删除地址
     *
     * @param int $uid 用户ID
     * @param int $id 地址唯一标识符id
     * @return array 接口返回的数据
     */
    public static function deleteAddress($uid, $id)
    {
        $param = Yohobuy::param();
        $param['id'] = $id;
        $param['method'] = 'app.address.del';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 我的消息接口
     *
     * @param int $uid 用户ID
     * @param int $page 获取第一页,默认是1
     * @param int $size 获取数目,默认是10
     * @return array 消息接口返回的数据
     */
    public static function messageData($uid, $page = 1, $size = 10)
    {
        $param = Yohobuy::param();
        $param['uid'] = $uid;
        $param['size'] = $size;
        $param['page'] = $page;
        $param['method'] = 'app.inbox.getlist';
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 兑换礼品卡
     * @param type $uid
     * @param type $giftCardCode1
     * @param type $giftCardCode2
     * @param type $giftCardCode3
     * @param type $captchaCode
     */
    public static function exchangeGift($uid, $giftCardCode1, $giftCardCode2, $giftCardCode3, $captchaCode)
    {
        $param = Yohobuy::param();
        $param['method'] = 'web.personCen.giftExchange';
        $param['uid'] = $uid;
        $param['giftCardCode1'] = $giftCardCode1;
        $param['giftCardCode2'] = $giftCardCode2;
        $param['giftCardCode3'] = $giftCardCode3;
        $param['captchaCode'] = $captchaCode;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 根据uid获取用户VIP信息
     *
     * @param int $uid
     * @return array
     */
    public static function getVIPInfoByUid($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.passport.vip';
        $param['uid'] = $uid;
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 根据uid获取用户优惠券列表
     *
     * @param int $uid
     * @param string $type use:已使用,notuse:未使用,overtime:过期
     * @param int $page
     * @param int $limit
     * @return array
     */
    public static function getCouponsList($uid, $type = 'notuse', $page = 1, $limit = 10)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.coupons.lists';
        $param['uid'] = $uid;
        $param['type'] = $type;
        $param['page'] = $page;
        $param['limit'] = $limit;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    public static function passportGet($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'open.passport.get';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

}