| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 | <?php/** * Gift.php UTF-8 * 礼包处理类 * * @date    : 2016年12月3日下午4:58:28 * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : wuyonghong <wyh@huosdk.com> * @version : HUOSDK 7.0 * @modified: 2016年12月3日下午4:58:28 */namespace huo\controller\gift;use huo\controller\common\Base;use huo\controller\game\GameCache;use huo\controller\help\QqCache;use huo\controller\integral\MemIntegral;use huo\controller\member\MemCache;use huo\logic\game\GiftLogic;use huolib\constant\MemItgConst;use huolib\status\GiftStatus;use huolib\status\IntegralStatus;use huolib\status\MemberStatus;class Gift extends Base {    protected $gift_model;    public function __construct(GiftLogic $gift_model = null) {        if (null === $gift_model) {            $this->gift_model = new GiftLogic();        } else {            $this->gift_model = $gift_model;        }    }    /**     * 获取积分礼包列表     *     * @param int    $game_id     * @param int    $mem_id     * @param string $page     * @param bool   $inc_me     *     * @return array     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\ModelNotFoundException     * @throws \think\exception\DbException     */    public function getIntegralGifts($game_id = 0, $mem_id = 0, $page = '1,10', $inc_me = false) {        $_map['condition'] = ['gt', 0];        if (!empty($game_id)) {            $_map['app_id'] = $game_id;        }        return $this->getGifts($mem_id, $_map, $page, $inc_me);    }    /**     * 获取普通礼包列表     *     * @param int    $game_id     * @param int    $mem_id     * @param string $page     * @param bool   $inc_me     *     * @return array     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\ModelNotFoundException     * @throws \think\exception\DbException     */    public function getNormalGifts($game_id = 0, $mem_id = 0, $page = '1,10', $inc_me = false) {        $_map['condition'] = 0;        if (!empty($game_id)) {            $_map['app_id'] = $game_id;        }        return $this->getGifts($mem_id, $_map, $page, $inc_me);    }    /**     * 获取礼包列表     *     * @param int    $mem_id     * @param        $map     * @param string $page     *     * @param bool   $inc_me     *     * @return array     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\ModelNotFoundException     * @throws \think\exception\DbException     */    public function getGifts($mem_id, $map, $page, $inc_me = false) {        $_map = $map;        if (isset($_map['gift_type'])) {            //礼包搜索类型条件处理            switch ($map['gift_type']) {                case 1:                    $_map['condition'] = 0;                    $_map['qq_id'] = 0;                    break;                case 2:                    $_map['condition'] = ['>', 0];                    break;                case 3:                    $_map['qq_id'] = ['>', 0];                    break;            }            unset($_map['gift_type']);        }        $_data = $this->getGiftListDetail($mem_id, $_map, $page, $inc_me);        if (is_numeric($_data)) {            $_code = $_data;            return $this->huoError($_code, GiftStatus::getMsg($_code));        }        $_code = GiftStatus::NO_ERROR;        return $this->huoSuccess($_code, GiftStatus::getMsg($_code), $_data);    }    /**     * 获取礼包列表详情     *     * @param string $mem_id     * @param array  $map     * @param string $page     *     * @param bool   $inc_me     *     * @return mixed     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\ModelNotFoundException     * @throws \think\exception\DbException     */    public function getGiftListDetail($mem_id, $map, $page, $inc_me = false) {        $_data = $this->gift_model->getGifts($mem_id, $map, $page, $inc_me);        if (false == is_array($_data)) {            return $_data;        }        $_list = $_data['list'];        if (empty($_list)) {            return $_data;        }        unset($_data['list']);        $_data['list'] = $this->getGiftExtInfo($_list);        return $_data;    }    /**     * 获取礼包扩展信息     *     * @param array $data     *     * @return array     */    public function getGiftExtInfo($data = []) {        if (empty($data)) {            return $data;        }        $_qq_class = new QqCache();        foreach ($data as $_k => $_v) {            if (empty($_v['qq_id'])) {                $data[$_k]['qq_group'] = null;            } else {                $data[$_k]['qq_group'] = $_qq_class->getInfoByQqId($_v['qq_id']);            }            $_game_info = GameCache::ins()->getInfoByAppId($_v['game_id']);            $data[$_k]['icon'] = $_game_info['icon'];            $data[$_k]['game_name'] = $_game_info['name'];        }        return $data;    }    /**     * 获取礼包详情     *     * @param int $gift_id     * @param     $mem_id     *     * @return array     */    public function getGiftDetail($gift_id = 0, $mem_id) {        if (empty($gift_id)) {            $_code = GiftStatus::GAME_ID_EMPTY;            $this->huoError($_code, GiftStatus::getMsg($_code));        }        $_gift_data = GiftCache::ins()->getInfoByGiftId($gift_id);        if (empty($_gift_data)) {            $_code = GiftStatus::GIFT_NOT_EXISTS;            return $this->huoError($_code, GiftStatus::getMsg($_code));        }        $_gift_logic = new GiftLogic();        $_base_field = $_gift_logic->getBaseField();        foreach ($_base_field as $_k => $_v) {            $_data[$_v] = $_gift_data[$_k];        }        $_gift_code = $_gift_logic->getGiftCodes($gift_id, $mem_id);        if (!empty($_gift_code)) {            $_data['code'] = $_gift_code[$gift_id];        } else {            $_data['code'] = null;        }        $_ext_data[] = $_data;        $_rdata = $this->getGiftExtInfo($_ext_data);        $_code = GiftStatus::NO_ERROR;        return $this->huoSuccess($_code, GiftStatus::getMsg($_code), $_rdata[0]);    }    /**     * 领取礼包     *     * @param int $mem_id     * @param int $gift_id     *     * @return array     */    public function setGift($mem_id = 0, $gift_id = 0, $isAward = 0) {        if (empty($mem_id)) {            $_code = MemberStatus::LOGIN_IS_OUT;            return $this->huoError($_code, MemberStatus::getMsg($_code));        }        if (empty($gift_id)) {            $_code = GiftStatus::GIFT_ID_EMPTY;            return $this->huoError($_code, GiftStatus::getMsg($_code));        }        $_gift_cache = GiftCache::ins();        $_gift_data = $_gift_cache->getInfoByGiftId($gift_id);        if (empty($_gift_data)) {            $_code = GiftStatus::GIFT_NOT_EXISTS;            return $this->huoError($_code, GiftStatus::getMsg($_code));        }        /* 判断余量 */        if (empty($_gift_data['remain_cnt']) || $_gift_data['remain_cnt'] <= 0) {            $_code = GiftStatus::GIFT_REMAIN_ZERO;            return $this->huoError($_code, GiftStatus::getMsg($_code));        }        $_mc_class = MemCache::ins();        $_me_data = $_mc_class->getMeInfoById($mem_id);        if (!$isAward) {//不是奖品,扣除积分            if ($_gift_data['condition'] > 0) {                $_my_integral = $_me_data['my_integral'];                if ($_my_integral < $_gift_data['condition']) {                    $_code = IntegralStatus::ITG_NOT_ENOUGH;                    return $this->huoError($_code, IntegralStatus::getMsg($_code));                }                $_me_data['my_integral'] -= $_gift_data['condition'];                $_mc_class->saveMeCache($mem_id, $_me_data);            }        }        $_gift_data['remain_cnt']--;        $_gift_cache->updateGift($gift_id, $_gift_data);        $_data = $this->gift_model->setGift($mem_id, $gift_id);        if (false === $_data) {            $_code = GiftStatus::GIFT_GET_ERROR;            return $this->huoError($_code, GiftStatus::getMsg($_code));        }        $_mitg_class = new MemIntegral();        /* 减少此次积分 */        $_mitg_class->setMemItg($mem_id, $_gift_data['condition'], MemItgConst::MEM_ITG_DEDUCT, 0, 0, "", 0, "兑换礼包");        $_me_data['gift_cnt']++;        $_mc_class->updateMeCache($mem_id, $_me_data);        $_code = GiftStatus::NO_ERROR;        $_gift_data['code'] = $_data;        return $this->huoSuccess($_code, GiftStatus::getMsg($_code), $_gift_data);    }    /**     * 获取游戏礼包列表     *     * @param int    $mem_id 玩家ID     * @param        $from     * @param string $page   页码     * @param        $app_ids     *     * @return array     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\ModelNotFoundException     * @throws \think\exception\DbException     */    public function getGameGifts($mem_id, $from, $page = '', $app_ids = null) {        $_gift_logic = new GiftLogic();        $_map['classify'] = $from;        if (!empty($app_id)) {            if (is_array($app_ids)) {                $_map['id'] = ['in', $app_ids];            } elseif (is_numeric($app_ids)) {                $_map['id'] = $app_ids;            }        }        $_map['classify'] = $from;        $_app_rs = $_gift_logic->getHasGiftAppIds($_map, $page);        if (is_numeric($_app_rs)) {            $_data=['count'=>0,'list'=>[]];            return $this->huoError($_app_rs, GiftStatus::getMsg($_app_rs),$_data);        }        $_rdata['count'] = $_app_rs['count'];        $_app_ids = $_app_rs['list'];        $_gc_class = GameCache::ins();        $_list = [];        foreach ($_app_ids as $_app_id) {            $_game_data = $_gc_class->getInfoByAppId($_app_id);            unset($_data);            $_data['game_id'] = $_app_id;            $_data['gamename'] = $_game_data['name'];            $_data['icon'] = $_game_data['icon'];            $_gift_map['app_id'] = $_app_id;            $_gift_data = $this->getGiftListDetail($mem_id, $_gift_map, $page,true);            $_data['gift_cnt'] = $_gift_data['count'];            $_data['gift_list'] = $_gift_data['list'];            $_list[] = $_data;        }        if (empty($_list)) {            $_code = GiftStatus::UNKNOWN_ERROR;            return $this->huoError($_code, GiftStatus::getMsg($_code));        }        $_rdata['list'] = $_list;        $_code = GiftStatus::NO_ERROR;        return $this->huoSuccess($_code, GiftStatus::getMsg($_code), $_rdata);    }    /**     * 获取玩家礼包列表     *     * @param  int   $mem_id     * @param string $page     */    public function getMemGifts($mem_id, $page = '') {        if (empty($mem_id)) {            $_code = MemberStatus::LOGIN_IS_OUT;            return $this->huoError($_code, MemberStatus::getMsg($_code));        }        $_rs = $this->gift_model->getMemGifts($mem_id, $page);        $_code = GiftStatus::NO_ERROR;        if (GiftStatus::GIFT_CNT_ZERO == $_rs) {            return $this->huoSuccess($_code, GiftStatus::getMsg($_code));        }        return $this->huoSuccess($_code, GiftStatus::getMsg($_code), $_rs);    }}
 |