This commit is contained in:
aozhiwei 2019-08-15 15:03:29 +08:00
parent fef83e2ca7
commit 3ea2a3af64
2 changed files with 58 additions and 25 deletions

View File

@ -412,6 +412,7 @@ class ActivityController{
$randreward_uuid = 'game2001api_randreward_uuid:' . md5($_REQUEST['account_id']); $randreward_uuid = 'game2001api_randreward_uuid:' . md5($_REQUEST['account_id']);
$randreward_list = array(); $randreward_list = array();
$r = $this->getRedis($randreward_uuid); $r = $this->getRedis($randreward_uuid);
$user_db_str = $r->get($randreward_uuid);
if (!$r) { if (!$r) {
die(); die();
return; return;

View File

@ -18,6 +18,18 @@ class ShareController{
return $conn; return $conn;
} }
protected function getRedis($shop_uuid)
{
$redis_conf = getRedisConfig(crc32($shop_uuid));
$r = new phpcommon\Redis(array(
'host' => $redis_conf['host'],
'port' => $redis_conf['port'],
'passwd' => $redis_conf['passwd']
));
return $r;
}
protected function getDrop($drop_id) protected function getDrop($drop_id)
{ {
$drop_meta_table = require('../res/drop@drop.php'); $drop_meta_table = require('../res/drop@drop.php');
@ -492,6 +504,32 @@ class ShareController{
'item_id' => $item_id, 'item_id' => $item_id,
'item_num' => $item_num, 'item_num' => $item_num,
)); ));
//保存客服奖励
$kefureward_uuid = 'game2001api_kefureward_uuid:' . md5($_REQUEST['account_id']);
$kefureward_list = array();
$r = $this->getRedis($kefureward_uuid);
$user_db_str = $r->get($kefureward_uuid);
if (!$r) {
die();
return;
}
if (empty($user_db_str)) {
$kefureward_db = array(
'kefureward_uuid' => $kefureward_uuid,
'kefureward_list' => $item_list,
);
$r -> set($kefureward_uuid, json_encode($kefureward_db));
$r -> pexpire($kefureward_uuid, 1000 * 300);
} else {
$kefureward_db = array(
'kefureward_uuid' => $kefureward_uuid,
'kefureward_list' => $item_list,
);
$r -> set($kefureward_uuid, json_encode($kefureward_db));
$r -> pexpire($kefureward_uuid, 1000 * 300);
}
//更新状态 //更新状态
$ret = $conn->execScript('UPDATE user SET kefu_status=1, modify_time=:modify_time ' . $ret = $conn->execScript('UPDATE user SET kefu_status=1, modify_time=:modify_time ' .
' WHERE accountid=:accountid;', ' WHERE accountid=:accountid;',
@ -526,35 +564,29 @@ class ShareController{
return; return;
} }
$mail_id = $_REQUEST['mail_ids']; $mail_id = $_REQUEST['mail_ids'];
$d = $this->getDrop(24005);
if (!$d) { $user_db_str = $r->get($kefureward_uuid);
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); if (empty($user_db_str)) {
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
return; return;
} }
$item_id_array = $this->getExplode($d['item_id']); $user_db = json_decode($user_db_str, true);
$weight_sum = 0; if (empty($user_db)) {
$keys = 0; phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
$item_num_array = $this->getExplode($d['num']); return;
$weight_array = $this->getExplode($d['weight']);
for ($i = 0; $i < count($weight_array); $i++) {
$weight_sum += $weight_array[$i][0];
} }
srand(crc32($account_id . $mail_id));
$random = Rand(0, $weight_sum);
$weight = 0;
for ($i = 0; $i < count($weight_array); $i++) {
$weight += $weight_array[$i][0];
if ($weight > $random) {
$keys = $i;
break;
}
}
$item_id = $item_id_array[$keys][0];
$item_num = $item_num_array[$keys][0];
$p = $this->getParameter(REWARD_TIMES); $p = $this->getParameter(REWARD_TIMES);
$times = $p['param_value'] - 1; $times = $p['value'] - 1;
$addreward = new classes\AddReward(); foreach ($user_db['kefureward_list'] as $kefureward) {
$addreward->addReward($item_id, $item_num * $times, $account_id); //增加奖励
$addreward = new classes\AddReward();
$addreward->addReward($kefureward['item_id'], $kefureward['item_num'] * $times, $account_id);
}
array_push($item_list, array(
'item_id' => $item_id,
'item_num' => $item_num,
));
echo json_encode(array( echo json_encode(array(
'errcode' => 0, 'errcode' => 0,
'errmsg' => '', 'errmsg' => '',