Yuanxiao.php 2.72 KB
<?php

namespace Cuxiao;
use LibModels\Wap\Cuxiao\ActivityData;
use LibModels\Wap\Home\UserData;

/**
 * Created by PhpStorm.
 * User: Gtskk
 * Date: 2016/2/18
 * Time: 16:26
 *
 * @name YuanxiaoModel
 * @package models/Cuxiao
 * @author Gtskk(tttt6399998@126.com)
 */
class YuanxiaoModel
{
    /**
     * 处理用户详情数据
     *
     * @param int $uid 用户ID
     * @return array|mixed 处理之后的个人详情数据
     */
    public static function getUserProfileData($uid)
    {
        $result = array(
            'birthday' => '2000-01-01',
            'gender' => 2
        );

        // 调用接口获取个人详情
        $userData = UserData::userData($uid, false);

        // 处理个人详情数
        if (isset($userData['data']) && !empty($userData['data'])) {
            $result['birthday'] = $userData['data']['birthday'] ?: '2000-01-01';
            $result['gender'] = $userData['data']['gender'];
        }

        return $result;
    }

    /**
     * @param int $uid 用户UID
     * @param sring $nickName 用户昵称
     * @param string $birthday 用户生日
     * @param int $gender 用户性别
     * @return array 处理之后抽签的结果
     */
    public static function getChouqianInfo($uid, $nickName, $birthday, $gender)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        do {
            if (empty($uid)) {
                break;
            }

            if (empty($nickName)) {
                $result['message'] = '昵称不能为空';
                break;
            }

            if (empty($birthday)) {
                $result['message'] = '生日不能为空';
                break;
            }

            if (empty($gender)) {
                $result['message'] = '性别不能为空';
                break;
            }

            $chouqian = ActivityData::getYuanxiaoInfo($uid, $nickName, $birthday, $gender);
            if ($chouqian) {
                $result = $chouqian;
            }
        } while (false);

        return $result;
    }

    /**
     * @param int $uid 用户UID
     * @return array|mixed 抽奖的结果
     */
    public static function getChoujiangShareInfo($uid)
    {
        $result = array('code' => 400, 'message' => '出错啦~');

        do {
            if (empty($uid)) {
                break;
            }

            $chouqian = ActivityData::getYuanxiaoShareInfo($uid);
            if (isset($chouqian['data'])) {
                $result = array(
                    'name' => $chouqian['data']['nickname'],
                    'type' => $chouqian['data']['randomCode'],
                    'total' => $chouqian['data']['total']
                );
            }
        } while (false);

        return $result;
    }
}