$redis_conf['host'], 'port' => $redis_conf['port'], 'passwd' => $redis_conf['passwd'] )); return $r; } protected function getMysql($account_id) { $mysql_conf = getMysqlConfig(crc32($account_id)); $conn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id'] )); return $conn; } public function prePay() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $goods_id = $_REQUEST['goods_id']; $url = ''; if (SERVER_ENV == _ONLINE) { $url = 'https://payservice.kingsome.cn/api/ingame/spreorder'; } else { $url = 'https://payservice-test.kingsome.cn/api/ingame/spreorder'; } $sign = md5($_REQUEST['account_id'] . $_REQUEST['goods_id'] . 'f3a6a9a5-217a-4079-ab99-b5d69b8212be' . $_REQUEST['session_id']); $params = array( 'account_id' => $_REQUEST['account_id'], 'goods_id' => $goods_id, 'session_id' => $_REQUEST['session_id'], 'user_ip' => phpcommon\getIPv4(), 'sign' => $sign ); if (!phpcommon\HttpClient::get($url, $params, $rsp)) { phpcommon\sendError(ERR_RETRY, '系统繁忙'); return; } if ($rsp == null || $rsp == '') { phpcommon\sendError(ERR_RETRY, '系统繁忙2'); return; } $response = json_decode($rsp, true); echo json_encode(array( 'errcode' => $response['errcode'], 'errmsg' => $response['errmsg'], 'order_id' => $response['order_id'] )); } public function payDone() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $order_id = $_REQUEST['order_id']; $url = ''; if (SERVER_ENV == _ONLINE) { $url = 'https://payservice.kingsome.cn/api/ingame/paid'; } else { $url = 'https://payservice-test.kingsome.cn/api/ingame/paid'; } $sign = md5($_REQUEST['account_id'] . $_REQUEST['order_id'] . 'f3a6a9a5-217a-4079-ab99-b5d69b8212be' . $_REQUEST['session_id']); $params = array( 'account_id' => $_REQUEST['account_id'], 'order_id' => $order_id, 'session_id' => $_REQUEST['session_id'], 'user_ip' => phpcommon\getIPv4(), 'sign' => $sign ); if (!phpcommon\HttpClient::get($url, $params, $rsp)) { phpcommon\sendError(ERR_RETRY, '系统繁忙'); return; } if ($rsp == null || $rsp == '') { phpcommon\sendError(ERR_RETRY, '系统繁忙 2'); return; } $response = json_decode($rsp, true); $diamonds = $response['diamond']; $diamond_num = -1; $diamond_present = 0; if ($diamonds > 0) { $userrow = $conn->execQueryOne( 'SELECT diamond_num, free_diamond FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); if (!$userrow) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $shopgoods_conf = metatable\getShopGoodsConf(); $goodsid = 0; if ($shopgoods_conf) { for ($i = 1; $i <= count($shopgoods_conf); $i++) { if ($shopgoods_conf[$i]['type'] != 1) { continue; } if ($diamonds < $shopgoods_conf[$i]['item_num']) { continue; } if ($shopgoods_conf[$i]['first_present'] > $diamond_present) { $diamond_present = $shopgoods_conf[$i]['first_present']; $goodsid = $shopgoods_conf[$i]['shop_id']; } } } $rechargerow = $conn->execQueryOne( 'SELECT * FROM recharge WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); $rechargeactivity = new classes\RechargeActivity(); $activity = array(); if ($rechargerow && $rechargerow['activity'] != null && $rechargerow['activity'] != '') { $activity = json_decode($rechargerow['activity'], true); } $rechargeactivity->updateActivityCur($activity, $diamonds, true); if (!$rechargerow) { $ret = $conn->execScript( 'INSERT INTO recharge(accountid, first_data, recharge_diamond, present_diamond, activity, create_time, modify_time) ' . ' VALUES(:account_id, :first_data, :recharge_diamond, :present_diamond, :activity, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:account_id, first_data=:first_data, recharge_diamond=:recharge_diamond, present_diamond=:present_diamond, activity=:activity, modify_time=:modify_time;', array( ':account_id' => $account_id, ':first_data' => $goodsid, ':recharge_diamond' => $diamonds, ':present_diamond' => $diamond_present, ':activity' => json_encode($activity), ':create_time' => time(), ':modify_time' => time() ) ); } else { $firstlist = explode(',', $rechargerow['first_data']); $firstrecharge = true; for ($i = 0; $i < count($firstlist); $i++) { if ($firstlist[$i] == $goodsid) { $firstrecharge = false; } } $firstdata = $rechargerow['first_data']; if ($firstrecharge) { if ($firstdata == NULL || $firstdata == '') { $firstdata = $goodsid; } else { $firstdata = $rechargerow['first_data'] . ',' . $goodsid; } } else { $diamond_present = 0; } $ret = $conn->execScript( 'UPDATE recharge SET first_data=:first_data, recharge_diamond=:recharge_diamond, present_diamond=:present_diamond, activity=:activity, modify_time=:modify_time' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':first_data' => $firstdata, ':recharge_diamond' => $rechargerow['recharge_diamond'] + $diamonds, ':present_diamond' => $rechargerow['present_diamond'] + $diamond_present, ':activity' => json_encode($activity), ':modify_time' => time() ) ); } $diamond_num = $userrow['diamond_num'] + $diamonds + $diamond_present; $ret = $conn->execScript( 'UPDATE user SET diamond_num=:diamond_num' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':diamond_num' => $diamond_num ) ); if (!$ret) { die(); return; } } echo json_encode(array( 'errcode' => $response['errcode'], 'errmsg' => $response['errmsg'], 'order_id' => $response['order_id'], 'diamond_nums' => $diamond_num, 'diamond_present' => $diamond_present, )); } public function prePurchase() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $raw_data = file_get_contents('php://input'); $sigdata = json_decode($raw_data, true); if (!$this->checkPurchaseLimit($conn, $account_id, $sigdata['productId'])) { phpcommon\sendError(ERR_USER_BASE + 2, '不能购买'); return; } $url = ''; if (SERVER_ENV == _ONLINE) { $url = 'https://payservice.kingsome.cn/api/ingame/sprepurchase'; } else { $url = 'https://payservice-test.kingsome.cn/api/ingame/sprepurchase'; } $sign = md5($_REQUEST['account_id'] . 'f3a6a9a5-217a-4079-ab99-b5d69b8212be' . $_REQUEST['session_id']); $params = array( 'account_id' => $_REQUEST['account_id'], 'session_id' => $_REQUEST['session_id'], 'user_ip' => phpcommon\getIPv4(), 'sign' => $sign, 'sig_data' => $raw_data, ); if (!phpcommon\HttpClient::post($url, json_encode($params), $rsp)) { phpcommon\sendError(ERR_RETRY, '系统繁忙'); return; } if ($rsp == null || $rsp == '') { phpcommon\sendError(ERR_RETRY, '系统繁忙2'); return; } $response = json_decode($rsp, true); echo json_encode(array( 'errcode' => $response['errcode'], 'errmsg' => $response['errmsg'], 'order_id' => $response['order_id'], 'pay_sig' => $response['pay_sig'], 'signature' => $response['signature'], 'sig_data' => $response['sig_data'], )); } public function purchaseDone() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $order_id = $_REQUEST['order_id']; if ($order_id == '') { die(); return; } $key = 'game2004api-purchase:' . $account_id . '-' . $order_id; $r = $this->getRedis($key); if (!$r) { echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'order_id' => $order_id, 'status' => 0, )); return; } $user_purchase_str = $r->get($key); if (empty($user_purchase_str)) { echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'order_id' => $order_id, 'status' => 0, )); return; } echo $user_purchase_str; } public function adFree() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $rechargerow = $conn->execQueryOne( 'SELECT * FROM recharge WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); if (!$rechargerow || $rechargerow['adfree'] < 1) { phpcommon\sendError(ERR_USER_BASE + 2, '券不足'); return; } $ret = $conn->execScript( 'UPDATE recharge SET adfree=adfree-1, modify_time=:modify_time WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':modify_time' => time(), ) ); if (!$ret) { phpcommon\sendError(ERR_INTERNAL + 1, '系统繁忙'); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'adfree' => $rechargerow['adfree'] - 1, )); } protected function checkPurchaseLimit($conn, $account_id, $productid) { $prod_conf = metatable\getShopGoodsById($productid); if (!$prod_conf) { return false; } if ($prod_conf['type'] != 2) { return true; } $conn = $this->getMysql($_REQUEST['account_id']); $rechargerow = $conn->execQueryOne( 'SELECT * FROM recharge WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); if (!$rechargerow) { return true; } $daily_purchase = $rechargerow['daily_purchase']; if ($daily_purchase == null || $daily_purchase == '') { return true; } $todaysecs = phpcommon\getdayseconds(time()); $daily_obj = json_decode($daily_purchase . true); if (!$daily_obj) { return true; } if ($productid == 10) { foreach ($daily_obj as $item) { if ($item['time'] > $todaysecs) { return false; } } } else { foreach ($daily_obj as $item) { if (($item['id'] == $productid || $item['id'] == 10) && $item['time'] > $todaysecs) { return false; } } } return true; } public function purchaseNotify() { $params = array( 'account_id' => $_REQUEST['account_id'], 'goodsid' => $_REQUEST['goodsid'], 'orderid' => $_REQUEST['orderid'], 'amount' => $_REQUEST['amount'], ); $oristr = 'account_id=' . $_REQUEST['account_id'] . '&goodsid=' . $_REQUEST['goodsid'] . '&orderid=' . $_REQUEST['orderid'] . '&amount=' . $_REQUEST['amount'] . ':' . $_REQUEST['timestamp'] . 'NrN3zkVOzXF1vRzUc9eJM9ZKRO5eLooD'; // $sign = phpcommon\md5Sign($params, 'NrN3zkVOzXF1vRzUc9eJM9ZKRO5eLooD', $_REQUEST['timestamp']); $sign = md5($oristr); error_log('src:' . $oristr . '|' . $sign . '|' . $_REQUEST['sign']); if ($sign != $_REQUEST['sign']) { error_log('game2004api payNotify sign error:' + $sign + '|' + json_encode($_REQUEST)); echo json_encode(array( 'errcode' => 1, 'errmsg' => '签名校验失败' )); die(); } $shopgoods = metatable\getShopGoodsById($_REQUEST['goodsid']); if (!$shopgoods) { error_log('game2004api payNotify goods error:' + json_encode($_REQUEST)); echo json_encode(array( 'errcode' => 2, 'errmsg' => 'goods 未找到' )); die(); } if ( $shopgoods['type'] != 2 && //特惠礼包 $shopgoods['type'] != 3 //月卡 ) { error_log('game2004api payNotify goods type error:' + json_encode($_REQUEST)); echo json_encode(array( 'errcode' => 3, 'errmsg' => 'goods type error' )); die(); } $privilegecard_conf = null; if ($shopgoods['type'] == 3) { $privilegecard_conf = metatable\getPrivilegeCardById($_REQUEST['goodsid']); if (!$privilegecard_conf) { error_log('game2004api payNotify privilege card goods config error:' + json_encode($_REQUEST)); echo json_encode(array( 'errcode' => 4, 'errmsg' => 'privilege card error' )); die(); } } $conn = $this->getMysql($_REQUEST['account_id']); $orderRow = $conn->execQueryOne( 'SELECT * FROM orderinfo WHERE orderid=:orderid', array( ':orderid' => $_REQUEST['orderid'] ) ); if ($orderRow) { echo json_encode(array( 'errcode' => 0, 'errmsg' => '' )); die(); } $nowtime = time(); $this->insertNewOrder($conn, $nowtime); $this->updateUserTable($conn); $this->addToBuyHis($conn, $nowtime); $account_id = $_REQUEST['account_id']; $rechargerow = $conn->execQueryOne( 'SELECT * FROM recharge WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); $all_item_list = array(); $item_list = array(); $addreward = new classes\AddReward(); if ($shopgoods['first_present'] > 0) { array_push($item_list, array( 'item_id' => 10003, 'item_num' => $shopgoods['first_present'], 'time' => 0, )); $addreward->addReward(10003, $shopgoods['first_present'], $account_id, 0, 0); } $rechargeactivity = new classes\RechargeActivity(); $activity = array(); if ($rechargerow && $rechargerow['activity'] != null && $rechargerow['activity'] != '') { $activity = json_decode($rechargerow['activity'], true); } $rechargeactivity->updateActivityCur($activity, $shopgoods['price'] * 10, true); if ($shopgoods['type'] == 3) { $nowtime = time(); // update vip_info if (!$rechargerow) { $vip_info = array(); $expire = 0; if ($privilegecard_conf['time'] > 0) { $expire = phpcommon\getdayseconds($nowtime) + $privilegecard_conf['time'] * 3600 * 24 + 3600 * 24 - 1; } array_push($vip_info, array( 'id' => $_REQUEST['goodsid'], 'expire' => $expire, 'daily_time' => 0, )); $ret = $conn->execScript( 'INSERT INTO recharge(accountid, vip_info, activity, create_time, modify_time) ' . ' VALUES(:account_id, :vip_info, :activity, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:account_id, vip_info=:vip_info, activity=:activity, modify_time=:modify_time;', array( ':account_id' => $account_id, ':vip_info' => json_encode($vip_info), ':activity' => json_encode($activity), ':create_time' => $nowtime, ':modify_time' => $nowtime, ) ); } else { $vip_info = array(); if ($rechargerow['vip_info'] != NULL) { $vip_info = json_decode($rechargerow['vip_info'], true); } $found = false; foreach ($vip_info as $key => $carditem) { if ($carditem['id'] == $_REQUEST['goodsid']) { $found = true; if ($vip_info[$key]['expire'] > $nowtime) { $vip_info[$key]['expire'] += $privilegecard_conf['time'] * 3600 * 24; } else { if ($privilegecard_conf['time'] > 0) { $vip_info[$key]['expire'] = phpcommon\getdayseconds($nowtime) + $privilegecard_conf['time'] * 3600 * 24 + 3600 * 24 - 1; } } } } if (!$found) { $expire = 0; if ($privilegecard_conf['time'] > 0) { $expire = phpcommon\getdayseconds($nowtime) + $privilegecard_conf['time'] * 3600 * 24 + 3600 * 24 - 1; } array_push($vip_info, array( 'id' => $_REQUEST['goodsid'], 'expire' => $expire, 'daily_time' => 0, )); } $ret = $conn->execScript( 'UPDATE recharge SET vip_info=:vip_info, activity=:activity, modify_time=:modify_time' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':vip_info' => json_encode($vip_info), ':activity' => json_encode($activity), ':modify_time' => time(), ) ); } } else { $itemconf = metatable\getItemById($shopgoods['item_id']); if (!$itemconf) { error_log('game2004api purchaseNotify daily goods config error:' . json_encode($_REQUEST)); echo json_encode(array( 'errcode' => 4, 'errmsg' => 'privilege card error 2' )); die(); } $dropconf = $this->getDrop($itemconf['fuctionindex']); if (!$dropconf) { error_log('game2004api purchaseNotify daily goods config error 1:' . json_encode($_REQUEST)); echo json_encode(array( 'errcode' => 4, 'errmsg' => 'privilege card error 3' )); die(); } $itemidlist = explode('|', $dropconf['item_id']); $itemnumlist = explode('|', $dropconf['num']); foreach ($itemidlist as $key => $itemid) { array_push($item_list, array( 'item_id' => $itemid, 'item_num' => $itemnumlist[$key], 'time' => 0, )); $items = $addreward->addReward($itemid, $itemnumlist[$key], $account_id, 0, 0); foreach ($items as $i) { array_push($all_item_list, array( 'item_id' => $i['item_id'], 'item_num' => $i['item_num'], 'time' => $i['time'], )); } } error_log(json_encode($item_list)); //update daily purchase if (!$rechargerow) { $daily_purchase = array(); array_push($daily_purchase, array( 'id' => $_REQUEST['goodsid'], 'time' => $_REQUEST['timestamp'], )); $ret = $conn->execScript( 'INSERT INTO recharge(accountid, daily_purchase, activity, create_time, modify_time) ' . ' VALUES(:account_id, :daily_purchase, :activity, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:account_id, daily_purchase=:daily_purchase, activity=:activity, modify_time=:modify_time;', array( ':account_id' => $account_id, ':daily_purchase' => json_encode($daily_purchase), ':activity' => json_encode($activity), ':create_time' => time(), ':modify_time' => time() ) ); } else { $daily_purchase = array(); if ($rechargerow['daily_purchase'] != NULL) { $daily_purchase = json_decode($rechargerow['daily_purchase'], true); } $found = false; foreach ($daily_purchase as $key => $dailyitem) { if ($dailyitem['id'] == $_REQUEST['goodsid']) { $found = true; $daily_purchase[$key]['time'] = $_REQUEST['timestamp']; } } if (!$found) { array_push($daily_purchase, array( 'id' => $_REQUEST['goodsid'], 'time' => $_REQUEST['timestamp'], )); } $ret = $conn->execScript( 'UPDATE recharge SET daily_purchase=:daily_purchase, activity=:activity, modify_time=:modify_time' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':daily_purchase' => json_encode($daily_purchase), ':activity' => json_encode($activity), ':modify_time' => time(), ) ); } } echo json_encode(array( 'errcode' => 0, 'errmsg' => '' )); $key = 'game2004api-purchase:' . $account_id . '-' . $_REQUEST['orderid']; $r = $this->getRedis($key); if ($r) { $coin_num = $addreward->getCoinNum($account_id); $diamond_num = $addreward->getDiamondNum($account_id); $adfree = $addreward->getAdfree($account_id); $privilege = new classes\Privilege(); $plustimes = $privilege->getCoinTimesPlus($account_id); $user_purchase = array( 'errcode' => 0, 'errmsg' => '', 'order_id' => $_REQUEST['orderid'], 'status' => 1, 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, 'adfree' => $adfree, 'vip_plustime' => $plustimes, 'item_list' => $item_list, 'all_item_list' => $all_item_list, ); $purchasestr = json_encode($user_purchase); $r->set($key, $purchasestr); $r->pexpire($key, 1000 * 15); error_log($key . ':' . $purchasestr); } } private function insertNewOrder($conn, $nowtime) { $ret = $conn->execScript( 'INSERT INTO orderinfo(accountid, orderid, goodsid, price, ' . ' create_time, modify_time)' . ' VALUES(:accountid, :orderid, :goodsid, :price, ' . ' :create_time, :modify_time);', array( ':accountid' => $_REQUEST['account_id'], ':orderid' => $_REQUEST['orderid'], ':price' => $_REQUEST['amount'], ':goodsid' => $_REQUEST['goodsid'], ':create_time' => $nowtime, ':modify_time' => $nowtime ) ); if (!$ret) { echo json_encode(array( 'errcode' => 2, 'errmsg' => '服务器内部错误' )); die(); } } private function updateUserTable($conn) { $ret = $conn->execScript( 'UPDATE user SET recharge_times_total=recharge_times_total + 1 ' . ' WHERE accountid=:accountid;', array( ':accountid' => $_REQUEST['account_id'], ) ); } private function addToBuyHis($conn, $nowtime) { $dayseconds = phpcommon\getdayseconds($nowtime); $conn->execScript( 'INSERT INTO buy_his(accountid, goodsid, sum_times, today_times, ' . ' last_buy_time, create_time, modify_time)' . ' VALUES(:accountid, :goodsid, 1, 1, ' . ' :last_buy_time, :create_time, :modify_time)' . ' ON DUPLICATE KEY UPDATE sum_times=sum_times + 1, ' . ' modify_time=:modify_time, last_buy_time=:last_buy_time,' . ' today_times=' . " CASE WHEN last_buy_time < $dayseconds THEN 1 ELSE today_times + 1 END;", array( ':accountid' => $_REQUEST['account_id'], ':goodsid' => $_REQUEST['goodsid'], ':last_buy_time' => $nowtime, ':create_time' => $nowtime, ':modify_time' => $nowtime, ) ); } public function activityInfo() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $rechargerow = $conn->execQueryOne( 'SELECT * FROM recharge WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); $firstrecharge = ''; $vipinfo = array(); $dailypurchase = array(); $daysecs = phpcommon\getdayseconds(time()); if ($rechargerow) { if ($rechargerow['first_data'] != null) { $firstrecharge = $rechargerow['first_data']; } if ($rechargerow['vip_info'] != null && $rechargerow['vip_info'] != '') { $vipinfo = json_decode($rechargerow['vip_info'], true); foreach ($vipinfo as $key => $val) { $vipinfo[$key]['award'] = $val['daily_time'] < $daysecs ? 0 : 1; unset($vipinfo[$key]['daily_time']); } } if ($rechargerow['daily_purchase'] != null && $rechargerow['daily_purchase'] != '') { $dailypurchase = json_decode($rechargerow['daily_purchase'], true); $packtime = 0; foreach ($dailypurchase as $key => $val) { if ($val['id'] == 10 && $val['time'] > $daysecs) { $packtime = $val['time']; break; } } if ($packtime > 0) { $shopconf = metatable\getShopGoodsConf(); foreach ($shopconf as $itemconf) { if ($itemconf['type'] != 2) { continue; } if ($itemconf['shop_id'] == 10) { continue; } $found = false; foreach ($dailypurchase as $key => $val) { if ($val['id'] == $itemconf['shop_id']) { $found = true; $dailypurchase[$key]['time'] = $packtime; break; } } if (!$found) { array_push($dailypurchase, array( 'id' => $itemconf['shop_id'], 'time' => $packtime, )); } } } $daily = array(); foreach ($dailypurchase as $key => $val) { if ($val['time'] < $daysecs) { unset($dailypurchase[$key]); } else { array_push($daily, $val); } } $dailypurchase = $daily; } } $activityconf = metatable\getRechargeActivityConf(); $recharge_activity = array(); $activity = array(); if ($rechargerow['activity'] != null && $rechargerow['activity'] != '') { $activity = json_decode($rechargerow['activity'], true); } $needupdate = false; foreach ($activityconf as $key => $itemconf) { if (time() < strtotime($itemconf['time1']) || time() > strtotime($itemconf['time2'])) { continue; } $found = false; $itemarray = array(); foreach ($activity as $itemkey => $item) { if ($itemconf['shop_id'] == $item['id']) { $found = true; switch ($itemconf['type']) { case 1: //累积充值 case 2: //累计消耗 $itemarray = array( 'id' => $item['id'], 'cur' => $item['cur'], 'target' => $item['target'], 'award' => $item['time'] > 0 ? 1 : 0, ); break; case 3: //每日累积充值 $itemarray['id'] = $item['id']; $itemarray['target'] = $item['target']; if ($item['time'] < $daysecs) { $itemarray['cur'] = 0; $itemarray['award'] = 0; $needupdate = true; $activity[$itemkey]['cur'] = 0; $activity[$itemkey]['award'] = 0; } else { $itemarray['cur'] = $item['cur']; $itemarray['award'] = $item['award']; } break; } } } if (!$found) { $itemarray = array( 'id' => $itemconf['shop_id'], 'cur' => 0, 'target' => $itemconf['target'], 'award' => 0, ); } if ( $itemconf['type'] == 1 || $itemconf['type'] == 3 ) { $itemarray['cur'] /= 10; $itemarray['target'] /= 10; } array_push($recharge_activity, $itemarray); } if ($needupdate) { $conn->execScript( 'UPDATE recharge SET activity=:activity, modify_time=:modify_time' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':activity' => json_encode($activity), ':modify_time' => time(), ) ); } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'first_recharge' => $firstrecharge, 'vip_info' => $vipinfo, 'daily_purchase' => $dailypurchase, 'recharge_activity' => $recharge_activity, )); } public function getVipDailyAward() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $rechargerow = $conn->execQueryOne( 'SELECT vip_info FROM recharge WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); if ($rechargerow['vip_info'] == null || $rechargerow['vip_info'] == '') { phpcommon\sendError(ERR_USER_BASE + 1, '没月卡'); return; } $vipinfo = json_decode($rechargerow['vip_info'], true); $item_list = array(); $found = false; $nowTime = time(); foreach ($vipinfo as $key => $val) { if ($val['id'] == $_REQUEST['id']) { if ($val['expire'] > 0 && $val['expire'] < $nowTime) { phpcommon\sendError(ERR_USER_BASE + 1, '月卡过期'); return; } if (phpcommon\getdayseconds($val['daily_time']) >= phpcommon\getdayseconds($nowTime)) { phpcommon\sendError(ERR_USER_BASE + 1, '月卡奖励已领'); return; } $privilegecard_conf = metatable\getPrivilegeCardById($_REQUEST['id']); if (!$privilegecard_conf) { error_log('game2004api payNotify privilege card goods config error:' + json_encode($_REQUEST)); echo json_encode(array( 'errcode' => 4, 'errmsg' => 'privilege card error' )); die(); } $itemconf = metatable\getItemById($privilegecard_conf['item_id']); if (!$itemconf) { error_log('game2004api payNotify privilege card goods config error 2:' + json_encode($_REQUEST)); echo json_encode(array( 'errcode' => 4, 'errmsg' => 'privilege card error 2' )); die(); } $dropconf = $this->getDrop($itemconf['fuctionindex']); if (!$dropconf) { error_log('game2004api payNotify privilege card goods config error 3:' + json_encode($_REQUEST)); echo json_encode(array( 'errcode' => 4, 'errmsg' => 'privilege card error 3' )); die(); } $vipinfo[$key]['daily_time'] = $nowTime; $ret = $conn->execScript( 'UPDATE recharge SET vip_info=:vip_info, modify_time=:modify_time' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':vip_info' => json_encode($vipinfo), ':modify_time' => time(), ) ); if (!$ret) { echo json_encode(array( 'errcode' => 2, 'errmsg' => '服务器内部错误' )); die(); } $itemidlist = explode('|', $dropconf['item_id']); $itemnumlist = explode('|', $dropconf['num']); $addreward = new classes\AddReward(); $all_item_list = array(); foreach ($itemidlist as $key => $itemid) { array_push($item_list, array( 'item_id' => $itemid, 'item_num' => $itemnumlist[$key], 'time' => 0, )); $items = $addreward->addReward($itemid, $itemnumlist[$key], $account_id, 0, 0); foreach ($items as $i) { array_push($all_item_list, array( 'item_id' => $i['item_id'], 'item_num' => $i['item_num'], 'time' => $i['time'], )); } } $found = true; $coin_num = $addreward->getCoinNum($account_id); $diamond_num = $addreward->getDiamondNum($account_id); $adfree = $addreward->getAdfree($account_id); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, 'adfree' => $adfree, 'id' => $_REQUEST['id'], 'item_list' => $item_list, 'vip_info' => json_encode($vipinfo), 'all_item_list' => $all_item_list, )); } } if (!$found) { phpcommon\sendError(ERR_USER_BASE + 1, '没月卡 2'); return; } } public function getActivityAward() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $rechargerow = $conn->execQueryOne( 'SELECT activity FROM recharge WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); if ($rechargerow['activity'] == null || $rechargerow['activity'] == '') { phpcommon\sendError(ERR_USER_BASE + 1, '没参与活动'); return; } $activity = json_decode($rechargerow['activity'], true); $item_list = array(); $found = false; $nowTime = time(); foreach ($activity as $key => $val) { if ($val['id'] == $_REQUEST['id']) { if ($val['cur'] < $val['target']) { phpcommon\sendError(ERR_USER_BASE + 1, '没完成'); return; } $activity_conf = metatable\getRechargeActivityById($_REQUEST['id']); if (!$activity_conf) { error_log('game2004api payNotify recharge activity config error:' + json_encode($_REQUEST)); echo json_encode(array( 'errcode' => 4, 'errmsg' => 'activity error' )); die(); } if ($activity_conf['type'] == 3) { //每日充值活动 if ($val['time'] < phpcommon\getdayseconds($nowTime) || $val['award'] != 0) { phpcommon\sendError(ERR_USER_BASE + 1, '已领'); return; } $activity[$key]['award'] = 1; } else { if ($val['time'] > 0) { phpcommon\sendError(ERR_USER_BASE + 1, '已领'); return; } $activity[$key]['time'] = $nowTime; } $ret = $conn->execScript( 'UPDATE recharge SET activity=:activity, modify_time=:modify_time' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':activity' => json_encode($activity), ':modify_time' => $nowTime, ) ); if (!$ret) { echo json_encode(array( 'errcode' => 2, 'errmsg' => '服务器内部错误' )); die(); } $itemidlist = explode('|', $activity_conf['item_id']); $itemnumlist = explode('|', $activity_conf['item_num']); $addreward = new classes\AddReward(); $all_item_list = array(); foreach ($itemidlist as $itemkey => $itemid) { array_push($item_list, array( 'item_id' => $itemid, 'item_num' => $itemnumlist[$itemkey], 'time' => 0, )); $items = $addreward->addReward($itemid, $itemnumlist[$itemkey], $account_id, 0, 0); foreach ($items as $i) { array_push($all_item_list, array( 'item_id' => $i['item_id'], 'item_num' => $i['item_num'], 'time' => $i['time'], )); } } foreach ($activity as $key => $val) { $activity[$key]['award'] = $val['time'] > 0 ? 1 : 0; unset($activity[$key]['time']); } $found = true; $coin_num = $addreward->getCoinNum($account_id); $diamond_num = $addreward->getDiamondNum($account_id); $adfree = $addreward->getAdfree($account_id); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, 'adfree' => $adfree, 'id' => $_REQUEST['id'], 'item_list' => $item_list, 'recharge_activity' => json_encode($activity), 'all_item_list' => $all_item_list, )); } } if (!$found) { phpcommon\sendError(ERR_USER_BASE + 1, '没活动 2'); return; } } protected function getDrop($drop_id) { $drop_meta_table = require('../res/drop@drop.php'); $drop_meta = getDropConfig($drop_meta_table, $drop_id); if (!$drop_meta) { return null; } $d = array( 'drop_id' => $drop_meta['drop_id'], 'item_id' => $drop_meta['item_id'], 'num' => $drop_meta['num'], 'weight' => $drop_meta['weight'], 'type' => $drop_meta['type'] ); return $d; } }