biz_content; if (!is_array($param)) { /// 参数格式错误 $return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } //{"agentid":"i33v0llvp0euhd1n9qo1fM2RV8vtog4y","channelid":"7N0e0z2u2098pf1M2fj0kyB1D4n4ylkA","accountperiod":"201801","freecard":"0","freegold":"0","pricecard":"1","pricegold":"1","loginid":"test"} $agent_id = @$param['agentid']; /// 代理id $channel_id = @$param['channelid']; /// 渠道id $account_period = @$param['accountperiod']; /// 账期(yyyymm) $account_period = str_replace('-', '',$account_period); $free_card = floatval(@$param['freecard']); /// 免费、赠送房卡数 $free_gold = floatval(@$param['freegold']); /// 免费、赠送金币数 $price_card = floatval(@$param['pricecard']); /// 房卡单价 $price_gold = floatval(@$param['pricegold']); /// 金币单价 $login_id = @$param['loginid']; /// 登录账号 if (empty($agent_id)) { $return->seterrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } if (empty($channel_id)) { $return->seterrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR); return false; } if (empty($account_period)) { $return->seterrors(ERRORCODE_ACCOUNTPERIODERROR, ERRORINFO_ACCOUNTPERIODERROR); return false; } /// 判断所属账期是否已支付过 $cmd = /** @lang text */ <<pdo_request($cmd, $agent_id, $channel_id, $account_period); if (!$this->pdo_isdone()) { $return->seterrors($this->geterrorcode(), $this->geterrorinfo() . '(' . __LINE__ . ')'); return false; } if (!empty($ret) && !empty($ret[0]['order_list'])) { $return->seterrors(ERRORCODE_ACCOUNTPERIODEXISTS, sprintf(ERRORINFO_ACCOUNTPERIODEXISTS, $ret[0]['order_list'])); return false; } $this->pdo_begintransaction(); try { /// 尝试删除已存在的账期数据 $cmd = /** @lang text */'delete from ct_channel_account_period where agent_id = ? and channel_id = ? and account_period = ?'; $ret = $this->pdo_execute($cmd, $agent_id, $channel_id, $account_period); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $cmd = /** @lang text */'delete from ct_channel_account_period_online where agent_id = ? and channel_id = ? and account_period = ?'; $ret = $this->pdo_execute($cmd, $agent_id, $channel_id, $account_period); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $card = 0; /// 房卡数 $gold = 0; /// 金币数 /// 计算总计转出到代理的房卡数 $cmd = /** @lang text */<<pdo_request($cmd, $agent_id, $channel_id, $account_period); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $card += floatval(@$ret[0]['amount']); /// 计算总计转出到玩家的房卡数 $cmd = /** @lang text */<<pdo_request($cmd, $agent_id, $channel_id, $account_period); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $card += floatval(@$ret[0]['amount']); /// 计算总计转出到代理的金币数 $cmd = /** @lang text */<<pdo_request($cmd, $agent_id, $channel_id, $account_period); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $gold += floatval(@$ret[0]['amount']); /// 计算总计转出到玩家的金币数 $cmd = /** @lang text */<<pdo_request($cmd, $agent_id, $channel_id, $account_period); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $gold += floatval(@$ret[0]['amount']); /// 计算索要订单 $cmd = /** @lang text */<<pdo_request($cmd, $agent_id, $channel_id, $account_period); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $card += floatval($ret[0]['card']); $gold += floatval($ret[0]['gold']); if ($free_card > $card) throw new Exception(sprintf(ERRORINFO_INVALIDCARDAMOUNT, $card, $free_card), ERRORCODE_INVALIDCARDAMOUNT); if ($free_gold > $gold) throw new Exception(sprintf(ERRORINFO_INVALIDGOLDAMOUNT, $gold, $free_gold), ERRORCODE_INVALIDGOLDAMOUNT); /// 获取渠道分成数据 $cmd = /** @lang text */'select (1 - proportions) proportions from ct_channel_list where agent_id = ? and channel_id = ?'; $ret = $this->pdo_request($cmd, $agent_id, $channel_id); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); elseif (empty($ret)) throw new Exception(ERRORINFO_AGENTNOTEXISTERROR, ERRORCODE_AGENTNOTEXISTERROR); $proportions = $ret[0]['proportions']; /// 分成百分比 $total = (($card - $free_card) * $price_card) + (($gold - $free_gold) * $price_gold); /// 总数 /// 新增账期数据 $cmd = /** @lang text */<<pdo_execute($cmd, $agent_id, $channel_id, $account_period, $account_period, $account_period, $card, $gold, $free_card, $free_gold, $price_card, $price_gold, $total, $total * $proportions, $total * $proportions); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $card = 0; $gold = 0; $total = 0; // /// 在线购买的房卡 // $cmd = /** @lang text */<<pdo_request($cmd, $agent_id, $channel_id, $account_period); // if (!$this->pdo_isdone()) // throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); // $card += $ret[0]['card_amount']; // $total += $ret[0]['card_money']; // // /// 在线购买的金币 // $cmd = /** @lang text */<<pdo_request($cmd, $agent_id, $channel_id, $account_period); // if (!$this->pdo_isdone()) // throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); // $gold += $ret[0]['gold_amount']; // $total += $ret[0]['gold_money']; /// 购买的房卡和金币数 $cmd = /** @lang text */<<pdo_request($cmd, $agent_id, $channel_id, $account_period); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $card += $ret[0]['card_amount']; $total += $ret[0]['card_money']; $gold += $ret[0]['gold_amount']; $total += $ret[0]['gold_money']; /// 第三方代付的房卡和金币 $cmd = /** @lang text */<<pdo_request($cmd, $agent_id, $channel_id, $account_period); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $card += $ret[0]['card_amount']; $total += $ret[0]['card_money']; $gold += $ret[0]['gold_amount']; $total += $ret[0]['gold_money']; /// 新增账期数据(在线支付) $cmd = /** @lang text */<<pdo_execute($cmd, $agent_id, $channel_id, $account_period, $account_period, $account_period, $card, $gold, $total, $total * $proportions, $total * $proportions); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); /// 保存操作流水 $cmd = /** @lang text */<<pdo_execute($cmd, $agent_id, $channel_id, $account_period, $free_card, $free_gold, $price_card, $price_gold, $login_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $this->pdo_commit(); } catch (Exception $Exception) { $this->pdo_rollback(); $return->seterrors($Exception->getcode(), $Exception->getmessage()); return false; } return true; } /** * @note 渠道付款 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $request * @param ReturnParameter $return * @return bool */ public function account_period_pay($request, $return) { // http://localhost/game_proxy/trunk/api/index.php?method=finance.finance.account_period_pay&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"i33v0llvp0euhd1n9qo1fM2RV8vtog4y","channelid":"7N0e0z2u2098pf1M2fj0kyB1D4n4ylkA","fee":"100","fee_online":"10","loginid":"test","accountperiod":"201803"}&user_auth_token=xxxxxxxx&tag=tag&random_string=xxxxxx $param = (array)$request->biz_content; if (!is_array($param)) { /// 参数格式错误 $return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agent_id = @$param['agentid']; /// 代理id $channel_id = @$param['channelid']; /// 渠道id $fee = floatval(@$param['fee']); /// 金额(渠道转款) $fee_online = floatval(@$param['fee_online']); /// 支付金额(线上支付,公众号等) $login_id = @$param['loginid']; /// 登录账号 $account_period = @$param['accountperiod']; /// 账期(yyyymm) if (empty($agent_id)) { $return->seterrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } if (empty($channel_id)) { $return->seterrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR); return false; } if ($fee < 0 || $fee_online < 0) { $return->seterrors(ERRORCODE_MONEYERROR, ERRORINFO_MONEYERROR); return false; } if (empty($account_period)) $account_period = date('Ym'); else $account_period = str_replace('-', '', $account_period); $this->pdo_begintransaction(); try { /// 获取当前账户余额 $cmd = /** @lang text */'select account, account_online from ct_channel_list where agent_id = ? and channel_id = ?'; $ret = $this->pdo_request($cmd, $agent_id, $channel_id); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); elseif (empty($ret)) throw new Exception(ERRORINFO_AGENTNOTEXISTERROR, ERRORCODE_AGENTNOTEXISTERROR); $account = floatval($ret[0]['account']); $account_online = floatval($ret[0]['account_online']); $total = $account + $fee; /// 转账的总金额 $total_online = $account_online + $fee_online; /// 在线支付的总金额 /// 创建支付订单号 do { $order_id = date('YmdHis') . rand(100000, 999999); $cmd = /** @lang text */'select 1 from ct_channel_pay_log where order_id = ?'; $ret = $this->pdo_request($cmd, $order_id); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); elseif (empty($ret)) break; } while (1); /// 新增支付流水记录 $cmd = /** @lang text */<<pdo_execute($cmd, $order_id, $agent_id, $channel_id, $account_period, $fee, $fee_online, $login_id, $account, $total, $account_online, $total_online); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $pay_log_id = $this->pdo_lastinsertid(); /// 支付流水id /// ======================================================================================================== /// 转房卡、金币的支付情况 $base = /** @lang text */<< 0, @realpay := 0.0000, @realpay := {$fee} * 1.0000) realpay, -- 本期实际付款 if(@line > 0, @carryover := 0.0000, @carryover := {$account} * 1.0000) carryover, -- 上期结转余额 @total_fee - @pay_count total_fee, -- 累计付款额(本期实付 + 上期结转) if (a.receivable + @pay_count < @total_fee, @pay_fee := a.receivable, @pay_fee := @total_fee - @pay_count) pay_fee, -- 本期实际冲抵额 if (a.receivable + @pay_count < @total_fee, @pay_count := @pay_count + a.receivable, @pay_count := @total_fee) pay_count, -- 累计冲抵额 a.receivable - @pay_fee pay_receivable, -- 还应支付余额 @total_fee - @pay_count pay_surplus, -- 支付后剩余的可用金额 @line := @line + 1 rownum -- 行号 from (select id, agent_id, channel_id, account_period, receivable from ct_channel_account_period where receivable > 0 order by account_period) a, (select @pay_fee := 0.0000) b, (select @pay_count := 0.0000) c, (select @total_fee := {$total} * 1.0000) d, (select @line := 0.0000) e where a.agent_id = ? and a.channel_id = ? EOL; /// 判断是否存在需要冲抵的账目 $cmd = $base; $ret = $this->pdo_request($cmd, $agent_id, $channel_id); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); elseif (!empty($ret)) /// 存在需要冲抵的账目 { /// 最后的账户余额 $last_account = $ret[count($ret) - 1]['pay_surplus']; /// 新增渠道帐期支付流水 $cmd = /** @lang text */<< 0 EOL; $ret = $this->pdo_execute($cmd, $agent_id, $channel_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); /// 修改账期数据 $cmd = /** @lang text */<<pdo_execute($cmd, $agent_id, $channel_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); /// 更新账户余额 $cmd = /** @lang text */'update ct_channel_list set account = ? where agent_id = ? and channel_id = ?'; $ret = $this->pdo_execute($cmd, $last_account, $agent_id, $channel_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); /// 更新支付流水信息里的支付后账户余额 $cmd = /** @lang text */'update ct_channel_pay_log set account_after = ? where id = ?'; $ret = $this->pdo_execute($cmd, $last_account, $pay_log_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); } else /// 不存在需要冲抵的账目 { /// 最后的账户余额 $last_account = $total; /// 更新账户余额 $cmd = /** @lang text */'update ct_channel_list set account = ? where agent_id = ? and channel_id = ?'; $ret = $this->pdo_execute($cmd, $last_account, $agent_id, $channel_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); } /// ======================================================================================================== /// 购买房卡、金币的支付情况 $base = /** @lang text */<< 0, @realpay := 0.0000, @realpay := {$fee_online} * 1.0000) realpay, -- 本期实际付款 if(@line > 0, @carryover := 0.0000, @carryover := {$account_online} * 1.0000) carryover, -- 上期结转余额 @total_fee - @pay_count total_fee, -- 累计付款额(本期实付 + 上期结转) if (a.receivable + @pay_count < @total_fee, @pay_fee := a.receivable, @pay_fee := @total_fee - @pay_count) pay_fee, -- 本期实际冲抵额 if (a.receivable + @pay_count < @total_fee, @pay_count := @pay_count + a.receivable, @pay_count := @total_fee) pay_count, -- 累计冲抵额 a.receivable - @pay_fee pay_receivable, -- 还应支付余额 @total_fee - @pay_count pay_surplus, -- 支付后剩余的可用金额 @line := @line + 1 rownum -- 行号 from (select id, agent_id, channel_id, account_period, receivable from ct_channel_account_period_online where receivable > 0 order by account_period) a, (select @pay_fee := 0.0000) b, (select @pay_count := 0.0000) c, (select @total_fee := {$total_online} * 1.0000) d, (select @line := 0.0000) e where a.agent_id = ? and a.channel_id = ? EOL; /// 判断是否存在需要冲抵的账目 $cmd = $base; $ret = $this->pdo_request($cmd, $agent_id, $channel_id); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); elseif (!empty($ret)) /// 存在需要冲抵的账目 { /// 最后的账户余额 $last_account = $ret[count($ret) - 1]['pay_surplus']; /// 新增渠道帐期支付流水 $cmd = /** @lang text */<< 0 EOL; $ret = $this->pdo_execute($cmd, $agent_id, $channel_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); /// 修改账期数据 $cmd = /** @lang text */<<pdo_execute($cmd, $agent_id, $channel_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); /// 更新账户余额 $cmd = /** @lang text */'update ct_channel_list set account_online = ? where agent_id = ? and channel_id = ?'; $ret = $this->pdo_execute($cmd, $last_account, $agent_id, $channel_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); /// 更新支付流水信息里的支付后账户余额 $cmd = /** @lang text */'update ct_channel_pay_log set account_online_after = ? where id = ?'; $ret = $this->pdo_execute($cmd, $last_account, $pay_log_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); } else /// 不存在需要冲抵的账目 { /// 最后的账户余额 $last_account = $total; /// 更新账户余额 $cmd = /** @lang text */'update ct_channel_list set account_online = ? where agent_id = ? and channel_id = ?'; $ret = $this->pdo_execute($cmd, $last_account, $agent_id, $channel_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); } $this->pdo_commit(); } catch (Exception $Exception) { $this->pdo_rollback(); $return->seterrors($Exception->getcode(), $Exception->getmessage()); return false; } $return->biz_content = array('orderid' => $order_id); return true; } /** * @note 渠道付款记录 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $request * @param ReturnParameter $return * @return bool */ public function account_period_pay_record($request, $return) { $params = $request->biz_content; // 查看那一页 $page = isset($params['page']) ? intval($params['page']) : 1; // 分页多少条 $limit = isset($params['limit']) ? intval($params['limit']) : 10; $limit_index = ($page - 1) * $limit; $sql = <<pdo_request($sql, $limit_index, $limit); if (!$this->pdo_isdone()) { $return->seterrors($this->geterrorcode(), $this->geterrorinfo() . '(' . __LINE__ . ')'); return false; } $data = []; if(is_array($items) && isset($items[0])) { $data['title'] = array_keys($items[0]); foreach ($items as $k => $v) { foreach ($v as $q) { $data['data'][$k][] = $q; } } } // 5、数据返回部分 $return->biz_content = $data; return true; } /** * @note 撤销渠道付款 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $request * @param ReturnParameter $return * @return bool */ public function account_period_cancel($request, $return) { // http://localhost/game_proxy/trunk/api/index.php?method=finance.finance.account_period_cancel&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"i33v0llvp0euhd1n9qo1fM2RV8vtog4y","channelid":"7N0e0z2u2098pf1M2fj0kyB1D4n4ylkA","orderid":"20180330113523646817","loginid":"test"}&user_auth_token=xxxxxxxx&tag=tag&random_string=xxxxxx $param = (array)$request->biz_content; if (!is_array($param)) { /// 参数格式错误 $return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agent_id = @$param['agentid']; /// 代理id $channel_id = @$param['channelid']; /// 渠道id $order_id = @$param['orderid']; /// 支付订单号 $remark = @$param['remark']; /// 备注 $login_id = @$param['loginid']; /// 登录账号 if (empty($agent_id)) { $return->seterrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } if (empty($channel_id)) { $return->seterrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR); return false; } if (empty($order_id)) { $return->seterrors(ERRORCODE_ORDERIDERROR, ERRORINFO_ORDERIDERROR); return false; } $this->pdo_begintransaction(); try { /// 校验订单信息 $cmd = /** @lang text */'select id from ct_channel_pay_log where agent_id = ? and channel_id = ? and order_id = ? and is_enable != 0'; $ret = $this->pdo_request($cmd, $agent_id, $channel_id, $order_id); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); elseif (empty($ret)) throw new Exception(ERRORINFO_INVALIDFINANCEORDER, ERRORCODE_INVALIDFINANCEORDER); /// 判断必须是最后一个有效订单 $pay_log_id = $ret[0]['id']; $cmd = /** @lang text */'select group_concat(order_id) order_id from ct_channel_pay_log where is_enable != 0 and id > ?'; $ret = $this->pdo_request($cmd, $pay_log_id); if (!$this->pdo_isdone()) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); elseif (!empty($ret) && !empty($ret[0]['order_id'])) throw new Exception(sprintf(ERRORINFO_FINANCEORDERISNOTLAST, $ret[0]['order_id']), ERRORCODE_FINANCEORDERISNOTLAST); /// 还原账期数据 $cmd = /** @lang text */<<pdo_execute($cmd, $pay_log_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $cmd = /** @lang text */<<pdo_execute($cmd, $pay_log_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); /// 还原账户数据 $cmd = /** @lang text */<<pdo_execute($cmd, $pay_log_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); /// 修改支付流水 $cmd = /** @lang text */'update ct_channel_pay_log set remark = ?, cancel_time = now(), cancel_user = ?, is_enable = 0 where id = ?'; $ret = $this->pdo_execute($cmd, $remark, $login_id, $pay_log_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $cmd = /** @lang text */'update ct_channel_account_period_pay_log set is_enable = 0 where pay_log_id = ?'; $ret = $this->pdo_execute($cmd, $pay_log_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $cmd = /** @lang text */'update ct_channel_account_period_online_pay_log set is_enable = 0 where pay_log_id = ?'; $ret = $this->pdo_execute($cmd, $pay_log_id); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $this->pdo_commit(); } catch (Exception $Exception) { $this->pdo_rollback(); $return->seterrors($Exception->getcode(), $Exception->getmessage()); return false; } $return->biz_content = array('orderid' => $order_id); return true; } /** * @note 获取渠道应收账款报表 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $request * @param ReturnParameter $return * @return bool */ public function query_channel_receivables_report($request, $return) { // http://localhost/game_proxy/trunk/api/index.php?method=finance.finance.query_channel_receivables_report&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"i33v0llvp0euhd1n9qo1fM2RV8vtog4y","channelid":"7N0e0z2u2098pf1M2fj0kyB1D4n4ylkA","year":"2018"}&user_auth_token=xxxxxxxx&tag=tag&random_string=xxxxxx $param = (array)$request->biz_content; if (!is_array($param)) { /// 参数格式错误 $return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $agent_id = @$param['agentid']; /// 代理id $channel_id = @$param['channelid']; /// 渠道id $year = intval(@$param['year']); /// 获取账期年份 $type = intval(@$param['type']); /// 类型(1:转账记录;2:支付记录) if (empty($agent_id)) { $return->seterrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR); return false; } if (empty($channel_id)) { $return->seterrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR); return false; } if (empty($year)) { $return->seterrors(ERRORCODE_FINANCEYEARERROR, ERRORINFO_FINANCEYEARERROR); return false; } if (1 == $type) $cmd = /** @lang text */<<seterrors(ERRORCODE_TYPEERROR, ERRORINFO_TYPEERROR); return false; } $ret = $this->pdo_request($cmd, $agent_id, $channel_id); if (!$this->pdo_isdone()) { $return->seterrors($this->geterrorcode(), $this->geterrorinfo() . '(' . __LINE__ . ')'); return false; } if(is_array($ret) && isset($ret[0])) { $data['title'] = array_keys($ret[0]); foreach ($ret as $k => $v) { foreach ($v as $q) { $data['data'][$k][] = $q; } } }else{ $data = []; } $return->biz_content = $data; return true; } /** * @note 保存营业收入数据 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $request * @param ReturnParameter $return * @return bool */ public function business_income_new($request, $return) { $param = (array)$request->biz_content; if (!is_array($param)) { /// 参数格式错误 $return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $account_period = @$param['date']; /// 账期(yyyymm) if (empty($account_period)) { $return->seterrors(ERRORCODE_ACCOUNTPERIODERROR, ERRORINFO_ACCOUNTPERIODERROR); return false; } $account_period = str_replace('-', '', $account_period); /// 处理字符串 $account_period = $this->NewMasterCommand()->GetIdentifiers($account_period, true); $this->pdo_begintransaction(); try { /// 删除往期账期数据 $cmd = /** @lang text */<<pdo_execute($cmd); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); /// 插入账期数据 $cmd = /** @lang text */<< 0 and date_format(a.create_time, '%Y%m') = {$account_period} group by a.agent_id, a.channel_id ) m on a.agent_id = m.agent_id and a.channel_id = m.channel_id left join ( select agent_id, channel_id, sum(case type when 1 then amount else 0 end) sum_card_sell_third, sum(case type when 2 then amount else 0 end) sum_gold_sell_third, sum(case type when 1 then fee else 0 end) sum_card_money_third, sum(case type when 2 then fee else 0 end) sum_gold_money_third from ct_pay_for_third where date_format(create_time, '%Y%m') = {$account_period} group by agent_id, channel_id ) o on a.agent_id = o.agent_id and a.channel_id = o.channel_id where a.is_open = 1 EOL; $ret = $this->pdo_execute($cmd); if (!$ret) throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); $this->pdo_commit(); } catch (Exception $Exception) { $this->pdo_rollback(); $return->seterrors($Exception->getcode(), $Exception->getmessage()); return false; } return true; } /** * @note 获取营业收入数据 * 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败) * @param RequestParameter $request * @param ReturnParameter $return * @return bool */ public function business_income_report($request, $return) { $param = (array)$request->biz_content; if (!is_array($param)) { /// 参数格式错误 $return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR); return false; } $account_period = @$param['date']; /// 账期(yyyymm) if (empty($account_period)) { $return->seterrors(ERRORCODE_ACCOUNTPERIODERROR, ERRORINFO_ACCOUNTPERIODERROR); return false; } $account_period = str_replace('-', '', $account_period); /// 处理字符串 $account_period = $this->NewMasterCommand()->GetIdentifiers($account_period, true); // 1-实时数据 0-历史数据 $type = isset($param['type']) ? (int)$param['type'] : 0; /// 先查询往期数据, $cmd = /** @lang text */<<pdo_request($cmd); if (!$this->pdo_isdone()) { $return->seterrors($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); return false; } if ($type === 1) /// 如果没有往期数据则根据指定账期动态查询 { $cmd = /** @lang text */<< 0 and date_format(a.create_time, '%Y%m') = {$account_period} group by a.agent_id, a.channel_id ) m on a.agent_id = m.agent_id and a.channel_id = m.channel_id left join ( select agent_id, channel_id, sum(case type when 1 then amount else 0 end) sum_card_sell_third, sum(case type when 2 then amount else 0 end) sum_gold_sell_third, sum(case type when 1 then fee else 0 end) sum_card_money_third, sum(case type when 2 then fee else 0 end) sum_gold_money_third from ct_pay_for_third where date_format(create_time, '%Y%m') = {$account_period} group by agent_id, channel_id ) o on a.agent_id = o.agent_id and a.channel_id = o.channel_id where a.is_open = 1 EOL; $items = $this->pdo_request($cmd); if (!$this->pdo_isdone()) { $return->seterrors($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode()); return false; } } $data = []; if(is_array($items) && isset($items[0])) { $data['title'] = array_keys($items[0]); foreach ($items as $k => $v) { foreach ($v as $q) { if(is_numeric($q)) $q = round($q, 2); $data['data'][$k][] = $q; } } } // 5、数据返回部分 $return->biz_content = $data; return true; } }