query($sql, [$params['salesid'], $params['agentid'], $params['channelid']]); return $result; } /** * 设置代理信息,管理员版 * @param $p */ public function setSalesInfo(&$p) { // 兼容 if(empty($p['parentid'])) $p['parentid'] = null; $sql = /** @lang text */'update sales_user set saus_parentid = ?, global_power = ?, statistic_type = ?, is_vip=?, announcement=? where saus_salesid = ? and saus_agentid = ? and saus_channelid = ? LIMIT 1;'; $this->execute($sql, [$p['parentid'], $p['global_power'], $p['statistic_type'], $p['is_vip'], $p['announcement'], $p['salesid'], $p['agentid'], $p['channelid']]); } /** * 管理员给玩家充值房卡或星星 */ public function playerRecharge(&$p) { /*$sql = 'select play_roomcard as card, play_bean as star from player WHERE play_agentid = ? and play_channelid = ? and play_playerid = ? LIMIT 1;'; $user_info = $this->query($sql, [$p['agentid'], $p['channelid'], $p['userid']]);*/ // 通过游戏的接口获取实时的玩家信息 $player_data = array( 'app' => 'youle', 'route' => 'agent', 'rpc' => 'query_player2', 'data' => array( 'agentid' => $p['agentid'], 'playerid' => $p['userid'], ), ); $player_info = file_get_contents(REQUEST_USER_INFO . '?' . json_encode($player_data)); if(!$player_info) throw new \Exception('获取玩家信息错误', 1103); $player_info = json_decode($player_info, true); $user_info = $player_info['data']; if(!isset($user_info['roomcard']) || !isset($user_info['bean'])) throw new \Exception('获取玩家信息错误', 1100); // 判断是房卡还是星星 if($p['p_type'] === 1) { $before = $user_info['roomcard']; $sql = /** @lang text */'insert into ct_user_process_log( from_agent, from_channel, from_user, to_agent, to_channel, to_user, oper_type, oper_data, remark, oper_time, is_process) values ( ?, ?, ?, ?, ?, ?, 2, ?, ?, ?, ?);'; } elseif($p['p_type'] === 2) { $before = $user_info['bean']; $sql = /** @lang text */'insert into ct_user_process_log( from_agent, from_channel, from_user, to_agent, to_channel, to_user, oper_type, oper_data, remark, oper_time, is_process) values ( ?, ?, ?, ?, ?, ?, 12, ?, ?, ?, ?);'; } else { throw new \Exception('充值类型错误', 1101); } $this->beginTransaction(); try { // 插入日志 $this->query($sql, [ $p['agentid'], $p['channelid'], $p['adminid'], $p['agentid'], $p['channelid'], $p['userid'], $p['amount'], '管理员充值', time(), 0 ]); $sql = /** @lang text */'insert into ct_manager_production_info ( agent_id, channel_id, from_user, to_user, user_type, production_type, amount, before_update, after_update, oper_type, create_time, source_from, remark) values ( ?,?,1,?,?,?, ?,?,?,1,now(),?, ?);'; $this->query($sql, [$p['agentid'], $p['channelid'], $p['userid'], $p['u_type'], $p['p_type'], $p['amount'], $before, ($before + $p['amount']), $p['adminid'], '管理员充值']); $this->commit(); } catch (\Exception $e) { $this->rollBack(); throw $e; } } /** * 管理员给代理充值房卡或星星 * @param $p * @throws \Exception */ public function salesRecharge(&$p) { $sql = /** @lang text */'select user_id, saus_roomcard card, saus_bean bean, diamond from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?'; $user_info = $this->query($sql, [$p['agentid'], $p['channelid'], $p['userid']]); if(empty($user_info)) throw new \Exception('获取代理的信息错误', 1100); $this->beginTransaction(); try { /// 判断是房卡还是星星 switch ($p['p_type']) { case 1: $before = $user_info['card']; // 校验数量 if(($before + $p['amount']) < 0) throw new \Exception('数量不足', 1102); $sql = /** @lang text */'update sales_user set saus_roomcard = saus_roomcard + ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ? limit 1;'; $ret = self::$Db->pdo_execute($sql, $p['amount'], $p['agentid'], $p['channelid'], $p['userid']); if (!$ret) throw new \Exception(self::$Db->geterrorinfo(), self::$Db->geterrorcode()); if (!empty($user_info['user_id'])) { $sql = /** @lang text */'update ct_user_account set card = card + ? where user_id = ?'; $ret = self::$Db->pdo_execute($sql, $p['amount'], $user_info['user_id']); if (!$ret) throw new \Exception(self::$Db->geterrorinfo(), self::$Db->geterrorcode()); } break; case 2: $before = $user_info['bean']; // 校验数量 if(($before + $p['amount']) < 0) throw new \Exception('数量不足', 1102); $sql = /** @lang text */'update sales_user set saus_bean = saus_bean + ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ? limit 1;'; $ret = self::$Db->pdo_execute($sql, $p['amount'], $p['agentid'], $p['channelid'], $p['userid']); if (!$ret) throw new \Exception(self::$Db->geterrorinfo(), self::$Db->geterrorcode()); if (!empty($user_info['user_id'])) { $sql = /** @lang text */'update ct_user_account set currency = currency + ? where user_id = ?'; $ret = self::$Db->pdo_execute($sql, $p['amount'], $user_info['user_id']); if (!$ret) throw new \Exception(self::$Db->geterrorinfo(), self::$Db->geterrorcode()); } break; default: throw new \Exception('充值类型错误', 1101); break; } $sql = /** @lang text */<<query($sql, [$p['agentid'], $p['channelid'], $p['userid'], $p['u_type'], $p['p_type'], $p['amount'], $before, ($before + $p['amount']), $p['adminid'], '管理员充值']); $this->commit(); } catch (\Exception $e) { $this->rollBack(); throw $e; } } /** * 获取代理银行账户信息 * @param $params * @return mixed */ public function getSalesBankInfo(&$params) { $sql =/** @lang text */ 'select saus_realname, saus_wechat, saus_alipay, saus_kaihu_name, saus_kaihu_bank, saus_kaihu_zhihang, saus_kaihu_count from sales_user WHERE saus_salesid = ? and saus_agentid = ? and saus_channelid = ?;'; $result = $this->query($sql, [$params['salesid'], $params['agentid'], $params['channelid']]); return $result; } /** * 获取玩家的上级 * @param $p * @return array */ public function getPlayerParentInfo(&$p) { $sql = 'select play_playerid, play_nickname, play_invitecode from player where play_agentid=? and play_channelid=? and play_playerid=?'; $player = $this->query($sql, [$p['agentid'], $p['channelid'], $p['playerid']]); $sql = 'select saus_salesid, saus_nickname, saus_invitecode, saus_parentid, player_id from sales_user where saus_agentid=? and saus_channelid=? and player_id=?'; $sales = $this->query($sql, [$p['agentid'], $p['channelid'], $p['playerid']]); return ['playerinfo' => $player, 'salesinfo' => $sales]; } public function setPlayerParent(&$p) { if(empty($p['parentid'])) $p['parentid'] = null; $this->beginTransaction(); try { $sql = 'select idx from player where play_agentid=? and play_channelid=? and play_playerid=? limit 1'; $res = $this->query($sql, [$p['agentid'], $p['channelid'], $p['playerid']]); if(!$res) throw new \Exception('玩家表信息不存在', 1000); $sql = 'select idx from sales_user where saus_agentid=? and saus_channelid=? and player_id=? limit 1'; $res = $this->query($sql, [$p['agentid'], $p['channelid'], $p['playerid']]); if(!$res) throw new \Exception('推广员表信息不存在', 1000); $sql = 'update player set play_invitecode=? where play_agentid=? and play_channelid=? and play_playerid=? limit 1'; $this->execute($sql, [$p['parentid'], $p['agentid'], $p['channelid'], $p['playerid']]); $sql = 'update sales_user set saus_invitecode=? where saus_agentid=? and saus_channelid=? and player_id=? limit 1'; $this->execute($sql, [$p['parentid'], $p['agentid'], $p['channelid'], $p['playerid']]); $this->commit(); return true; } catch (\Exception $e) { $this->rollBack(); throw $e; } } }