diff --git a/Application/Home/Common/function.php b/Application/Home/Common/function.php index d473d7d5c..28fbfc621 100644 --- a/Application/Home/Common/function.php +++ b/Application/Home/Common/function.php @@ -1212,4 +1212,78 @@ function gameSearch($relationGameId, $sdkVersion) $gameIds = $gameIds ?? [-1]; return $gameIds; +} + +function convertAmountToCn($num) { + //判断$num是否存在 + if(!$num) return '零圆'; + //保留小数点后两位 + $num = round($num, 2); + //将浮点转换为整数 + $tem_num = $num * 100; + //判断数字长度 + $tem_num_len = strlen($tem_num); + if($tem_num_len > 14) { + return '数值过大'; + } + + //大写数字 + $dint = array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'); + //大写金额单位 + $danwei = array('仟', '佰', '拾', '亿', '仟', '佰', '拾', '万', '仟', '佰', '拾', '圆'); + $danwei1 = array('角', '分'); + + //空的变量用来保存转换字符串 + $daxie = ''; + + //分割数字,区分圆角分 + list($left_num, $right_num) = explode('.', $num); + + //计算单位长度 + $danwei_len = count($danwei); + //计算分割后的字符串长度 + $left_num_len = strlen($left_num); + $right_num_len = strlen($right_num); + + //循环计算亿万元等 + for($i = 0; $i < $left_num_len; $i++) { + //循环单个文字 + $key_ = substr($left_num, $i, 1); + + //判断数字不等于0或数字等于0与金额单位为亿、万、圆,就返回完整单位的字符串 + if($key_ !== '0' || ($key_ == '0' && ($danwei[$danwei_len - $left_num_len + $i] == '亿' || $danwei[$danwei_len - $left_num_len + $i] == '万' || $danwei[$danwei_len - $left_num_len + $i] == '圆'))) { + $daxie = $daxie . $dint[$key_] . $danwei[$danwei_len - $left_num_len + $i]; + } else { + //否则就不含单位 + $daxie = $daxie . $dint[$key_]; + } + } + + //循环计算角分 + for($i = 0; $i < $right_num_len; $i++) { + $key_ = substr($right_num, $i, 1); + if($key_ > 0) { + $daxie = $daxie . $dint[$key_] . $danwei1[$i]; + } + } + + //计算转换后的长度 + $daxie_len = strlen($daxie); + //设置文字切片从0开始,utf-8汉字占3个字符 + $j = 0; + while($daxie_len > 0) { + //每次切片两个汉字 + $str = substr($daxie, $j, 6); + //判断切片后的文字不等于零万、零圆、零亿、零零 + if($str == '零万' || $str == '零圆' || $str == '零亿' || $str == '零零') { + //重新切片 + $left = substr($daxie, 0, $j); + $right = substr($daxie, $j + 3); + $daxie = $left . $right; + } + $j += 3; + $daxie_len -= 3; + } + + return $daxie . '整'; } \ No newline at end of file diff --git a/Application/Home/Controller/FinanceController.class.php b/Application/Home/Controller/FinanceController.class.php index 8ecbce4d2..1587d16b5 100644 --- a/Application/Home/Controller/FinanceController.class.php +++ b/Application/Home/Controller/FinanceController.class.php @@ -119,7 +119,8 @@ class FinanceController extends BaseController $income = $model->field("sum(if(pay_time < $thisDay, if(selle_ratio > 0, pay_amount * selle_ratio, 0), 0)) as history_income, sum(if(pay_time >= $thisMonth, if(selle_ratio > 0, pay_amount * selle_ratio, 0), 0)) as this_month_income, sum(if((pay_time >= $yesterday and pay_time < $thisDay), if(selle_ratio > 0, pay_amount * selle_ratio, 0), 0)) as yesterday_income, - sum(if(pay_time < $thisDay, if(selle_status = 0, pay_amount * selle_ratio, 0), 0)) as balance") + sum(if(pay_time < $thisDay, if(selle_status = 0, pay_amount * selle_ratio, 0), 0)) as balance, + sum(if(selle_status = 0, pay_amount, 0)) as not_withdrawn_amount") ->where($map) ->find(); @@ -127,10 +128,41 @@ class FinanceController extends BaseController $value = bcdiv($value, 100, 2); } + $withdrawMap['promote_id'] = $this->loginPromote['id']; + $withdrawMap['status'] = ['neq', 2]; + + //已提现总额 + $income['withdrawn_amount'] = M('withdraw', 'tab_')->field('sum(sum_money) as withdrawn_amount')->where($withdrawMap)->find()['withdrawn_amount']; + + $withdrawns = M('withdraw', 'tab_')->field('settlement_begin_time, settlement_end_time') + ->where($withdrawMap) + ->select(); + + $days = []; + if (!empty($withdrawns)) { + foreach ($withdrawns as $withdrawn) { + $thisDays = []; + if (empty($withdrawn['settlement_begin_time'])) { + if ($begTime < $withdrawn['settlement_end_time']) { + if ($endTime <= $withdrawn['settlement_end_time']) { + $thisEndTime = $endTime; + } else { + $thisEndTime = $withdrawn['settlement_end_time']; + } + $thisDays = $this->getDayList($begTime, $thisEndTime); + } + } else { + $thisDays = $this->getDayList($withdrawn['settlement_begin_time'], $withdrawn['settlement_end_time']); + } + $days = array_merge($days, $thisDays); + } + } + $days = array_unique($days); + $map['pay_time'] = ['between', [$begTime, $endTime]]; $dayList = $this->getDayList($begTime, $endTime); $data = $model->field('FROM_UNIXTIME(pay_time, "%Y-%m-%d") as day, - sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as income') + sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as income, selle_status') ->where($map) ->group('day') ->select(); @@ -140,13 +172,16 @@ class FinanceController extends BaseController $records[] = [ 'day' => $date, 'income' => bcdiv($data[$day], 100, 2), + 'selle_status_text' => (in_array($day, $days) ? '已提现' : '未提现'), 'url' => U('settlementDtl', array('begtime' => $day, 'endtime' => $day)) ]; } } + $settlementCycle = ($this->loginPromote['settlement_type'] == 1 ? '周结' : '月结'); $this->assign('income', $income); $this->assign('listData', $records); + $this->assign('settlementCycle', $settlementCycle); $this->assign('initBegTime', $initBegTime); $this->assign('initEndTime', $initEndTime); $this->assign('yesterday', date('Y-m-d', $yesterday)); @@ -625,45 +660,25 @@ class FinanceController extends BaseController $this->error('参数异常'); } - $settlementBeginTime = $withdraw['settlement_begin_time']; - $settlementEndTime = $withdraw['settlement_end_time']; - $withdraw['create_time'] = date('Y-m-d H:i:s', $withdraw['create_time']); - $withdraw['settlement_end_time'] = date('Y-m-d H:i:s', $withdraw['settlement_end_time']); - $withdraw['status'] = FinanceController::$withdrawStatus[$withdraw['status']]; - - if (empty($withdraw['game_ratio'])) { - $map['_string'] = '1 = 2'; - } else { - $gameRatios = json_decode($withdraw['game_ratio'], true); - $gameIds = array_keys($gameRatios); - $map['game_id'] = ['in', $gameIds]; - $map['pay_time'] = ['between', [$settlementBeginTime, $settlementEndTime]]; - } - if ($withdraw['settlement_type'] != 3) { - $map['withdraw_id'] = $withdrawId; - } - - $data = M('spend', 'tab_') - ->field('game_id,game_name,if(selle_ratio >= 0,selle_ratio,0) as selle_ratio,pay_way,sum(pay_amount) as pay_amount_all,sum(if(selle_ratio > 0,pay_amount * selle_ratio,0)) as income') - ->where($map) - ->group('game_id') - ->order('game_id') - ->select(); - if (!empty($data)) { - foreach ($data as &$list) { - $list['income'] = '0.00'; - if (isset($gameRatios[$list['game_id']])) { - foreach ($gameRatios[$list['game_id']] as $gameIncome) { - $income = bcdiv(bcmul($gameIncome['sum_amount'], $gameIncome['selle_ratio'], 2), 100, 2); - $list['income'] = bcadd($list['income'], $income, 2); - } - } - } - } - - $this->assign('withdraw', $withdraw); - $this->assign('listData', $data); - $this->assign('promoteData', $this->loginPromote); + $statementMap['ext_field'] = $withdraw['widthdraw_number']; + $statementMap['statement_type'] = 1; + $statement = M('statement', 'tab_')->where($statementMap)->find(); + if (empty($statement)) { + $this->error('未生成下游结算单'); + } + + $statement['first_party_info'] = json_decode($statement['first_party_info'], 1);//甲方 + $statement['second_party_info'] = json_decode($statement['second_party_info'], 1);//乙方 + $statement['statement_info'] = json_decode($statement['statement_info'], 1);//结算记录 + //收款方 + $statement['receive_company'] = ($statement['pay_type'] ? $statement['first_party_info']['partner'] : $statement['second_party_info']['partner']); + $all_sum_money = array_sum(array_column($statement['statement_info'], 'sum_money'));//合计平台总额 + $all_pay_amount = array_sum(array_column($statement['statement_info'], 'pay_amount'));//合计结算金额 + $big_all_sum_money = convertAmountToCn($statement['statement_money']);//大写 + $this->assign('big_all_sum_money', $big_all_sum_money); + $this->assign('all_sum_money', $all_sum_money); + $this->assign('all_pay_amount', $all_pay_amount); + $this->assign('data', $statement); $this->assign('meta_title', $metaTitle); $this->assign('modelList', $modelList); $this->display(); diff --git a/Application/Home/View/default/Finance/index.html b/Application/Home/View/default/Finance/index.html index 39dc54177..63f96312b 100644 --- a/Application/Home/View/default/Finance/index.html +++ b/Application/Home/View/default/Finance/index.html @@ -33,6 +33,11 @@
昨日收益
¥{$income.yesterday_income}账户余额
¥{$income.balance}已提现总金额
¥{$income.withdrawn_amount}未提现金额
¥{$income.not_withdrawn_amount}结算周期
{$settlementCycle}游戏名称 | -流水 | -现金分成基数 | - -平台币分成基数 | - -绑定币分成基数 | - -合作方分成金额 | +结算时间 | +产品 | +平台总额 | +补点比例 | +分成比例 | +税费费率 | +结算金额(元) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -156,36 +145,73 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{$vo.game_name} | -{$vo.pay_amount_all} | -{$vo.pay_amount_all} | -0 | -{$vo.pay_amount_all} | -0 | -{$vo.pay_amount_all} | -0 | -{$vo.income} | -||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- | +{$item.type_name} | +{$item.sum_money} | +- | +- | +{$item.sum_money} | +|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{$item.statement_begin_time}-{$item.statement_end_time} | +{$item.game_name} | +{$item.pay_amount} | +{$item.second_ratio}% | +{$item.fax_ratio}% | +{$item.sum_money} | +|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
总计 | +- | +- | +- | +|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
本月分成总金额(人民币大写): | +- | +- | +- | +- | +