diff --git a/Application/Admin/Controller/FinancePromoteController.class.php b/Application/Admin/Controller/FinancePromoteController.class.php index 5f98c6d27..c910dc112 100644 --- a/Application/Admin/Controller/FinancePromoteController.class.php +++ b/Application/Admin/Controller/FinancePromoteController.class.php @@ -149,10 +149,10 @@ class FinancePromoteController extends AdminController $insideBelong = 0; foreach ($data as $key => $value) { - if ($value['company_belong']=='外团') { - $outBelong+=$value['allcount']; - } else { + if ($value['company_belong']=='内团') { $insideBelong+=$value['allcount']; + } else { + $outBelong+=$value['allcount']; } } diff --git a/Application/Admin/Controller/StatementMangementController.class.php b/Application/Admin/Controller/StatementMangementController.class.php index 6ad7ab8af..830528d3e 100644 --- a/Application/Admin/Controller/StatementMangementController.class.php +++ b/Application/Admin/Controller/StatementMangementController.class.php @@ -316,7 +316,11 @@ class StatementMangementController extends ThinkController } if ($id) { $upt = M('reward_record', 'tab_')->where(['id'=>$id])->save($data); - return $upt ? $this->success('更新成功', U('StatementMangement/rewardManageList')) : $this->error('更新失败'); + if ($upt === false) { + $this->error('保存失败'); + } else { + $this->success('保存成功', U('StatementMangement/rewardManageList')); + } } else { $data['create_time'] = time(); $data['creater_id'] = is_login(); @@ -609,7 +613,7 @@ class StatementMangementController extends ThinkController $statement = M('statement','tab_') ->field('ext_field') - ->where(['ext_field'=>['like','%,%']]) + ->where(['statement_type'=>2]) ->select(); $withdrawData = []; @@ -624,7 +628,10 @@ class StatementMangementController extends ThinkController } - $thisWithdraw = explode(',',$_REQUEST['withdraw']); +// $thisWithdraw = explode(',',$_REQUEST['withdraw']); + $thisWithdraw = explode(',',M('statement','tab_')->where(['id'=>$_REQUEST['id']])->find()['ext_field']); +// dump($thisWithdraw);die(); + foreach ($data as $key => $value) { // $data[$key]['settlement_begin_time'] = date("Y-m-d H:i:s", $data[$key]['settlement_begin_time']); @@ -795,6 +802,8 @@ class StatementMangementController extends ThinkController $is_save = M('statement','tab_')->where(['id'=>$_REQUEST['withdraw_id']])->save($data); +// echo M('statement','tab_')->_sql();die(); + if ($is_save) { $this->ajaxReturn(['status'=>1,'msg'=>'修改成功']); } else { diff --git a/Application/Admin/Model/WithdrawModel.class.php b/Application/Admin/Model/WithdrawModel.class.php index 75b82fb75..a591165cb 100644 --- a/Application/Admin/Model/WithdrawModel.class.php +++ b/Application/Admin/Model/WithdrawModel.class.php @@ -498,7 +498,7 @@ class WithdrawModel extends Model{ { $promoteGameRatioMap['status'] = 1; $promoteGameRatioMap['promote_id'] = $promote['id']; - $promoteGameRatios = D('promote_game_ratio')->field('game_id, ratio, turnover_ratio, begin_time, end_time') + $promoteGameRatios = M('promote_game_ratio', 'tab_')->field('game_id, ratio, turnover_ratio, begin_time, end_time') ->where($promoteGameRatioMap) ->order('update_time desc') ->select(); @@ -566,7 +566,7 @@ class WithdrawModel extends Model{ $promoteGameRatioMap['status'] = 1; $promoteGameRatioMap['promote_id'] = $promote['id']; - $promoteGameRatios = D('promote_game_ratio')->field('game_id, ratio, turnover_ratio, begin_time, end_time') + $promoteGameRatios = M('promote_game_ratio', 'tab_')->field('game_id, ratio, turnover_ratio, begin_time, end_time') ->where($promoteGameRatioMap) ->order('update_time desc') ->select(); diff --git a/Application/Admin/View/FinancePromote/index.html b/Application/Admin/View/FinancePromote/index.html index 2e1ae29a4..1e4a00369 100644 --- a/Application/Admin/View/FinancePromote/index.html +++ b/Application/Admin/View/FinancePromote/index.html @@ -258,7 +258,7 @@ 内外团占比: - 内团充值金额占比:{$insideBelong}%    外团充值金额占比:{$outBelong}% + 内团充值金额占比:{$insideBelong}%    其他团体充值金额占比:{$outBelong}% diff --git a/Application/Admin/View/Promote/lists.html b/Application/Admin/View/Promote/lists.html index d98c32800..014df7416 100644 --- a/Application/Admin/View/Promote/lists.html +++ b/Application/Admin/View/Promote/lists.html @@ -299,6 +299,9 @@ 删除 + + 资质认证 + diff --git a/Application/Admin/View/StatementMangement/PersonOrderEdit.html b/Application/Admin/View/StatementMangement/PersonOrderEdit.html index 37b7545eb..1d2643564 100644 --- a/Application/Admin/View/StatementMangement/PersonOrderEdit.html +++ b/Application/Admin/View/StatementMangement/PersonOrderEdit.html @@ -80,6 +80,7 @@
+  - 
@@ -277,6 +278,7 @@ return $(elem).val(); }).get().join(","); var id =$("#withdraw_id").val(); + var withdraw =$("#withdraw").val(); var url = "/admin.php?s=/statementMangement/PersonOrderEdit/withdraw/" + text + "/time_start/" + $("#time_start").val() + "/time_end/" + $("#time_end").val() + "/id/" + id; console.log(url) diff --git a/Application/Home/Controller/FinanceController.class.php b/Application/Home/Controller/FinanceController.class.php index 9bf7327c1..d65b914f6 100644 --- a/Application/Home/Controller/FinanceController.class.php +++ b/Application/Home/Controller/FinanceController.class.php @@ -34,13 +34,23 @@ class FinanceController extends BaseController return true; } - private function getDayList($beginTime, $endTime) + private function getDayList($beginTime, $endTime, $timeType = 1) { $dayList = []; - do { - $dayList[] = date('Y-m-d', $beginTime); - $beginTime += 24 * 60 * 60; - } while ($beginTime < $endTime); + switch ($timeType) { + case 1: + do { + $dayList[] = date('Y-m-d', $beginTime); + $beginTime += 24 * 60 * 60; + } while ($beginTime < $endTime); + break; + case 2: + do { + $dayList[] = date('Y-m', $beginTime); + $beginTime = strtotime('+1 month', $beginTime); + } while ($beginTime < $endTime); + break; + } return $dayList; } @@ -120,20 +130,24 @@ 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(selle_status = 0, pay_amount, 0)) as not_withdrawn_amount") + sum(if(pay_time < $thisDay, if(selle_status = 0, pay_amount * selle_ratio, 0), 0)) as balance") ->where($map) ->find(); + foreach ($income as &$value) { + $value = bcdiv($value, 100, 2); + } + $withdrawMap['promote_id'] = $this->loginPromote['id']; - $withdrawMap['status'] = ['neq', 2]; + $withdrawMap['status'] = 2; //已提现总额 $income['withdrawn_amount'] = M('withdraw', 'tab_')->field('sum(sum_money) as withdrawn_amount')->where($withdrawMap)->find()['withdrawn_amount']; - - foreach ($income as &$value) { - $value = bcdiv($value, 100, 2); - } + $withdrawMap['status'] = ['in', [-1, 0, 1]]; + $notWithdrawnAmount = M('withdraw', 'tab_')->field('sum(sum_money) as withdrawn_amount')->where($withdrawMap)->find()['withdrawn_amount']; + $income['withdrawn_amount'] = $income['withdrawn_amount'] ?? '0.00'; + $notWithdrawnAmount = $notWithdrawnAmount ?? 0; + $income['not_withdrawn_amount'] = bcadd($this->getSumAmountBySettlementType(), $notWithdrawnAmount, 2); $withdrawMap['status'] = ['not in', [-2, -1]]; $withdrawns = M('withdraw', 'tab_')->field('settlement_begin_time, settlement_end_time') @@ -191,6 +205,122 @@ class FinanceController extends BaseController $this->display(); } + public function getSumAmountBySettlementType() + { + $withdrawModel = new WithdrawModel(); + $balance = 0; + + if ($this->loginPromote['settlement_type'] == 2) { + $settlementType = 2; + } else { + $map['pay_status'] = 1; + $map['selle_status'] = 0; + $balance = M('spend', 'tab_')->field('sum(pay_amount * selle_ratio) as balance')->where($map)->find()['balance']; + $balance = $balance ? bcdiv($balance , 100, 2) : 0; + $settlementType = 3; + } + + $months = $this->getDayList(strtotime('2019-09'), strtotime(date('Y-m')), 2); + $promote = $this->loginPromote; + + if ($settlementType == 2) { + $fun = 'getMonthAmount'; + } else { + $fun = 'getRecoupAmount'; + } + + if ($months) { + foreach ($months as $month) { + $data['begin_time'] = strtotime($month); + $data['end_time'] = strtotime('+1 month', $data['begin_time']) - 1; + $balance = bcadd($balance, $withdrawModel->$fun($promote, $data), 2); + } + } + + return $balance; + } + + public function getNotWithdrawnAmount() + { + $thisMonth = strtotime(date('Y-m')); + $map['promote_id'] = $this->loginPromote['id']; + $map['status'] = 1; + $map['begin_time'] = ['elt', $thisMonth]; + $promoteGameRatios = M('promote_game_ratio', 'tab_')->field('game_id, begin_time, end_time, ratio, turnover_ratio') + ->where($map) + ->select(); + + if (empty($promoteGameRatios)) { + return 0; + } else { + $income = 0; + $map['status'] = ['neq', -2]; + $map['settlement_type'] = ['in', [2, 3]]; + unset($map['begin_time']); + $withdrawDays = M('withdraw', 'tab_')->where($map)->getField('settlement_begin_time', true); + if ($withdrawDays) { + foreach ($withdrawDays as &$withdrawDay) { + $withdrawDay = date('Y-m', $withdrawDay); + } + } else { + $withdrawDays = []; + } + foreach ($promoteGameRatios as $promoteGameRatio) { + $map = []; + $map['game_id'] = $promoteGameRatio['game_id']; + $promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true); + $days = $this->getDayList($promoteGameRatio['begin_time'], $thisMonth, 2); + if ($days) { + foreach ($days as $day) { + if (!in_array($day, $withdrawDays)) { + $day = strtotime($day); + $map['pay_time'] = ['between', [$day, strtotime('+1 month', $day) - 1]]; + $sumAmount = $this->getSumMoney($map); + $diffRatio = $this->getDiffRatio($sumAmount, $promoteGameRatio['ratio'], $promoteGameRatio['turnover_ratio']); + $income += bcmul($sumAmount, bcdiv($diffRatio, 100, 2), 2); + } + } + } + } + } + + return $income; + } + + private function getSumMoney($map = []) + { + $map['pay_status'] = 1; + + $sumAmount = M('spend', 'tab_')->field('sum(pay_amount) as sum_amount')->where($map)->find()['sum_amount']; + $sumAmount = $sumAmount ?? 0; + return $sumAmount; + } + + private function getDiffRatio($sumAmount, $defaultRatio, $turnoverRatios) + { + if ($turnoverRatios) { + $ratio = $defaultRatio; + foreach ($turnoverRatios as $turnoverRatio) { + if (empty($turnoverRatio['instanceof']) || $turnoverRatio['instanceof'] == 1) { + if ($sumAmount >= $turnoverRatio['turnover']) { + $ratio = $turnoverRatio['ratio']; + break; + } + } else { + if ($sumAmount > $turnoverRatio['turnover']) { + $ratio = $turnoverRatio['ratio']; + break; + } + } + } + + $ratio = bcsub($ratio - $defaultRatio, 2); + return $ratio; + } + + return 0; + } + //结算明细 public function settlementDtl() { diff --git a/Application/Home/View/default/Finance/index.html b/Application/Home/View/default/Finance/index.html index 63f96312b..ae9906f67 100644 --- a/Application/Home/View/default/Finance/index.html +++ b/Application/Home/View/default/Finance/index.html @@ -34,8 +34,8 @@
  • 账户余额

    ¥{$income.balance}
    • -
    • 已提现总金额

      ¥{$income.withdrawn_amount}
    • -
    • 未提现金额

      ¥{$income.not_withdrawn_amount}
    • +
    • 已实际提现总金额

      ¥{$income.withdrawn_amount}
    • +
    • 未实际提现金额

      ¥{$income.not_withdrawn_amount}
    • 结算周期

      {$settlementCycle}