Skip to content

Instantly share code, notes, and snippets.

@wangchen
Created April 25, 2014 14:25
Show Gist options
  • Save wangchen/11291388 to your computer and use it in GitHub Desktop.
Save wangchen/11291388 to your computer and use it in GitHub Desktop.
refectory
<?php
$mem = null;
$my = null;
/**
* Create tables
* @param array $tbl_num_list example: [100, 100, 100]
*/
function create_tables ($tbl_num_list) {
global $mem;
$cfg_list = array(
array(200, 100, 50, 0),
array(500, 800, 400, 5000),
array(1000, 5000, 2500, 300000)
);
$tid_list = array();
$tid = 0;
foreach ($tbl_num_list as $i => $tbl_num) {
for($j=0; $j < $tbl_num; $j ++) {
$cfg = $cfg_list[$i];
$item = array(
"tid" => $tid,
"status" => 0,
"table" => $cfg[0],
"ticket" => $cfg[1],
"stake" => $cfg[2],
"score" => 10,
"multiple" => 5,
"limit" => $cfg[3]
);
$tid_list[] = $tid;
$tid += 1;
printf("%s\n", json_encode($item));
$mc->set("tb_{$tid}", $item);
}
}
printf("%s\n", json_encode($tid_list));
$mc->set("tb_ids", $tb_id_list)
}
/**
* Add robots
* @param array $robot_num_list example: {"robots1"=>100, "robots8"=>100, "robots50"=>100}
*/
function add_robots($robot_num_list)
{
global $mem, $my;
$robot_num_total = array_sum($robot_num_list);
$sql = "select u.`uid`, i.`nickname`, b.`card_type` FROM `user` u
left join `userinfo` i on i.`uid` = u.`uid`
left join `userbag` b on b.`card_id` = i.`card_id`
where u.`is_bot` = 1 and u.`is_valid` = 1 and b.`card_id` > 0
order by b.`card_level1` desc
limit $robot_num_total";
$result = $my->query($sql) || die($my->error);
foreach ($robot_num_list as $name => $robot_num) {
$robots = array();
printf("Creating $name:$robot_num\n");
for($j=0; $j < $tbl_num; $j ++) {
$row = $result->fetch_array();
$mem->set("user" . $row['uid'], 0);
$mem->set("user" . $row['uid'] . "_nickname", $row['nickname']);
$face = $row["card_type"] > 0? $row["card_type"] : "1311";
$mem->set("user" . $row['uid'] . "_face", $face);
$robots[] = $row['uid'];
}
$mem->set($name, $robots);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment