biz_content) ? $inParam->biz_content : ''; if (!is_array($request_data)) { //参数格式错误 $outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agent_id = @$request_data['agentid']; $open_id = @$request_data['openid']; $player_id = @$request_data['playerid']; $amount = isset($request_data['amount']) ? intval($request_data['amount']) : 0; $channel_id = @$request_data['channelid']; $from_sales = @$request_data['fromsales']; /// 来源代理号 if (empty($agent_id)) { $outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } if (empty($open_id)) { $outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR); return false; } if (empty($player_id)) { $outParam->SetErrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR); return false; } if ($amount <= 0) { $outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR); return false; } if (empty($channel_id)) { $outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR); return false; } if (empty($from_sales)) { $sql = 'select saus_salesid from sales_user where saus_agentid = ? and saus_channelid = ? and saus_openid = ?;'; $sales_info = $this->PDO_Request($sql, $agent_id, $channel_id, $open_id); $from_sales = $sales_info[0]['saus_salesid']; //$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR); //return false; } $this->PDO_BeginTransaction(); try { $command = /** @lang text */<<PDO_Request($command, $agent_id, $channel_id, $from_sales); if (!is_array($dbSalesInfo)) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); if (count($dbSalesInfo) < 1) throw new Exception(ERRORINFO_SALESIDERROR, ERRORCODE_SALESIDERROR); if (intval($dbSalesInfo[0]['saus_status']) == 1) throw new Exception(ERRORINFO_SALESCLOSEERROR, ERRORCODE_SALESCLOSEERROR); if (intval($dbSalesInfo[0]['saus_salesman']) == 0) throw new Exception(ERRORINFO_NOTSALESERROR, ERRORCODE_NOTSALESERROR); $user_id = $dbSalesInfo[0]['user_id']; if (empty($user_id)) { if ($dbSalesInfo[0]['saus_roomcard'] < $amount) throw new Exception(ERRORINFO_ROOMCARDENOUGHERROR, ERRORCODE_ROOMCARDENOUGHERROR); } else { $user_info = $this->pdo_request(/** @lang text */'select card, enabled from ct_user_account where agent_id = ? and channel_id = ? and user_id = ?', $agent_id, $channel_id, $user_id); if (empty($user_info)) throw new Exception(ERRORINFO_SALESNOTEXISTERROR, ERRORCODE_SALESNOTEXISTERROR); if (0 == $user_info[0]['enabled']) /// 判断状态 throw new Exception(ERRORINFO_SALESCLOSEERROR, ERRORCODE_SALESCLOSEERROR); if ($user_info[0]['card'] < $amount) /// 房卡存量 throw new Exception(ERRORINFO_ROOMCARDENOUGHERROR, ERRORCODE_ROOMCARDENOUGHERROR); } $salePower = $dbSalesInfo[0]['salespower']; if (empty($salePower)) { $dbAgentInfo = $this->PDO_Request(/** @lang text */ 'select agen_salespower from agent where agen_agentid = ?;', $agent_id); if (!is_array($dbAgentInfo) || count($dbAgentInfo) < 1) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); $salePower = $dbAgentInfo[0]['agen_salespower']; } /// 这里校验用户信息的有效性 $dbPlayerInfo = $this->PDO_Request(/** @lang text */ 'select play_invitecode as playerinvitecode, play_unionid from player where play_agentid = ? and play_channelid=? and play_playerid = ?', $agent_id, $channel_id, $player_id); //if (!is_array($dbPlayerInfo)) if (!$this->PDO_IsDone()) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); elseif (empty($dbPlayerInfo)) throw new Exception(ERRORINFO_PLAYER_NOT_EXISTS, ERRORCODE_PLAYER_NOT_EXISTS); switch (intval(substr($salePower, 1, 1))) { case 0: /// 无权限 throw new Exception(ERRORINFO_NOPOWERERROR, ERRORCODE_NOPOWERERROR); break; case 1: /// 需要判断是否绑定自己 if($player_id == $dbSalesInfo[0]['player_id']) { break; } elseif ($dbPlayerInfo[0]['playerinvitecode'] != $from_sales) { $playerSalesInfo = $this->GetHelper()->PDO_Request( 'select saus_invitecode from sales_user where saus_agentid=? and saus_channelid=? and saus_unionid=?;', $agent_id, $channel_id, $dbPlayerInfo[0]['play_unionid']); if (!is_array($playerSalesInfo) || count($playerSalesInfo) < 1) throw new Exception(ERRORINFO_ONLYBINDSELFERROR, ERRORCODE_ONLYBINDSELFERROR); if ($playerSalesInfo[0]['saus_invitecode'] != $from_sales) throw new Exception(ERRORINFO_ONLYBINDSELFERROR, ERRORCODE_ONLYBINDSELFERROR); } break; case 2: /// 可以给所有玩家转卡 break; default: throw new Exception(ERRORINFO_NOPOWERERROR, ERRORCODE_NOPOWERERROR); break; } /// 加入充卡记录 $ret = $this->PDO_Execute(/** @lang text */ 'insert into sales_sellbill(sase_agentid, sase_openid, sase_playerid, sase_amount, sase_selltime, channel_id, from_sales) values(?, ?, ?, ?, ?, ?, ?);', $agent_id, $open_id, $player_id, $amount, date('Y-m-d H:i:s', time()), $channel_id, $from_sales); if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); /// 当传入了用户id的时候,则需要更新用户账户表中的数据 if (!empty($user_id)) { $ret = $this->PDO_Execute(/** @lang text */ 'update ct_user_account set card = card - ? where agent_id = ? and channel_id = ? and user_id = ?', $amount, $agent_id, $channel_id, $user_id); if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); /// 如果当前代理子账户余额不足,则扣除绑定的其他子账户中的房卡 if ($dbSalesInfo[0]['saus_roomcard'] < $amount) { /// 更新代理信息表 $ret = $this->PDO_Execute(/** @lang text */ 'update sales_user set saus_roomcard = 0 where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;', $agent_id, $channel_id, $from_sales); if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); /// 扣除掉其他绑定了同一个账号的子代理账号 $need_amount = $amount - $dbSalesInfo[0]['saus_roomcard']; $command = /** @lang text */<<pdo_execute($command, $agent_id, $channel_id, $user_id)) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); } else { /// 更新代理信息表 $ret = $this->PDO_Execute(/** @lang text */ 'update sales_user set saus_roomcard = saus_roomcard - ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;', $amount, $agent_id, $channel_id, $from_sales); if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); } } else { /// 更新代理信息表 $ret = $this->PDO_Execute(/** @lang text */ 'update sales_user set saus_roomcard = saus_roomcard - ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;', $amount, $agent_id, $channel_id, $from_sales); if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); } /// 记录日志 $log_res = $this->PDO_Execute(/** @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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $agent_id, $channel_id, $from_sales, $agent_id, $channel_id, $player_id, 2, $amount, '', time(), 0); if (!$log_res) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); $this->PDO_Commit(); } catch(Exception $e) { $this->PDO_Rollback(); $outParam->SetErrors($e->GetCode(), $e->GetMessage()); return false; } $outParam->biz_content = array( 'state' => 0, 'roomcard' => ($dbSalesInfo[0]['saus_roomcard'] - $amount), 'amount' => $amount, 'playerid' => $player_id, 'playername' => $player_id, 'playerroomcard' => 0, ); return true; } /** * 获取充卡名单 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $inParam * @param ReturnParameter $outParam * @return bool */ public function addList($inParam, $outParam) { $request_data = isset($inParam->biz_content) ? $inParam->biz_content : ''; if (!is_array($request_data)) { //参数格式错误 $outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agentID = isset($request_data['agentid']) ? $request_data['agentid'] : ''; if (empty($agentID)) { $outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } $openID = isset($request_data['openid']) ? $request_data['openid'] : ''; if (empty($openID)) { $outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR); return false; } $addList = $this->PDO_Request( 'call cp_sales_get_topupname(?,?);', $agentID, $openID ); if (!is_array($addList) || count($addList) < 1) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $outParam->biz_content = array( 'state' => 0, 'players' => $addList, ); return true; } /** * 代理后台查询给玩家的充卡记录 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $inParam * @param ReturnParameter $outParam * @return bool */ public function addRecord($inParam, $outParam) { $request_data = isset($inParam->biz_content) ? $inParam->biz_content : ''; if (!is_array($request_data)) { //参数格式错误 $outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agent_id = isset($request_data['agentid']) ? $request_data['agentid'] : ''; $channel_id = isset($request_data['channelid']) ? $request_data['channelid'] : ''; //$open_id = isset($request_data['openid']) ? $request_data['openid'] : ''; $begin_time = isset($request_data['begintime']) ? $request_data['begintime'] : ''; $end_time = isset($request_data['endtime']) ? $request_data['endtime'] : ''; $page_index = empty($request_data['page_index']) ? 1 : intval($request_data['page_index']); $page_size = empty($request_data['page_size']) ? 10 : intval($request_data['page_size']); $sales_id = @$request_data['salesid']; /// 代理号 $user_id = @$request_data['userid']; /// 用户编号(新用户表,绑定手机后自动生成。) if (empty($agent_id)) { $outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } if ($begin_time > $end_time) { $outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR); return false; } if (empty($user_id)) /// 如果没有userid,则按原方式获取记录 { $str_time = ''; $array_param = array($agent_id, $channel_id, $sales_id, ); if (!empty($begin_time)) { $str_time .= ' and date_format(a.sase_selltime, \'%Y-%m-%d\') >= ? '; $array_param[] = $begin_time; } if (!empty($end_time)) { $str_time .= ' and date_format(a.sase_selltime, \'%Y-%m-%d\') <= ? '; $array_param[] = $end_time; } $start = ($page_index - 1) * $page_size; $strPage = ''; if (!empty($request_data['page_index'])) { $strPage .= " limit {$start},{$page_size} "; } /// 转卡流水 $command = /** @lang text */<<PDO_Request($command, $array_param); if (!$this->pdo_isdone()) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $page_count = 1; if (!empty($request_data['page_index'])) { /// 流水总条数 $command = /** @lang text */<<PDO_Request($command, $array_param); if (!$this->pdo_isdone() || count($dbData) < 1) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $page_count = intval($dbData[0]['num']) / $page_size + 1; } } else { $str_time = ''; $array_param = array($agent_id, $channel_id, $user_id, ); if (!empty($begin_time)) { $str_time .= ' and date_format(a.sase_selltime, \'%Y-%m-%d\') >= ? '; $array_param[] = $begin_time; } if (!empty($end_time)) { $str_time .= ' and date_format(a.sase_selltime, \'%Y-%m-%d\') <= ? '; $array_param[] = $end_time; } $start = ($page_index - 1) * $page_size; $strPage = ''; if (!empty($request_data['page_index'])) { $strPage .= " limit {$start},{$page_size} "; } $command = /** @lang text */<<PDO_Request($command, $array_param); if (!$this->pdo_isdone()) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $page_count = 1; if (!empty($request_data['page_index'])) { $command = /** @lang text */<<PDO_Request($command, $array_param); if (!$this->pdo_isdone() || count($dbData) < 1) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $page_count = intval($dbData[0]['num']) / $page_size + 1; } } $outParam->biz_content = array( 'detail' => $record, 'page_index' => $page_index, 'page_size' => $page_size, 'page_count' => $page_count, ); return true; } /** * 获取购卡记录 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $inParam * @param ReturnParameter $outParam * @return bool */ public function buyCardRecord($inParam, $outParam) { $request_data = isset($inParam->biz_content) ? $inParam->biz_content : ''; if (!is_array($request_data)) { //参数格式错误 $outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agentID = isset($request_data['agentid']) ? $request_data['agentid'] : ''; if (empty($agentID)) { $outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } $openID = isset($request_data['openid']) ? $request_data['openid'] : ''; if (empty($openID)) { /*$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR); return false;*/ } $str_time = ''; $array_param = array( $agentID, $openID, ); $beginTime = isset($request_data['begintime']) ? $request_data['begintime'] : ''; if (!empty($beginTime)) { $str_time .= ' and date_format(sabu_paytime, \'%Y-%m-%d\') >= ? '; $array_param[] = $beginTime; } $endTime = isset($request_data['endtime']) ? $request_data['endtime'] : ''; if (!empty($endTime)) { $str_time .= ' and date_format(sabu_paytime, \'%Y-%m-%d\') <= ? '; $array_param[] = $endTime; } if ($beginTime > $endTime) { $outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR); return false; } // 查询类型 0-玩家购买 1-代理购买 $type = isset($request_data['type']) ? $request_data['type'] : 0; if($type == 1) { $record = $this->PDO_Request(/** @lang text */ "select date_format(sabu_paytime, '%Y-%m-%d %H:%i') as time, sabu_paymoney as money, sabu_amount as amount from sales_buybill where sabu_agentid = ? and sabu_openid = ? and sabu_billtype = 1 and sabu_paystate = 1 {$str_time} order by time desc limit 50;", $array_param); } else { $record = $this->PDO_Request(/** @lang text */ "select date_format(sabu_paytime, '%Y-%m-%d %H:%i') as time, sabu_playerid as playerid, sabu_paymoney as money, sabu_amount as amount from sales_buybill where sabu_agentid = ? and sabu_openid = ? and sabu_billtype = 0 and sabu_paystate = 1 {$str_time} order by time desc limit 50;", $array_param); } if (!is_array($record)) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $outParam->biz_content = array('detail' => $record); return true; } /** * 给个人代理转卡 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $inParam * @param ReturnParameter $outParam * @return bool */ public function transCard($inParam, $outParam) { $request_data = isset($inParam->biz_content) ? $inParam->biz_content : ''; if (!is_array($request_data)) { //参数格式错误 $outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agent_id = isset($request_data['agentid']) ? $request_data['agentid'] : ''; $channel_id = isset($request_data['channelid']) ? $request_data['channelid'] : ''; $open_id = isset($request_data['openid']) ? $request_data['openid'] : ''; $sales_id = isset($request_data['salesid']) ? $request_data['salesid'] : ''; $amount = isset($request_data['amount']) ? intval($request_data['amount']) : 0; $from_sales = @$request_data['fromsales']; /// 来源代理号 if (empty($agent_id)) { $outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } if (empty($channel_id)) { $outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR); return false; } if (empty($sales_id)) { $outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR); return false; } if (empty($amount)) { $outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR); return false; } if (empty($from_sales)) { $sql = /** @lang text */'select saus_salesid from sales_user where saus_agentid = ? and saus_channelid = ? and saus_openid = ?;'; $sales_info = $this->PDO_Request($sql, $agent_id, $channel_id, $open_id); $from_sales = $sales_info[0]['saus_salesid']; //$outParam->SetErrors($from_sales, ERRORINFO_SALESIDERROR); //return false; } $this->PDO_BeginTransaction(); try { //$dbAgentInfo = $this->PDO_Request(/** @lang text */ // 'select agen_salespower as agentsalespower from agent where agen_agentid = ?;', $agent_id); $dbAgentInfo = $this->PDO_Request(/** @lang text */ 'select default_sales_power as agentsalespower from ct_agent_list where agent_id = ?;', $agent_id); if (!is_array($dbAgentInfo) || count($dbAgentInfo) < 1) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); $command = /** @lang text */<<PDO_Request($command, $agent_id, $channel_id, $from_sales); if (!is_array($dbSalesInfo) || count($dbSalesInfo) < 1) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); if (intval($dbSalesInfo[0]['saus_status']) == 1) throw new Exception(ERRORINFO_SALESCLOSEERROR, ERRORCODE_SALESCLOSEERROR); if (intval($dbSalesInfo[0]['saus_salesman']) == 0) throw new Exception(ERRORINFO_NOTSALESERROR, ERRORCODE_NOTSALESERROR); $user_id = $dbSalesInfo[0]['user_id']; if (empty($user_id)) { if (intval($dbSalesInfo[0]['roomcard']) < $amount) throw new Exception(ERRORINFO_AMOUNTERROR, ERRORCODE_AMOUNTERROR); $room_card = $dbSalesInfo[0]['roomcard']; } else { $user_info = $this->pdo_request(/** @lang text */ 'select card, enabled from ct_user_account where agent_id = ? and channel_id = ? and user_id = ?', $agent_id, $channel_id, $user_id); if (empty($user_info)) throw new Exception(ERRORINFO_SALESNOTEXISTERROR, ERRORCODE_SALESNOTEXISTERROR); if (0 == $user_info[0]['enabled']) /// 判断状态 throw new Exception(ERRORINFO_SALESCLOSEERROR, ERRORCODE_SALESCLOSEERROR); if ($user_info[0]['card'] < $amount) /// 房卡存量 throw new Exception(ERRORINFO_AMOUNTERROR, ERRORCODE_AMOUNTERROR); $room_card = $user_info[0]['card']; } /// 要转到的代理信息 $to_sales = $this->pdo_request(/** @lang text */ 'select idx, user_id, saus_salesid, saus_nickname, saus_roomcard, saus_invitecode, saus_parentid from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?', $agent_id, $channel_id, $sales_id ); if (!$this->pdo_isdone()) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); if (empty($to_sales)) throw new Exception(ERRORINFO_INVITECODE_NOT_EXISTS, ERRORCODE_INVITECODE_NOT_EXISTS); else $to_sales = $to_sales[0]; $salePower = $dbSalesInfo[0]['salespower']; if (empty($salePower)) { //$dbAgentInfo = $this->PDO_Request(/** @lang text */'select agen_salespower from agent where agen_agentid = ?;', $agent_id); $dbAgentInfo = $this->PDO_Request(/** @lang text */'select default_sales_power as agen_salespower from ct_agent_list where agent_id = ?;', $agent_id); if (!is_array($dbAgentInfo) || count($dbAgentInfo) < 1) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); $salePower = $dbAgentInfo[0]['agen_salespower']; } switch (intval(substr($salePower, 0, 1))) { case 0: /// 无权限 throw new Exception(ERRORINFO_NOPOWERERROR, ERRORCODE_NOPOWERERROR); break; case 1: /// 需要判断是否绑定自己 if ($to_sales['saus_parentid'] != $from_sales) throw new Exception(ERRORINFO_ONLYBINDSELFERROR, ERRORCODE_ONLYBINDSELFERROR); break; case 2: /// 可以给所有代理转卡 break; default: throw new Exception(ERRORINFO_NOPOWERERROR, ERRORCODE_NOPOWERERROR); break; } /// 加入转卡记录 $ret = $this->PDO_Execute(/** @lang text */ 'insert into sales_transferbill(satr_agentid,satr_openid,channel_id,from_sales,satr_salesid,satr_amount,satr_transfertime) values(?, ?, ?, ?, ?, ?, now());', $agent_id, $open_id, $channel_id, $from_sales, $sales_id, $amount); if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); /// 当传入了用户id的时候,则需要更新用户账户表中的数据 if (!empty($user_id)) { /// 多判断一次数量是否足够 $ret = $this->pdo_request(/** @lang text */ 'select card from ct_user_account where agent_id = ? and channel_id = ? and user_id = ?', $agent_id, $channel_id, $user_id); if (!$this->pdo_isdone()) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); if ($ret[0]['card'] < $amount) throw new Exception(ERRORINFO_AMOUNTERROR, ERRORCODE_AMOUNTERROR); $ret = $this->PDO_Execute(/** @lang text */ 'update ct_user_account set card = card - ? where agent_id = ? and channel_id = ? and user_id = ?', $amount, $agent_id, $channel_id, $user_id); if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); /// 如果当前代理子账户余额不足,则扣除绑定的其他子账户中的房卡 if ($dbSalesInfo[0]['roomcard'] < $amount) { /// 更新代理信息表 $ret = $this->PDO_Execute(/** @lang text */ 'update sales_user set saus_roomcard = 0 where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;', $agent_id, $channel_id, $from_sales); if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); /// 扣除掉其他绑定了同一个账号的子代理账号 $need_amount = $amount - $dbSalesInfo[0]['roomcard']; $command = /** @lang text */<<pdo_execute($command, $agent_id, $channel_id, $user_id)) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); } else { /// 更新代理信息表 $ret = $this->PDO_Execute(/** @lang text */ 'update sales_user set saus_roomcard = saus_roomcard - ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;', $amount, $agent_id, $channel_id, $from_sales); if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); } } else { /// 多判断一次数量是否足够 $ret = $this->pdo_request(/** @lang text */ 'select saus_roomcard card from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?', $agent_id, $channel_id, $from_sales); if (!$this->pdo_isdone()) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); if ($ret[0]['card'] < $amount) throw new Exception(ERRORINFO_AMOUNTERROR, ERRORCODE_AMOUNTERROR); /// 更新代理信息表 $ret = $this->PDO_Execute(/** @lang text */ 'update sales_user set saus_roomcard = saus_roomcard - ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;', $amount, $agent_id, $channel_id, $from_sales); if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); } /// 更新转到的代理信息表 if (empty($to_sales['user_id'])) { $command = /** @lang text */<<pdo_execute($command, $amount, $to_sales['idx']); } else { $command = /** @lang text */<<pdo_execute($command, $amount, $amount, $to_sales['idx']); } if (!$ret) throw new Exception($this->GetErrorInfo(), $this->GetErrorCode()); $this->PDO_Commit(); } catch (Exception $e) { $this->PDO_Rollback(); $outParam->SetErrors($e->GetCode(), $e->GetMessage()); return false; } $outParam->biz_content = array( 'state' => 0, 'roomcard' => $room_card - $amount, 'amount' => $amount, 'salesid' => $to_sales['saus_salesid'], 'salesname' => $to_sales['saus_nickname'], 'salesroomcard' => $to_sales['saus_roomcard'] + $amount, ); return true; } /** * 获取转卡名单 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $inParam * @param ReturnParameter $outParam * @return bool */ public function transList($inParam, $outParam) { $request_data = isset($inParam->biz_content) ? $inParam->biz_content : ''; if (!is_array($request_data)) { //参数格式错误 $outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agentID = isset($request_data['agentid']) ? $request_data['agentid'] : ''; if (empty($agentID)) { $outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } $openID = isset($request_data['openid']) ? $request_data['openid'] : ''; if (empty($openID)) { $outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR); return false; } $db_data = $this->PDO_Request( 'call cp_sales_get_transfername(?,?);', $agentID, $openID ); if (!is_array($db_data)) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $outParam->biz_content = array( 'state' => 0, 'salesman' => $db_data, ); return true; } /** * 获取转卡记录 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $inParam * @param ReturnParameter $outParam * @return bool */ public function transRecord($inParam, $outParam) { $request_data = isset($inParam->biz_content) ? $inParam->biz_content : ''; if (!is_array($request_data)) { //参数格式错误 $outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agent_id = isset($request_data['agentid']) ? $request_data['agentid'] : ''; //$open_id = isset($request_data['openid']) ? $request_data['openid'] : ''; $begin_time = isset($request_data['begintime']) ? $request_data['begintime'] : ''; $end_time = isset($request_data['endtime']) ? $request_data['endtime'] : ''; $page_index = empty($request_data['page_index']) ? 1 : intval($request_data['page_index']); $page_size = empty($request_data['page_size']) ? 10 : intval($request_data['page_size']); $from_sales = @$request_data['fromsales']; /// 来源代理号 $user_id = @$request_data['userid']; /// 用户编号(新用户表,绑定手机后自动生成。) if (empty($agent_id)) { $outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } if ($begin_time > $end_time) { $outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR); return false; } if (true /*empty($user_id)*/) { $str_time = ''; $array_param = array($agent_id, $from_sales, ); if (!empty($begin_time)) { $str_time .= ' and date_format(a.satr_transfertime, \'%Y-%m-%d\') >= ? '; $array_param[] = $begin_time; } if (!empty($end_time)) { $str_time .= ' and date_format(a.satr_transfertime, \'%Y-%m-%d\') <= ? '; $array_param[] = $end_time; } $start = ($page_index - 1) * $page_size; $strPage = ''; if (!empty($request_data['page_index'])) $strPage .= " limit {$start},{$page_size} "; $command = /** @lang text */<<PDO_Request($command, $array_param); if (!$this->PDO_IsDone()) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $page_count = 1; if (!empty($request_data['page_index'])) { $command = /** @lang text */<<PDO_Request($command, $array_param); if (!is_array($dbCount) || count($dbCount) < 1) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $page_count = intval($dbCount[0]['num']) / $page_size + 1; } } else { $str_time = ''; $array_param = array($agent_id, $user_id, ); if (!empty($begin_time)) { $str_time .= ' and date_format(a.satr_transfertime, \'%Y-%m-%d\') >= ? '; $array_param[] = $begin_time; } if (!empty($end_time)) { $str_time .= ' and date_format(a.satr_transfertime, \'%Y-%m-%d\') <= ? '; $array_param[] = $end_time; } $start = ($page_index - 1) * $page_size; $strPage = ''; if (!empty($request_data['page_index'])) $strPage .= " limit {$start},{$page_size} "; $command = /** @lang text */<<PDO_Request($command, $array_param); if (!$this->PDO_IsDone()) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $page_count = 1; if (!empty($request_data['page_index'])) { $command = /** @lang text */<<PDO_Request($command, $array_param); if (!is_array($dbCount) || count($dbCount) < 1) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $page_count = intval($dbCount[0]['num']) / $page_size + 1; } } $outParam->biz_content = array( 'detail' => $db_data, 'page_index' => $page_index, 'page_size' => $page_size, 'page_count' => $page_count, ); return true; } /** * 个人代理间的转卡记录 * @param RequestParameter $inParam * @param ReturnParameter $outParam * @return bool */ public function getTransRecord($inParam, $outParam) { $request_data = isset($inParam->biz_content) ? $inParam->biz_content : ''; if (!is_array($request_data)) { //参数格式错误 $outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agentID = isset($request_data['agentid']) ? $request_data['agentid'] : ''; if (empty($agentID)) { $outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } $salesID = isset($request_data['salesid']) ? $request_data['salesid'] : ''; if (empty($salesID)) { $outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR); return false; } $str_time = ''; $array_param = array( $agentID, $salesID, ); $beginTime = isset($request_data['begintime']) ? $request_data['begintime'] : ''; if (!empty($beginTime)) { $str_time .= ' and date_format(saab_asktime, \'%Y-%m-%d\') >= ? '; //$array_param[] = $beginTime; } $endTime = isset($request_data['endtime']) ? $request_data['endtime'] : ''; if (!empty($endTime)) { $str_time .= ' and date_format(saab_asktime, \'%Y-%m-%d\') <= ? '; //$array_param[] = $endTime; } if ($beginTime > $endTime) { $outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR); return false; } $command = /** @lang text */ " SELECT date_format(saab_asktime, '%Y-%m-%d %H:%i') as time, saab_askid as salesid, saab_asknickname as name, saab_askavatar as avatar, saab_amount as amount FROM sales_ask_bill WHERE saab_agentid = ? and saab_salesid = ? and saab_state = 1 and saab_type = 1{$str_time} ORDER BY saab_asktime desc"; $db_data = $this->PDO_Request($command, $array_param); if (!is_array($db_data)) { $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo()); return false; } $outParam->biz_content = array('detail' => $db_data); return true; } }