diff --git a/third_party/phpcommon b/third_party/phpcommon index 0a068e9..525288b 160000 --- a/third_party/phpcommon +++ b/third_party/phpcommon @@ -1 +1 @@ -Subproject commit 0a068e9955af28447277dc664489d8b852dec15e +Subproject commit 525288beb5a668632e277ad604dc4a4de94546a0 diff --git a/webapp/controller/NewPayActivityController.class.php b/webapp/controller/NewPayActivityController.class.php new file mode 100644 index 0000000..7165d8f --- /dev/null +++ b/webapp/controller/NewPayActivityController.class.php @@ -0,0 +1,1096 @@ +readData(); + } + + private function readData() + { + $conn = $this->getSelfMysql(); + $rows = phpcommon\SqlHelper::select + ( + $this->getSelfMysql(), + 'recharge_activity', + array( + 'blobdata' + ), + array( + 'accountid' => $this->getAccountId() + ) + ); + foreach ($rows as $row) { + $rec_db_str = $row['blobdata']; + $this->data= json_decode($rec_db_str, true); + } + if (empty($this->data)) { + $this->data = array( + 'single_list' => array(), + 'sum_list' => array(), + 'quest_list' => array(), + 'shop_list' => array(), + 'dress_list' => array(), + 'discount_list' => array(), + 'draw_list' => array(), + 'table_list' => array(), + 'daily_list' => array(), + ); + } + } + + function getExplode($string) + { + $delim = "|"; + $drop_multiply = explode($delim, $string); + $delim1 = ":"; + $arr = array(); + for ($i = 0; $i < count($drop_multiply); $i++) { + $mul = explode($delim1, $drop_multiply[$i]); + array_push($arr, $mul); + } + return $arr; + } + + protected function saveRecActDB($account_id, $rec_db) { + $conn = $this->getMysql($account_id); + $row = $conn->execQueryOne('SELECT accountid FROM recharge_activity WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $rec_db_str = ""; + if (!empty($rec_db)) { + $rec_db_str = json_encode($rec_db); + } + if (!empty($row)) { + //update + $row = $conn->execScript('UPDATE recharge_activity SET blobdata=:blobdata, modify_time=:modify_time WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':blobdata' => $rec_db_str, + ':modify_time' => phpcommon\getNowTime() + )); + } else { + //insert + $row = $conn->execScript('INSERT INTO recharge_activity(accountid, blobdata, create_time, modify_time) ' . + ' VALUES(:account_id, :blobdata, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:account_id, blobdata=:blobdata, modify_time=:modify_time;', + array( + ':account_id' => $account_id, + ':blobdata' => $rec_db_str, + ':create_time' => phpcommon\getNowTime(), + ':modify_time' => phpcommon\getNowTime(), + )); + } + } + + protected function recSingleRmb($num, $account_id) + { + $conn = $this->getMysql($account_id); + $user_db = $this->readRecActDB($account_id); + $row = $conn->execQueryOne('SELECT accountid, daily_max_single FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if ($row['daily_max_single'] == 0) { + foreach ($user_db['single_list'] as &$us) { + if ($us['status'] != 1) { + continue; + } + for ($i = count($us['reward']) - 1; $i > 0; $i--) { + if ($num >= $us['reward'][$i]['condition']) { + $us['reward'][$i]['status'] = 1; + break; + } + } + $us['status'] = 2; + $us['time'] = phpcommon\getNowTime(); + break; + } + $this->saveRecActDB($account_id, $user_db); + } + } + + public function rechargeRmb() + { + $num = $_REQUEST['num']; + $addreward = new classes\AddReward(); + $now_lv = $addreward->getVipLevel($account_id); + $this->recSingleRmb($num, $account_id); + $locket = $this->addRmb($num, $account_id); + $quest = new classes\Quest(); + $quest->flushActQuest(71014, $num, $account_id); + $new_lv = $addreward->getVipLevel($account_id); + $isUp = false; + if ($new_lv > $now_lv) { + $isUp = true; + $addreward->insertMailEvent($account_id, $now_lv, $new_lv); + $addreward->updaterechargelv($account_id, $new_lv, 0); + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'isUp' => $isUp, + 'lv' => $new_lv, + 'locket' => $locket, + )); + } + + protected function addRmb($num, $account_id) + { + $conn = $this->getMysql($account_id); + $row = $conn->execQueryOne('SELECT accountid, sum_coin, recharge_times_total, max_single_recharge, daily_max_single, rmb_lot_ticket, sumlot_coin FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $sum_coin = $row['sum_coin'] + $num; + $rmb_lot_ticket = floor(($num + $row['sumlot_coin']) / 10) + $row['rmb_lot_ticket']; + $sumlot_coin = floor(($num + $row['sumlot_coin']) % 10); + $recharge_times_total = $row['recharge_times_total'] + 1; + $max_single_recharge = $row['max_single_recharge']; + if ($max_single_recharge < $num) { + $max_single_recharge = $num; + } + $daily_max_single = $row['daily_max_single']; + if ($daily_max_single < $num) { + $daily_max_single = $num; + } + $ret = $conn->execScript('UPDATE user SET sum_coin=:sum_coin, recharge_times_total=:recharge_times_total, max_single_recharge=:max_single_recharge, daily_max_single=:daily_max_single, modify_time=:modify_time, rmb_lot_ticket=:rmb_lot_ticket, sumlot_coin=:sumlot_coin WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':modify_time' => phpcommon\getNowTime(), + ':sum_coin' => $sum_coin, + ':recharge_times_total' => $recharge_times_total, + ':max_single_recharge' => $max_single_recharge, + ':daily_max_single' => $daily_max_single, + ':rmb_lot_ticket' => $rmb_lot_ticket, + ':sumlot_coin' => $sumlot_coin, + )); + return $rmb_lot_ticket; + } + + public function rechargeBuy() + { + $id = $_REQUEST['id']; + $item_conf = metatable\getItemById($id); + if (!$item_conf) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具'); + return; + } + $item_list = metatable\getDropListById($item_conf['fuctionindex']); + if (!$item_list) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + if ($item_conf['buy_reward'] && $item_conf['buy_reward'] != '') { + $item_arr = $this->getExplode($item_conf['buy_reward']); + array_push($item_list, array( + 'item_id' => $item_arr[0][0], + 'item_num' => $item_arr[0][1], + 'time' => $item_arr[0][2], + )); + } + $all_item_list = array(); + $addreward = new classes\AddReward(); + foreach ($item_list as $item) { + $items = $addreward->addReward($item['item_id'], $item['item_num'], $account_id, $item['time'], 0); + foreach($items as $i) { + array_push($all_item_list, array( + 'item_id' => $i['item_id'], + 'item_num' => $i['item_num'], + 'time' => $i['time'], + )); + } + } + $coin_num = $addreward->getCoinNum($account_id); + $rmb_num = $addreward->getRmbNum($account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'item_list' => $item_list, + 'coin_nums' => $coin_num, + 'rmb_nums' => $rmb_num, + 'all_item_list' => $all_item_list + )); + } + + public function unlockPassCard() + { + $row = phpcommon\SqlHelper::selectOne + ($this->getSelfMysql(), + 'user', + array( + 'rmb_num', + 'rmb_lot_ticket' + ), + array( + 'accontid' => $this->getAccountId() + ) + ); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $cost = metatable\getParameterByName('season_card_cost'); + if (!$cost) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具'); + return; + } + //扣除点券 + // $rmb_lot_ticket = floor($cost / 10) + $row['rmb_lot_ticket']; + // // if ($row['rmb_num'] < $cost) { + // // phpcommon\sendError(ERR_USER_BASE + 3, '点券不足'); + // // return; + // // } + $ret = phpcommon\SqlHelper::update + ($this->getSelfMysql(), + 'user', + array( + 'accountid' => $this->getAccountId() + ), + array( + 'passcard' => 1, + 'modify_time' => $this->getNowTime() + ) + ); + if (!$ret) { + die(); + return; + } + $addreward = new classes\AddReward(); + // $now_lv = $addreward->getVipLevel($account_id); + // $this->recSingleRmb($cost, $account_id); + // $this->addRmb($cost, $account_id); + + // $new_lv = $addreward->getVipLevel($account_id); + // $isUp = false; + // if ($new_lv > $now_lv) { + // $isUp = true; + // $addreward->insertMailEvent($account_id, $now_lv, $new_lv); + // $addreward->updaterechargelv($account_id, $new_lv, 0); + // } + + $rmb_num = $addreward->getRmbNum($account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'status' => 1, + // 'isUp' => $isUp, + // 'lv' => $new_lv, + 'rmb_nums' => $rmb_num, + )); + } + + //充值活动 + public function recAcitivityInfo() + { + $row = phpcommon\SqlHelper::SelectOne + ($this->getSelfMysql(), + 'user', + array( + 'rmb_num', + 'score' + ), + array( + 'accountid' => $this->getAccountId() + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + //充值活动信息 + $this->getRecActInfo($row['rmb_num']); + $user_db = $this->readRecActDB($account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'single_list' => $user_db['single_list'], + 'sum_list' => $user_db['sum_list'], + 'quest_list' => $user_db['quest_list'], + 'shop_list' => $user_db['shop_list'], + 'dress_list' => $user_db['dress_list'], + 'discount_list' => $user_db['discount_list'], + 'draw_list' => $user_db['draw_list'], + 'table_list' => $user_db['table_list'], + 'daily_list' => $user_db['daily_list'], + )); + } + + protected function getRecActInfo($rmb_num) + { + $recharge = new classes\RechargeActInfo(); + $single_list = $recharge->getActSingleInfo(1, $user_db['single_list'], $rmb_num, $account_id); + $sum_list = $recharge->getActSumInfo(2, $user_db['sum_list'], $rmb_num, $account_id); + $quest_list = $recharge->getActQuestInfo(3, $user_db['quest_list'], $rmb_num, $account_id); + $shop_list = $recharge->getActShopInfo(4, $user_db['shop_list'], $rmb_num, $account_id); + $dress_list = $recharge->getActDressInfo(5, $user_db['dress_list'], $rmb_num, $account_id); + $discount_list = $recharge->getActDiscountInfo(6, $user_db['discount_list'], $rmb_num, $account_id); + $draw_list = $recharge->getActDrawInfo(7, $user_db['draw_list'], $rmb_num,$account_id); + $table_list = $recharge->getActTableInfo(8, $user_db['table_list'], $rmb_num, $account_id); + // if ($user_db['daily_list']) { + // $item_list = $this->getDailyExtraReward($user_db, $account_id); + // } + $daily_list = $recharge->getActDailyInfo(9, $user_db['daily_list'], $rmb_num, $account_id); + $act_db = array( + 'single_list' => $single_list, + 'sum_list' => $sum_list, + 'quest_list' => $quest_list, + 'shop_list' => $shop_list, + 'dress_list' => $dress_list, + 'discount_list' => $discount_list, + 'draw_list' => $draw_list, + 'table_list' => $table_list, + 'daily_list' => $daily_list, + ); + $this->saveRecActDB($account_id, $act_db); + } + + protected function getDailyExtraReward($user_db, $account_id, $type, $id, $idx) + { + $item_list = array(); + foreach ($user_db['daily_list'] as &$us) { + if ($us['id'] != $id) { + continue; + } + foreach ($us['daily_list'] as &$key) { + if ($idx != $key['condition']) { + continue; + } + $item_list = $key['extra']; + $key['time'] = phpcommon\getNowTime(); + $key['extra_status'] = 2; + } + } + $this->saveRecActDB($account_id, $user_db); + return $item_list; + } + + //充值活动奖励 + public function recAcitivityReward() + { + $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 + 2, '没有这个玩家'); + return; + } + $user_db = $this->readRecActDB($account_id); + if (!$user_db || empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $type = $_REQUEST['type']; + $id = $_REQUEST['id']; + $idx = $_REQUEST['idx']; + //十连抽特殊字段 + $draw_type = 0; + if (isset($_REQUEST['draw_type'])) { + $draw_type = $_REQUEST['draw_type']; + } + $isUp = false; + $addreward = new classes\AddReward(); + $new_lv = $addreward->getVipLevel($account_id); + $item_list = $this->getActRewardList($account_id, $user_db, $type, $id, $idx, $draw_type); + // if ($type == 9 && $draw_type == 0) { + // $cost = $item_list[0]['cost']; + // $item_list = $item_list[0]['item_list']; + // $now_lv = $addreward->getVipLevel($account_id); + // $this->recSingleRmb($cost, $account_id); + // $this->addRmb($cost, $account_id); + // $new_lv = $addreward->getVipLevel($account_id); + // $isUp = false; + // if ($new_lv > $now_lv) { + // $isUp = true; + // $addreward->insertMailEvent($account_id, $now_lv, $new_lv); + // $addreward->updaterechargelv($account_id, $new_lv, 0); + // } + // } + if (!$item_list || empty($item_list)) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $all_item_list = array(); + foreach ($item_list as $item) { + $items = $addreward->addReward($item['item_id'], $item['item_num'], $account_id, $item['time'], 0); + foreach($items as $i) { + array_push($all_item_list, array( + 'item_id' => $i['item_id'], + 'item_num' => $i['item_num'], + 'time' => $i['time'], + )); + } + } + $coin_num = $addreward->getCoinNum($account_id); + $rmb_num = $addreward->getRmbNum($account_id); + $rmb_ticket = $addreward->getRmbTicketNum($account_id); + $row = $conn->execQueryOne('SELECT free_box FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'item_list' => $item_list, + 'coin_nums' => $coin_num, + 'rmb_nums' => $rmb_num, + 'all_item_list' => $all_item_list, + 'rmb_lot_ticket' => $rmb_ticket, + 'free_box' => $row['free_box'], + // 'isUp' => $isUp, + // 'lv' => $new_lv, + )); + } + + protected function getActRewardList($account_id, $user_db, $type, $id, $idx, $draw_type) + { + $item_list = array(); + if ($type == 1) { + $item_list = $this->getSingleReward($account_id, $user_db, $type, $id, $idx); + } else if ($type == 2) { + $item_list = $this->getSumReward($account_id, $user_db['sum_list'], $id, $draw_type); + } else if ($type == 3) { + $item_list = $this->getQuestReward($account_id, $user_db, $type, $id, $idx, $draw_type); + } else if ($type == 4) { + $item_list = $this->getShopReward($account_id, $user_db, $type, $id, $idx); + } else if ($type == 5) { + $item_list = $this->getDressReward($account_id, $user_db['dress_list'], $type, $id, $idx); + } else if ($type == 6) { + $item_list = $this->getDiscountReward($account_id, $user_db, $type, $id, $idx); + } else if ($type == 7) { + $item_list = $this->getDrawReward($account_id, $user_db['draw_list'], $type, $id, $idx, $user_db); + } else if ($type == 8) { + $item_list = $this->getTableReward($account_id, $user_db['table_list'], $type, $id, $idx, $draw_type); + } else if ($type == 9) { + if ($draw_type == 0) { + $item_list = $this->getDailyReward($account_id, $user_db, $type, $id, $idx); + } else { + $item_list = $this->getDailyExtraReward($user_db, $account_id, $type, $id, $idx); + } + } + return $item_list; + } + + protected function getDailyReward($account_id, $user_db, $type, $id, $idx) + { + $item_list = array(); + $cost = 0; + $addreward = new classes\AddReward(); + foreach ($user_db['daily_list'] as &$us) { + if ($us['id'] != $id) { + continue; + } + $key = 0; + $day = 0; + foreach ($us['daily_list'] as &$d) { + if ($idx != $d['condition']) { + if ($d['condition'] > $cost) { + $d['dprice'] = $cost + $d['dprice']; + } + if ($d['status'] == 1) { + $day = $day + $d['time_long']; + } + } else { + $item_conf = metatable\getItemById($d['reward_id']); + if (!$item_conf) { + return null; + } + $item_list = metatable\getDropListById($item_conf['fuctionindex']); + foreach ($d['extra'] as $ex) { + array_push($item_list, $ex); + } + $d['status'] = 1; + $d['time'] = phpcommon\getNowTime(); + $d['buytime'] = phpcommon\getNowTime(); + $d['day'] = $day + $d['time_long']; + $d['extra_status'] = 2; + $cost = $d['condition']; + $us['forever'] = $key + 1; + for ($i = 1; $i < $us['forever']; $i++) { + $addreward->addReward($i + 19000, 1, $account_id, 0, 0); + } + $addreward->updaterechargelv($account_id, $key + 1, 1); + } + $key++; + } + break; + } + $this->saveRecActDB($account_id, $user_db); + // // $this->recSingleRmb($cost, $account_id); + // // $this->addRmb($cost, $account_id); + // $item_info = array(); + // array_push($item_info, array( + // 'item_list' => $item_list, + // 'cost' => $cost, + // )); + return $item_list; + } + + protected function getSingleReward($account_id, $user_db, $type, $id, $idx) + { + $item_list = array(); + foreach ($user_db['single_list'] as &$us) { + if ($us['id'] != $id) { + continue; + } + foreach ($us['reward'] as &$r) { + if ($idx != $r['condition']) { + continue; + } + $item_conf = metatable\getItemById($r['reward_id']); + if (!$item_conf) { + return null; + } + $item_list = metatable\getDropListById($item_conf['fuctionindex']); + $r['status'] = 2; + break; + } + $us['status'] = 3; + $us['time'] = phpcommon\getNowTime(); + break; + } + foreach ($user_db['single_list'] as &$us) { + $us['time'] = phpcommon\getNowTime(); + } + $this->saveRecActDB($account_id, $user_db); + return $item_list; + } + + protected function getSumReward($account_id, $info_list, $id, $draw_type) + { + $act = metatable\getActPlusById($id); + $item_conf = metatable\getItemById($act['reward']); + $item_list = array(); + if (!$item_conf) { + return null; + } + $num = 1; + if ($draw_type == 1) { + $num = 10; + } + $re = $this->subCoin($account_id, 99999, $num); + if (!$re) { + phpcommon\sendError(ERR_USER_BASE + 4, '货币不足'); + die(); + return; + } + $item_list = array(); + for ($i = 0; $i < $num; $i++) { + $items = metatable\getDropListById($item_conf['fuctionindex']); + if (!$items) { + return null; + } + foreach ($items as $it) { + array_push($item_list, array( + 'item_id' => $it['item_id'], + 'item_num' => $it['item_num'], + 'time' => $it['time'], + )); + } + } + return $item_list; + } + + protected function getQuestReward($account_id, $user_db, $type, $id, $idx, $condition) + { + $item_list = array(); + foreach ($user_db['quest_list'] as &$us) { + if (!isset($us['id']) || $us['id'] != $id) { + continue; + } + $num = 0; + foreach ($us['quest_list'] as &$q) { + if ($q['id'] != $idx) { + $num++; + continue; + } + + if ($q['condition'] != $condition) { + $num++; + continue; + } + + if ($q['status'] != 1) { + $num++; + continue; + } + array_push($item_list, array( + 'item_id' => $us['reward'][$num]['item_id'], + 'item_num' => $us['reward'][$num]['item_num'], + 'time' => $us['reward'][$num]['time'], + )); + $q['status'] = 2; + $num++; + break; + } + break; + } + $this->saveRecActDB($account_id, $user_db); + return $item_list; + } + protected function getShopReward($account_id, $user_db, $type, $id, $idx) + { + $item_list = array(); + foreach ($user_db['shop_list'] as &$us) { + if (empty($us['id']) || $us['id'] != $id) { + continue; + } + foreach ($us['reward']['shop_list'] as &$s) { + if ($s['id'] != $idx) { + continue; + } + $price_id = 10003; + if ($s['buy'] == 2) { + $price_id = 10003; + } else if ($s['buy'] == 1) { + $price_id = 10001; + } + $re = $this->subCoin($account_id, $price_id, $s['price']); + if (!$re || ($s['status'] >= $s['limit_val'] && $s['limit_val'] != 0)) { + return null; + } + array_push($item_list, array( + 'item_id' => $s['id'], + 'item_num' => 1, + 'time' => 0, + )); + $s['status']++; + break; + } + } + $this->saveRecActDB($account_id, $user_db); + return $item_list; + } + protected function getDressReward($account_id, $info_list, $type, $id, $idx) + {} + protected function getDiscountReward($account_id, $user_db, $type, $id, $idx) + { + $item_list = array(); + $item_id = 0; + foreach ($user_db['discount_list'] as &$us) { + if ($id != $us['id']) { + continue; + } + foreach ($us['reward'] as &$r) { + $re = $this->subCoin($account_id, 10003, $r['price']); + if (!$re || $r['status'] == 1) { + return null; + } + $item_id = $r['id']; + array_push($item_list, array( + 'item_id' => $r['id'], + 'item_num' => 1, + 'time' => 0, + )); + $r['status'] = 1; + break; + } + } + $rec = $this->flushItem($account_id, $user_db, $id, $item_id, 1); + if (!$rec) { + return null; + } + //$this->saveRecActDB($account_id, $user_db); + return $item_list; + } + + protected function getDrawReward($account_id, $info_list, $type, $id, $idx, $user_db) + { + $item_list = array(); + $keys = 0; + for ($i = 0; $i < count($info_list); $i++) { + if ($info_list[$i]['id'] == $id) { + $reward = $info_list[$i]['reward']; + break; + } + } + if (empty($reward) || !$reward) { + return $item_list; + } + $weight_sum = 0; + for ($j = 0; $j < count($reward); $j++) { + $weight_sum += $reward[$j]['weight']; + } + + $random = Rand(0, $weight_sum); + $weight = 0; + for ($j = 0; $j < count($reward); $j++) { + $weight += $reward[$j]['weight']; + if ($weight > $random) { + $keys = $j; + break; + } + } + $item_id = $reward[$keys]['item_id']; + $item_num = $reward[$keys]['item_num']; + $time = $reward[$keys]['time']; + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num, + 'time' => $time, + )); + if ($item_list) { + $re = $this->subCoin($account_id, $info_list[$idx]['conditionid'], $info_list[$idx]['condition']); + if (!$re) { + return null; + } + } + unset($reward[$keys]); + $user_db['draw_list'][$idx]['reward'] = array_values($reward); + $this->saveRecActDB($account_id, $user_db); + return $item_list; + } + + protected function getTableReward($account_id, $info_list, $type, $id, $idx, $draw_type) + { + $act = metatable\getActPlusById($id); + $item_conf = metatable\getItemById($act['reward']); + $item_list = array(); + if (!$item_conf) { + return null; + } + $num = 1; + if ($draw_type == 1) { + $num = 10; + } + for ($i = 0; $i < $num; $i++) { + $items = metatable\getDropListById($item_conf['fuctionindex']); + if (!$items) { + return null; + } + foreach ($items as $it) { + array_push($item_list, array( + 'item_id' => $it['item_id'], + 'item_num' => $it['item_num'], + 'time' => $it['time'], + )); + } + } + if ($draw_type != 2) { + $re = $this->subCoin($account_id, $info_list[$idx]['conditionid'], $info_list[$idx]['condition'] * $num); + if (!$re) { + phpcommon\sendError(ERR_USER_BASE + 4, '货币不足'); + die(); + return; + } + } else { + $conn = $this->getMysql($account_id); + $row = $conn->execQueryOne('SELECT free_box FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + if (!$row || $row['free_box'] >= metatable\getParameterByName('activit_draw_times')) { + phpcommon\sendError(ERR_USER_BASE + 5, '今日次数已达上限'); + die(); + return; + } + $ret = $conn->execScript('UPDATE user SET free_box=:free_box, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':free_box' => $row['free_box'] + 1, + ':modify_time' => phpcommon\getNowTime() + )); + } + return $item_list; + } + + protected function subCoin($account_id, $id, $num) + { + $conn = $this->getMysql($account_id); + $row = $conn->execQueryOne('SELECT rmb_num, coin_num, rmb_lot_ticket FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + if (!$row) { + return false; + } + if ($id == 10001) { + if ($row['coin_num'] < $num) { + return false; + } + $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':coin_num' => $row['coin_num'] - $num, + ':modify_time' => phpcommon\getNowTime() + )); + } else if ($id == 10003 || $id == 10007) { + if ($row['rmb_num'] < $num) { + return false; + } + $ret = $conn->execScript('UPDATE user SET rmb_num=:rmb_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':rmb_num' => $row['rmb_num'] - $num, + ':modify_time' => phpcommon\getNowTime() + )); + } else if ($id == 99999) { + if ($row['rmb_lot_ticket'] < $num) { + return false; + } + $ret = $conn->execScript('UPDATE user SET rmb_lot_ticket=:rmb_lot_ticket, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':rmb_lot_ticket' => $row['rmb_lot_ticket'] - $num, + ':modify_time' => phpcommon\getNowTime() + )); + } + if (!$ret) { + return false; + } + return true; + } + + protected function itemlistinfo($reward) + { + $item_list = array(); + $weight_sum = 0; + $keys = 0; + for ($j = 0; $j < count($reward); $j++) { + $weight_sum += $reward[$j]['weight']; + } + + $random = Rand(0, $weight_sum); + $weight = 0; + for ($j = 0; $j < count($reward); $j++) { + $weight += $reward[$j]['weight']; + if ($weight > $random) { + $keys = $j; + break; + } + } + $item_id = $reward[$keys]['item_id']; + $item_num = $reward[$keys]['item_num']; + $time = $reward[$keys]['time']; + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num, + 'time' => $time, + )); + return $item_list; + } + + //好友砍价 + public function shareDiscount() + { + $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 + 2, '没有这个玩家'); + return; + } + $user_db = $this->readRecActDB($account_id); + if (!$user_db || empty($user_db) || empty($user_db['discount_list'])) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $id = $_REQUEST['id']; + $item_id = $_REQUEST['item_id']; + $price = 0; + $flag = false; + foreach ($user_db['discount_list'] as &$us) { + if ($id != $us['id']) { + continue; + } + foreach ($us['reward'] as &$r) { + if ($r['id'] != $item_id) { + continue; + } + $r['price'] = floor($r['price'] * $r['dis_num'] / 100); + if ($r['price'] <= 5) { + $r['price'] = 0; + } + $price = $r['price']; + $flag = true; + break; + } + } + if (!$flag) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个道具'); + return; + } + $this->saveRecActDB($account_id, $user_db); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'price' => $price, + )); + } + + //好友砍价刷新 + public function flushDiscountShop() + { + $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 + 2, '没有这个玩家'); + return; + } + $user_db = $this->readRecActDB($account_id); + if (!$user_db || empty($user_db) || empty($user_db['discount_list'])) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $id = $_REQUEST['id']; + $flag = false; + $item_id = $_REQUEST['item_id']; + $rec = $this->flushItem($account_id, $user_db, $id, $item_id, 0); + if (!$rec) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个道具'); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + protected function flushItem($account_id, $user_db, $id, $item_id, $type) + { + $flag = false; + foreach ($user_db['discount_list'] as &$us) { + if ($id != $us['id']) { + continue; + } + $num = 0; + foreach ($us['sum_list'] as $s) { + if ($s['id'] == $item_id) { + $flag = true; + break; + } + $num++; + } + if (!$flag) { + //phpcommon\sendError(ERR_USER_BASE + 3, '没有这个道具'); + return null; + } + if ($type == 1) { + array_splice($us['sum_list'], $num, 1); + } + $sum_list = $us['sum_list']; + $recharge = new classes\RechargeActInfo(); + $reward = $recharge->randDiscount($sum_list, $us['reward'][0]['id']); + $us['reward'] = $reward; + break; + } + $this->saveRecActDB($account_id, $user_db); + return true; + } + + public function changeHeadKuang() + { + $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 + 2, '没有这个玩家'); + return; + } + $id = $_REQUEST['id']; + $ret = $conn->execScript('UPDATE user SET head_kuang_id=:head_kuang_id, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':head_kuang_id' => $id, + ':modify_time' => phpcommon\getNowTime() + )); + if (!$ret) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'head_kuang_id' => $id, + )); + } + + public function addmailReward() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $attachment = $_REQUEST['attachment']; + $item_list = array(); + $all_item_list = array(); + $arr = json_decode($attachment, true); + foreach ($arr as $a) { + $time = 0; + if (isset($a['time'])){ + $time = $a['time']; + } + array_push($item_list, array( + 'item_id' => $a['itemid'], + 'item_num' => $a['itemnum'], + 'time' => $time, + )); + } + $addreward = new classes\AddReward(); + foreach ($item_list as $i) { + $items = $addreward->addReward($i['item_id'], $i['item_num'], $account_id, $i['time'], 0); + foreach($items as $s) { + array_push($all_item_list, array( + 'item_id' => $s['item_id'], + 'item_num' => $s['item_num'], + 'time' => $s['time'], + )); + } + } + $coin_num = $addreward->getCoinNum($account_id); + $rmb_num = $addreward->getRmbNum($account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'item_list' => $item_list, + 'all_item_list' => $all_item_list, + 'coin_num' => $coin_num, + 'rmb_num' => $rmb_num, + )); + } + + +} +?>