123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2018/9/26 0026
- * Time: 下午 6:28
- */
- class ActivitySer extends Mysqldb
- {
- private static $mysql;
- protected $redis = null;
- private static $appid = null;
- protected $game_db_name = 'gank_activites';
- protected $redis_prefix = 'gank_wechat_activites';
- protected $activity_reward_table = 'app_user_reward';
- protected $redis_prize_key = null;
- protected static $activity_user_table = null;
- protected static $activity_prize_dbname = 'wechat_prize_config';
- protected $login_table = 'receivelogin';
- protected static $consignee_table = 'wechat_user_consignee';
- protected static $virtual_item_prize_table = 'wechat_virtual_item_prize';
- protected static $table = null;
- public static $prize_info = null;
- protected static $wechat_stat_lottery_tab = 'wechat_stat_lottery_info';
- protected static $wechat_stat_webclick_tab = 'wechat_stat_web_click';
- const LIMIT_ONE = 1;
- const K_EXPICE_TIME = 3600;
- function __construct($appid = null)
- {
- log_message::info("初始 act sers ...");
- self::$appid = $appid;
- self::$activity_user_table = 'wechat_user';
- $this->redis_prize_key = "prize_info:wechat";
- $xredis_conf = array(
- 'redis_prefix' => $this->redis_prefix,
- 'k_expire_time' => self::K_EXPICE_TIME
- );
- $this->redis = new Xredis($xredis_conf);
- self::$mysql = new Mysqldb();
- self::$prize_info = $this->getCachePrizeInfo();
- self::$table = $this->game_db_name . '.' . self::$activity_user_table;
- }
- //wechat_sign_activity
- public function GetActivitySign($openId)
- {
- $sql = "SELECT id,openid,rule,create_at FROM wechat_sign_activity WHERE openid='" . $openId . "' limit 1 ";
- if (self::$mysql->query($sql)) {
- return self::$mysql->fetch_row();
- }
- return false;
- }
- public function SetActivitySign($openId, $ruleinfo)
- {
- $sql = "INSERT INTO wechat_sign_activity (openid,rule,create_at) VALUES('" . $openId . "','" . $ruleinfo . "',NOW())";
- if (self::$mysql->query($sql)) {
- error_log('1' . "\n", 3, 'D:\xampp\htdocs\wechat\log\wechat-log.txt');
- return true;
- }
- return false;
- }
- public function EditActivitySign($infostr, $id)
- {
- $up = self::$mysql->update2('wechat_sign_activity', ['rule' => $infostr], 'id=:id', array('id' => $id));
- if ($up) {
- return true;
- }
- return false;
- }
- /***
- * 礼包码变更
- */
- public function EditGiftCode($id)
- {
- $up = self::$mysql->update2('wechat_gift_code', ['status' => 1], 'id=:id', array('id' => $id));
- if ($up) {
- return true;
- }
- return false;
- }
- /**
- * 礼包码获取 1
- */
- public function GetGiftCode($type)
- {
- $sql = "SELECT type,giftcode,status FROM wechat_gift_code WHERE type=" . $type . " AND status=GIFTCODE_STATUS limit 1 ";
- error_log($sql . "\n", 3, 'D:\xampp\htdocs\wechat\log\wechat-sql-log.txt');
- if (self::$mysql->query($sql)) {
- return self::$mysql->fetch_row();
- }
- return false;
- }
- /**
- * 礼包码清理
- */
- public function ClearGiftCode($id)
- {
- $sql = "DELETE FROM wechat_gift_code WHERE id=$id";
- if (self::$mysql->query($sql)) {
- return true;
- }
- return false;
- }
- /***
- * @param type 对应不同类型获取不同的配置属性
- * 活动配置获取
- */
- public function ActivityConfigList($type = null)
- {
- $sql = "SELECT type,title,desc FROM wechat_activity_config";
- if (self::$mysql->query($sql)) {
- return self::$mysql->fetch_all();
- }
- return false;
- }
- /**
- * 设置活动cache
- * @param $key
- * @param $data
- */
- public function setConfigCache($key, $app_id, $data)
- {
- // get redis cache
- // if false get mysql data
- // and set redis
- // and return redis
- //$redis->hSet('paylog', $orderid, $payLogStr);
- $this->redis->hSet($key, $app_id, $data);
- }
- public function setRankingCache()
- {
- }
- /***
- * 后期联合 appid openid channelid
- * @param $openid
- * @return bool|null|string
- *
- */
- public function getCacheUserInfo($uid)
- {
- $userinfo = $this->redis->get(self::$activity_user_table . ":" . $uid);
- if ($userinfo) {
- $this->setCacheEX(self::$activity_user_table . ":" . $uid);
- return $userinfo;
- }
- log_message::info('cache user info is null ');
- return null;
- }
- /***
- * @param $key
- * @return bool
- */
- public function setCacheEX($key)
- {
- $ttl = $this->redis->ttl($key);
- if ($ttl < self::K_EXPICE_TIME) {
- return $this->redis->expire($key, self::K_EXPICE_TIME);
- }
- $this->redis->expire($key, self::K_EXPICE_TIME);
- }
- /***
- * @param $data
- * @return int
- */
- public function setCacheUserInfo($data)
- {
- $uid = $data['uid'];
- $data_str = json_encode($data, JSON_UNESCAPED_UNICODE);
- $ret = $this->redis->setex(self::$activity_user_table . ":" . $uid, self::K_EXPICE_TIME, $data_str);
- if (!$ret) {
- return log_message::info('set cache user info false');
- }
- return true;
- log_message::info('set cache user info true');
- }
- /***
- * 获取用户信息
- * @param $openid
- * @return array|bool
- */
- public function getdbUserInfo($uid,$gameid=null)
- {
- $field = "uid,gameid,respce_lottery_total,surplus_lottery_num,
- act_lottery_end_at,lottery_total,create_at,lucky_draw_total,lottery_up_limit,login_at";
- $where = " WHERE uid=:uid AND gameid=:gameid LIMIT " . self::LIMIT_ONE;
- $sql = "SELECT $field FROM " . self::$activity_user_table . $where;
- $prepare = array('uid' => $uid,'gameid'=>$gameid);
- if (self::$mysql->query($sql, $prepare) && self::$mysql->rowcount() > ZERO) {
- return self::$mysql->fetch_row();;
- }
- return false;
- }
- /**
- *
- */
- /*public function getUserPrizelotteryUplimit($uid)
- {
- $prepare = [
- 'uid' => $uid,
- 'type' => ONE,
- 'date' => date('Ymd', time())
- ];
- $were_str = 'WHERE ' . self::$mysql->formatSqlWhere($prepare);
- $sql = "SELECT count(*) as lottery_cnt FROM " . self::$consignee_table . $were_str;
- if (self::$mysql->query($sql, $prepare) && self::$mysql->rowcount() > ZERO) {
- return self::$mysql->fetch_row();;
- }
- return false;
- }*/
- /***
- * 修改用户数据
- * @param $data
- * @param $prepare_array
- * @return bool
- */
- public function updateUserInfo($updata, $get_prepare_array)
- {
- $where_str = self::$mysql->formatSqlWhere($get_prepare_array);
- $where_val = $get_prepare_array;
- $up_ret = self::$mysql->update2(self::$activity_user_table, $updata, $where_str, $where_val);
- if ($up_ret) {
- return true;
- log_message::info("update info ok");
- }
- log_message::info("update info false");
- return false;
- }
- public static function formatSqlWhere($data, $addition = null)
- {
- if (isDatas($data)) {
- $where = null;
- foreach ($data as $field_key => $field_val) {
- if (!empty($where)) {
- $where .= ' AND ' . $field_key . '=:' . $field_key;
- } else {
- $where .= $field_key . '=:' . $field_key;
- }
- }
- return $where . $addition;
- }
- return false;
- }
- /***
- * Save Userinfo
- * @param $data ['openid']
- * @return array|bool|mixed|null
- */
- public function saveUserInfo($data)
- {
- //$openid = isset($data['openid']) ? $data['openid'] : ZERO;
- $uid = isset($data['uid']) ? $data['uid'] : ZERO;
- $gameid = isset($data['gameid']) ? $data['gameid'] : ZERO;
- $user_info = $this->getCacheUserInfo($uid);
- if ($user_info) {
- log_message::info('return cache user info .');
- return Utils::decodeDate($user_info);
- }
- $db_user_info = $this->getdbUserInfo($uid,$gameid);
- // 如果db 也不存在那么 cache 与 redis 都有进行录入set
- if (empty($db_user_info)) {
- // 这个时候注意参数 $data 是客户端新用户第一次进来初始的参数
- if (!self::$mysql->insert(self::$table, $data)) {
- log_message::info('insert indo db saveuserinfo false');
- }
- if (!$this->setCacheUserInfo($data)) {
- log_message::info('insert indo cache saveuserinfo false');
- }
- return $data;
- }
- // 否则之前录入的redis 已经失效大db存在,这时候要重新设置下cache
- // 如果db 有的话直接set cache 的是 get db 的数据 $db_user_info
- if (!$this->setCacheUserInfo($db_user_info)) {
- log_message::info('insert indo cache saveuserinfo2 false');
- }
- return $db_user_info;
- }
- /***
- * 更新用户抽奖数据
- * @param $data
- * @param bool $lottery
- * @param bool $initial true 初始加载 default false
- * @return array|bool
- */
- public function updateUserlotteryInfo($data, $lottery = false, $lottery_up_limit = ZERO)
- {
- $uid = isset($data['uid']) ? $data['uid'] : ZERO;
- $gameid = isset($data['gameid']) ? $data['gameid'] : ZERO;
- // 登录次数总次数 累计
- $respce_lottery_total = isset($data['respce_lottery_total']) ? $data['respce_lottery_total'] : ZERO;
- /* $login_frequency = isset($data['login_frequency']) ? $data['login_frequency'] : ZERO;
- // 登录累计天数
- $login_successive_day = isset($data['login_successive_day']) ? $data['login_successive_day'] : ZERO;
- // 登录总天数
- $login_total_day = isset($data['login_total_day']) ? $data['login_total_day'] : ZERO;
- // 付费次数
- $pay_frequency = isset($data['pay_frequency']) ? $data['pay_frequency'] : ZERO;
- // 付费金额
- $pay_amount = isset($data['pay_amount']) ? $data['pay_amount'] : ZERO;*/
- // 抽奖的剩余次数为 付费金额 + 登录天数 - 抽奖次数
- // -- 符合条件的抽奖次数 减去 已经抽了的次数 = 剩余的次数
- if ($uid != '0366415e26930fa2f42dae66fce21f1b') {
- // respace
- $sql = "UPDATE " . self::$table . " SET
- respce_lottery_total = respce_lottery_total+($respce_lottery_total-respce_lottery_total),
- surplus_lottery_num = respce_lottery_total - lottery_total
- WHERE uid = " . $uid ." AND gameid=".$gameid;
- }
- if ($lottery == true) {
- $sql = "UPDATE " . self::$table . " SET surplus_lottery_num = surplus_lottery_num-1,
- lottery_total=lottery_total+1,lucky_draw_total=lucky_draw_total+1,lottery_up_limit=lottery_up_limit+" . $lottery_up_limit . "
- WHERE uid = " . $uid." AND gameid=".$gameid;;
- }
- $uid = isset($data['uid']) ? $data['uid'] : ZERO;
- //$ret = $this->mysql->update($this->table, $data, $where, array('openid' => $openid));
- if (!empty($sql)) {
- log_message::info("lottery", $sql);
- $ret = self::$mysql->query($sql);
- if ($ret->rowCount() > ZERO) {
- $data = $this->getdbUserInfo($uid,$gameid);
- // 重置缓存
- // $this->getdbUserInfo($openid);
- $this->setCacheUserInfo($data);
- //surplus_lottery_num 剩余次数
- return $data;
- }
- return false;
- }
- }
- /**
- * 获取登录次数 登录天数 连续登录天数
- * @param $appid
- * @param $channelid
- * @param $sid
- * @param $uid
- * @param $act_start_at
- * @param $act_end_at
- * @return array|bool
- */
- public function getOnlineNum($appid, $channelid, $sid, $uid, $act_start_at, $act_end_at)
- {
- $login_data = [];
- $dbconfg = Utils::config('game_stat_db');
- $appid = '6';
- $serverid = '378';
- $channelid = 'xcx1970';
- $who = '1000002587037899';
- $act_start_at = '2018-08-22 00:00:00';
- $act_end_at = '2018-10-22 23:59:59';
- $mysql = new Mysqldb($dbconfg);
- $field = "who,DATE(begdate) as login_at,COUNT(*) as login_frequency";
- $where = " WHERE who=:who AND begdate>=:act_start_at
- AND begdate<=:act_end_at AND appid=:appid
- AND channelid=:channelid AND serverid=:serverid ";
- $sql = "SELECT $field FROM (SELECT * FROM " .
- $this->login_table . $where . " ) as a GROUP BY DATE(a.begdate)";
- $prepare = array(
- 'who' => $who,
- 'appid' => $appid,
- 'channelid' => $channelid,
- 'act_start_at' => $act_start_at,
- 'act_end_at' => $act_end_at,
- 'serverid' => $serverid
- );
- if ($mysql->query($sql, $prepare) && $mysql->rowcount() > ZERO) {
- log_message::info('login 查询成功!!!!');
- $data = $mysql->fetch_all();
- log_message::info("6666666", json_encode($data));
- $login_day = [];
- $login_num = [];
- $login_successive_day = [];
- foreach ($data as $var) {
- $login_day[] = $var['login_at']; // 登录天数
- $login_num[] = $var['login_frequency']; // 没登录一次记一次
- }
- $login_data = [
- 'login_day' => count($login_day), // 累计登录天数
- 'login_frequency' => array_sum($login_num), // 登录次数
- 'login_successive_day' => count(Utils::successiveTime($login_day)), // 连续登录天数
- ];
- log_message::info(json_encode($login_data));
- return $login_data;
- }
- return false;
- }
- /***
- * 活动付费记录
- * @param $appid
- * @param $channelid
- * @param $sid
- * @param $uid
- * @param $act_start_at
- * @param $act_end_at
- * @return array|bool
- */
- public function getUserPayInfo($appid, $channelid, $sid, $uid, $act_start_at, $act_end_at)
- {
- log_message::info("get **************");
- $login_data = [];
- $dbconfg = Utils::config('game_stat_db');
- $appid = '6';
- $serverid = '378';
- $channelid = 'xcx1970';
- $who = '1000002587037899';
- $act_start_at = '2018-08-22 00:00:00';
- $act_end_at = '2018-10-22 23:59:59';
- // 每日 收充 + 1 count(disct begdate)
- $mysql = new Mysqldb($dbconfg);
- $field = "COUNT(*) paynum,SUM(currencyamount) as amount ";
- $where = " WHERE who=:who AND begdate>=:act_start_at
- AND begdate<=:act_end_at AND appid=:appid AND
- channelid=:channelid AND serverid=:serverid LIMIT " . self::LIMIT_ONE;
- $sql = "SELECT $field FROM todaypayment " . $where;
- $prepare = array(
- 'who' => $who,
- 'appid' => $appid,
- 'channelid' => $channelid,
- 'act_start_at' => $act_start_at,
- 'act_end_at' => $act_end_at,
- 'serverid' => $serverid
- );
- log_message::info("ddddddddddd");
- if ($mysql->query($sql, $prepare) && $mysql->rowcount() > ZERO) {
- log_message::info('pay 查询成功!!!!');
- $data = $mysql->fetch_row();
- log_message::info("&&&&&&JHHHHHHHHH", json_encode($data));
- $pay_frequency = ZERO;
- $pay_amount = ZERO;
- $pay_frequency = empty($data['pay_frequency']) ? ZERO : $data['pay_frequency'];
- $pay_amount = empty($data['pay_amount']) ? ZERO : $data['pay_amount'];
- $pay_data = [
- 'pay_frequency' => $pay_frequency,
- 'pay_amount' => $pay_amount,
- ];
- log_message::info("555555555555555555&&&&&&JHHHHHHHHH", json_encode($pay_data));
- return $pay_data;
- }
- return false;
- }
- //===========================================================================
- /***抽奖
- * 获取奖励db配置信息
- * @param $openid
- * @return array|bool
- */
- //===========================================================================
- public function getdbPrizeInfo()
- {
- $appid = self::$appid;
- //appid,prize_id,prize,rate,number,upper_limit,prize_type
- $field = "appid,prize_id,prize,rate,number,commodity,upper_limit,creat_at";
- $where = " WHERE appid=:appid";
- $sql = "SELECT $field FROM " . self::$activity_prize_dbname;
- $prepare = array('appid' => $appid);
- if (self::$mysql->query($sql, $prepare) && self::$mysql->rowcount() > ZERO) {
- return self::$mysql->fetch_all();
- }
- return false;
- }
- /***
- *
- */
- public function respcedbLottery()
- {
- }
- /***
- * @return array|bool|null
- */
- public function getCachePrizeInfo()
- {
- $prize_info = null;
- $data = null;
- $redis_data = null;
- $cache_data = null;
- $data = Utils::config('game_prize');
- // 直接覆盖重置数据
- $prize_info = $this->redis->hGetAll($this->redis_prize_key);
- if ($prize_info) {
- foreach ($prize_info as $key => $var) {
- $redis_data[] = json_decode($var, true);
- }
- $cache_data = Utils::prizeFormat($redis_data);
- log_message::info('getCachePrizeInfo is cache info ', json_encode($cache_data));
- return $cache_data;
- }
- $dbdata = $this->getdbPrizeInfo();
- if ($dbdata) {
- // grt db set cache
- $this->setCachePrizeInfo($dbdata);
- $dbdata = Utils::prizeFormat($dbdata);
- log_message::info('cache prize info is null ');
- return $dbdata;
- } else {
- // DB CACHE 都没有获取配置文件
- if ($data) {
- $data = Utils::prizeFormat($data);
- log_message::info("getCachePrizeInfo set db prize ");
- $this->respaceLottery($data);
- return $data;
- }
- }
- return false;
- }
- /***
- * @param $respace_data
- * @return bool
- */
- public function respaceLottery($respace_data)
- {
- if ($respace_data) {
- $res_db = $this->setdbPrizeInfo($respace_data);
- $res_cache = $this->setCachePrizeInfo($respace_data);
- if ($res_db && $res_cache) {
- log_message::info("更新 prize db 与 cache 成功");
- return $respace_data;
- }
- log_message::info("更新 prize db 与 cache 失败");
- return false;
- }
- log_message::info(" respace_data is null ");
- return false;
- }
- public function setdbPrizeInfo($data)
- {
- $prize_out = null;
- $fields = 'prize_id,prize,rate,number,upper_limit,prize_type,status';
- foreach ($data as $key => $var) {
- $prize_out[$key] = [
- "prize_id" => $var['prize_id'],
- "prize" => '"' . $var['prize'] . '"',
- "rate" => $var['rate'],
- "number" => $var['number'],
- "upper_limit" => $var['upper_limit'],
- "prize_type" => $var['prize_type'],
- "status" => $var['status'],// DEFAULT 0 1 实物需发货
- ];
- }
- if (isDatas($prize_out)) {
- if (self::$mysql->insertBatch(self::$activity_prize_dbname, $fields, $prize_out)) {
- return true;
- }
- log_message::info("setdbPrizeInfo false ");
- return false;
- }
- log_message::info("prize_out is null");
- return false;
- }
- /***
- * @param $data
- * @param null $appid
- * @return int
- */
- public function setCachePrizeInfo($data)
- {
- // 整理hmset 索规定的格式 并录入缓存 ..[key=>string],[key,string]
- // 后期同步db 后台可同步
- $data = Utils::prizeAssembly($data);
- // ..[key=>string],[key,string]
- $ret = $this->redis->hMset($this->redis_prize_key, $data);
- if (!$ret) {
- log_message::info('set cache prize info false');
- return false;
- }
- return true;
- }
- /***
- * 覆盖抽奖配置规则
- * @param $appid
- * @return bool|mixed|null
- */
- public function setLotteryFrequency($prize_id)
- {
- if ($this->redis->exists($this->redis_prize_key)) {
- $data = json_decode($this->redis->hGet($this->redis_prize_key, $prize_id), true);
- if (isDatas($data)) {
- $upper_limit = (int)$data['upper_limit'];
- $frequency = $data['frequency'];
- // 重置cache 物品抽奖的累计次数 递增 | frequency
- return $this->setUpperLimit($frequency, $upper_limit, $data);
- }
- log_message::info("setLotteryFrequency false");
- return false;
- }
- log_message::info("setLotteryFrequency false cache is null");
- return false;
- }
- /***
- * 重置cache 物品抽奖的累计次数
- * @param $role_upper_limit
- * @param $game_upper_limit
- * @param $data
- * @return bool|mixed|null
- */
- public function setUpperLimit($role_upper_limit, $game_upper_limit, $data)
- {
- log_message::info('-----------------', json_encode($data, JSON_UNESCAPED_UNICODE));
- $commodity = $data['status']; // 0 虚拟 1 实物
- $prize_id = $data['prize_id'];
- $prize_value = null;
- $isNayUpperLimit = self::isNayUpperLimit($role_upper_limit, $game_upper_limit);
- // 如果奖品抽取次数小于规定的限制次数
- if ($isNayUpperLimit) {
- $role_upper_limit += ONE;
- $data['frequency'] = $role_upper_limit;
- $prize_value = json_encode($data, JSON_UNESCAPED_UNICODE);
- log_message::info("########################", $prize_value);
- // 重置prize cache 次数
- log_message::info('^^^^^^^^^^^^^^^^^^^^^cishu', $prize_id, $prize_value);
- $this->redis->hSet($this->redis_prize_key, $prize_id, $prize_value);
- return self::prizeIsCommodity($data, $commodity);
- } else {
- log_message::info('set uo limit is nay InterventionLottery');
- // 如果抽奖达到上限则重新随机奖励
- return self::interventionLottery();
- }
- }
- /***
- * 抽到实物需要收货地址弹框相应
- * 此类型key 不会再 cache 里设置并返回,只允许代码里判断有效类型
- * @param $appid
- * @return bool|mixed|null
- */
- public static function prizeIsCommodity($data, $commodity)
- {
- $id = $data['prize_id'];
- $status = (int)$data['status'];
- $up_limit = $data['upper_limit'];
- if ($commodity == ONE) {
- $data['prize_type'] = (int)ONE;
- }
- if ($up_limit != ZERO && $status != ONE) {
- $ret = self::getdbVirtualItemPrize($id);
- log_message::info("******************", json_encode($ret, JSON_UNESCAPED_UNICODE));
- if ($ret) {
-
- $card_info = '卡密:' . $ret['password'];
- $data['prize_desc'] = $card_info;
-
- //$data['prize_desc'] = '卡号:'.$ret['account'].' 卡密:'.$ret['account'];
- $item_prize_id = $ret['id'];
- self::setdbVirtualItemPrize($item_prize_id);
- log_message::info("prizeIsCommodity VirtualItem data is true");
- } else {
- log_message::info("prizeIsCommodity VirtualItem data is pres");
- unset($data);
- /*foreach (self::$prize_info as $val) {
- if ($val['prize_id'] ==SIX){
- $data = $val;
- }
- }*/
- $data = self::$prize_info[SIX];
- }
- // 最后重置一个吧
- //
- log_message::info("prizeIsCommodity VirtualItem data is null");
- }
- // 如果虚拟判断是否卡密 对应 prize id 获取卡密配置信息
- return json_encode($data, JSON_UNESCAPED_UNICODE);
- }
- /***
- * 干预奖品信息 如果抽奖达到上限则重新随机奖励
- */
- public function interventionLottery($data = [])
- {
- $prize_all = self::$prize_info;
- foreach ($prize_all as $key => $val) {
- $arr[$val['prize_id']] = $val['rate'];
- }
- do {
- log_message::info("********************* prize_all ", json_encode($arr));
- $rid = Utils::getPrizeRand($arr);
- log_message::info("********************* rid ", $rid);
- //$pirze_lottery = $prize_all[$rid - ONE];
- $pirze_lottery = $prize_all[$rid];
- $game_upper_limit = (int)$pirze_lottery['upper_limit'];
- $role_upper_limit = (int)$pirze_lottery['frequency'];
- return $this->setLotteryFrequency($pirze_lottery['prize_id']);
- } while (Utils::isUpperlimit($role_upper_limit, $game_upper_limit));
- }
- /***
- * 获取
- * @param $id
- * @return bool|false|string
- */
- public function byPrizeidInfo($id = null, $all = false)
- {
- $data = $this->redis->hGet($this->redis_prize_key, $id);
- if ($all == true) {
- $data = $this->redis->hGetAll($this->redis_prize_key);
- }
- if (isDatas($data)) {
- return $data;
- }
- log_message::info("getPrizeidInfo is null");
- return false;
- }
- /***
- * 干预判断 如果 不是无限制的类型并且 game 上限大于或等于用户已抽取的次数
- * 表示已经达到上限符合干预条件需要系统重新随机奖品
- * @param $role_upper_limit
- * @param $game_upper_limit
- * @return bool
- */
- public static function isUpperlimit($role_upper_limit, $game_upper_limit)
- {
- if (($game_upper_limit != ZERO && $game_upper_limit >= $role_upper_limit)) {
- return true;
- }
- return false;
- }
- /****
- * 判断有效范围内可增加抽取次数并返回客户端
- * @param $role_upper_limit
- * @param $game_upper_limit
- * @return bool
- */
- public static function isNayUpperLimit($role_upper_limit, $game_upper_limit)
- {
- if ($game_upper_limit == ZERO || ($game_upper_limit != ZERO && $role_upper_limit < $game_upper_limit)) {
- return true;
- }
- return false;
- }
- /***
- * 重置上限次数
- */
- public function replaceUpperLimit()
- {
- $where_data = ['appid' => self::$appid];
- $edit_data = ['frequency' => ZERO];
- $where_str = self::$mysql->formatSqlWhere($where_data);
- $up = self::$mysql->update2(self::$activity_prize_dbname, $edit_data, $where_str, $where_data);
- if ($up) {
- log_message::info('抽奖上限次数重置成功!');
- return true;
- }
- log_message::info('抽奖上限次数重置失败!');
- return false;
- }
- public function getdbLotteryInfo()
- {
- }
- // --------------------------------------------------------------------
- // 抽奖活动用户信息,用户抽取次数
- // --------------------------------------------------------------------
- /***
- * @param $appid
- * @param $channelid
- * @param $uid
- * @param $act_start_at
- * @param $act_end_at
- * @param $openid
- * @return array|bool
- */
- public function getdbLotteryTotal($appid, $channelid, $uid, $act_start_at, $act_end_at, $openid)
- {
- $dbconfg = Utils::config('game_stat_db');
- $mysql = new Mysqldb($dbconfg);
- $field = " COUNT(*) as cont_frequency,COUNT(DISTINCT DATE(begdate)) cont_day";
- $where = " WHERE who=:who appid=:appid AND channelid=:channelid AND begdate>=:start_at
- AND begdate<=:end_at LIMIT" . self::LIMIT_ONE;
- $sql = "SELECT $field FROM " . $this->login_table . $where;
- $prepare = array(
- 'who' => $uid,
- 'appid' => $appid,
- 'channelid' => $channelid,
- 'start_at' => $act_start_at,
- 'end_at' => $act_end_at,
- );
- if ($mysql->query($sql, $prepare) && $mysql->rowcount() > ZERO) {
- return $mysql->fetch_row();
- }
- return false;
- }
- /***
- * 设置用户收货地址
- * @param $data
- * @return bool
- */
- public static function savePirzeConsignee($data)
- {
- /*$addItion = " ON DUPLICATE KEY UPDATE
- type=1,
- consignee_address ={$data['consignee_address']} ,
- consignee_name = {$data['consignee_name']},
- consignee_phone={$data['consignee_phone']},";*/
- $ret = self::$mysql->insert(self::$consignee_table, $data);
- if ($ret) {
- return true;
- }
- return false;
- }
- /***
- * @param $data
- * @return bool
- */
- public static function editPirzeConsignee($data)
- {
- $uid = $data['uid'];
- $gameid = $data['gameid'];
- $prize_order = $data['prize_order'];
- $type = $data['type'];
- $where_data = [
- 'uid' => $uid,
- 'gameid' => $gameid,
- 'prize_order' => $prize_order
- ];
- $where_str = self::$mysql->formatSqlWhere($where_data);
- $edit_data = [
- 'consignee_address' => $data['consignee_address'],
- 'consignee_phone' => $data['consignee_phone'],
- 'type' => $type
- ];
- $up = self::$mysql->update2(self::$consignee_table, $edit_data, $where_str, $where_data);
- if ($up) {
- log_message::info('地址更新成功!');
- return true;
- }
- log_message::info('地址更新失败!');
- return false;
- }
- /***
- * 获取用户抽奖记录
- */
- public function userPrizeInfo($uid,$gameid=null)
- {
- $sql = " SELECT * FROM " . self::$consignee_table . "
- WHERE uid=:uid AND gameid=:gameid";
- $prepare = array(
- 'uid' => $uid,
- 'gameid' => $gameid,
- );
- if (self::$mysql->query($sql, $prepare) && self::$mysql->rowcount() > ZERO) {
- return self::$mysql->fetch_all();
- }
- return false;
- }
- /***
- * 获取用户抽奖记录
- */
- public function byuserPrizeOrderInfo($uid,$gameid, $prize_order)
- {
- $sql = " SELECT * FROM " . self::$consignee_table . "
- WHERE uid=:uid AND gameid =:gameid AND prize_order=:prize_order";
- $prepare = array(
- 'uid' => $uid,
- 'gameid' => $gameid,
- 'prize_order' => $prize_order
- );
- if (self::$mysql->query($sql, $prepare) && self::$mysql->rowcount() > ZERO) {
- return self::$mysql->fetch_row();
- }
- return false;
- }
- /**
- * @param $where_data
- * @return bool|mixe
- */
- public static function globalConfig($where_data)
- {
- $sql = "SELECT * FROM tb_stat_back_ranking ";
- $addition = 'ORDER BY id desc limit 1';
- $sql .= ' WHERE ' . self::$mysql->formatSqlWhere($where_data, $addition);
- if (self::$mysql->query($sql, $where_data) && self::$mysql->rowcount() > ZERO) {
- return self::$mysql->fetch_row();
- log_message::info("globalconfig true");
- }
- log_message::info("globalconfig false", $sql);
- return false;
- }
- public function getRankingList($data)
- {
- $sql = "select * from WHERE ";
- //self::$mysql-
- }
- // get item acccount info
- /***
- * @param $itemid
- * @return array|bool
- */
- public static function getdbVirtualItemPrize($itemid)
- {
- // AND status=:status
- $sql = " SELECT id,account,password,`desc`,itemid FROM " . self::$virtual_item_prize_table . "
- WHERE itemid=:itemid AND status=:status LIMIT " . self::LIMIT_ONE;
- $prepare = array(
- 'itemid' => $itemid,
- 'status' => ZERO, // 0待领取 1 已领取 获取new prize itme
- );
- if (self::$mysql->query($sql, $prepare) && self::$mysql->rowcount() > ZERO) {
- return self::$mysql->fetch_row();
- }
- return false;
- }
- /***
- * @param $itemid
- * @return bool
- */
- public static function setdbVirtualItemPrize($id)
- {
- $where_data = ['id' => $id];
- $edit_data = ['status' => ONE];
- $where_str = self::$mysql->formatSqlWhere($where_data);
- $up = self::$mysql->update2(self::$virtual_item_prize_table, $edit_data, $where_str, $where_data);
- if ($up) {
- log_message::info('重置虚拟配置成功!');
- return true;
- }
- log_message::info('重置虚拟配置失败!');
- return false;
- }
- // 统计 抽奖信息
- public function setLotteryLog($data)
- {
- $ret = self::$mysql->insert(self::$wechat_stat_lottery_tab, $data);
- if ($ret) {
- return true;
- }
- return false;
- }
- // 统计 页面点击
- public function setWebClickLog($data)
- {
- $ret = self::$mysql->insert(self::$wechat_stat_webclick_tab, $data);
- if ($ret) {
- return true;
- }
- return false;
- }
- }
|