|
@@ -89,9 +89,81 @@ class refill_balance
|
|
|
return intval($item['balance_id']);
|
|
|
}
|
|
|
|
|
|
+ private function refill_time_finder($type, $cid, $start)
|
|
|
+ {
|
|
|
+ if ($start != 0) {
|
|
|
+ return $start;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($type == 'system') {
|
|
|
+ $mod_refill = Model('refill_order');
|
|
|
+ $item = $mod_refill->table('refill_order')->field('order_id,order_time')->order('order_id asc')->find();
|
|
|
+ } elseif ($type == 'merchant') {
|
|
|
+ $mod_refill = Model('refill_order');
|
|
|
+ $item = $mod_refill->table('refill_order')->field('order_id,order_time')->where(['mchid' => $cid])->order('order_id asc')->find();
|
|
|
+ } else {
|
|
|
+ $mod_refill = Model('vr_order');
|
|
|
+ $item = $mod_refill->table('vr_order')->field('order_id,add_time')->where(['store_id' => $cid])->order('order_id asc')->find();
|
|
|
+ }
|
|
|
+
|
|
|
+ $time = $item['order_time'] ?? time();
|
|
|
+ return $time;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function merchant_paytime_finder($cid, $start)
|
|
|
+ {
|
|
|
+ if ($start != 0) {
|
|
|
+ return $start;
|
|
|
+ }
|
|
|
+
|
|
|
+ $mod_pay = Model();
|
|
|
+ if ($cid == 0)
|
|
|
+ {
|
|
|
+ $item = $mod_pay->table('refill_evidence')
|
|
|
+ ->field('min(add_time) as add_time')
|
|
|
+ ->find();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $item = $mod_pay->table('refill_evidence')
|
|
|
+ ->field('min(add_time) as add_time')
|
|
|
+ ->where(['mchid' => $cid])
|
|
|
+ ->find();
|
|
|
+ }
|
|
|
+
|
|
|
+ $time = $item['add_time'] ?? time();
|
|
|
+ return $time;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function provider_paytime_finder($cid, $start)
|
|
|
+ {
|
|
|
+ if ($start != 0) {
|
|
|
+ return $start;
|
|
|
+ }
|
|
|
+
|
|
|
+ $mod_pay = Model();
|
|
|
+ if ($cid == 0)
|
|
|
+ {
|
|
|
+ $item = $mod_pay->table('provider_amount')
|
|
|
+ ->field('min(add_time) as add_time')
|
|
|
+ ->find();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $item = $mod_pay->table('provider_amount')
|
|
|
+ ->field('min(add_time) as add_time')
|
|
|
+ ->where(['provider_id' => $cid])
|
|
|
+ ->find();
|
|
|
+ }
|
|
|
+
|
|
|
+ $time = $item['add_time'] ?? time();
|
|
|
+ return $time;
|
|
|
+ }
|
|
|
+
|
|
|
private function balance_data($type, $cid, $start, $end, $time_type, $parent_balance, $remark)
|
|
|
{
|
|
|
- $order_stat = $this->order_stat($type, $cid, $start, $end, $time_type);
|
|
|
+ $refill_time = $this->refill_time_finder($type, $cid, $start);
|
|
|
+ $order_stat = $this->order_stat($type, $cid, $refill_time, $end, $time_type);
|
|
|
|
|
|
$transfer_calcer = function ($detail,$types = [])
|
|
|
{
|
|
@@ -109,14 +181,19 @@ class refill_balance
|
|
|
};
|
|
|
|
|
|
if ($type == 'system') {
|
|
|
- $transfer_detail = $this->merchant_evidence_stat(0, $start, $end);
|
|
|
- $out = $this->provider_amount_stat(0, $start, $end);
|
|
|
+ $merchant_time = $this->merchant_paytime_finder($cid, $start);
|
|
|
+ $transfer_detail = $this->merchant_evidence_stat($cid, $merchant_time, $end);
|
|
|
+
|
|
|
+ $provider_time = $this->provider_paytime_finder(0, $start);
|
|
|
+ $out = $this->provider_amount_stat(0, $provider_time, $end);
|
|
|
$cname = 'system';
|
|
|
|
|
|
+ $pay_time = min($merchant_time,$provider_time);
|
|
|
$in = $transfer_calcer($transfer_detail);
|
|
|
$balance = ncPriceFormat($in - $out);
|
|
|
} elseif ($type == 'merchant') {
|
|
|
- $transfer_detail = $this->merchant_evidence_stat($cid, $start, $end);
|
|
|
+ $pay_time = $this->merchant_paytime_finder($cid, $start);
|
|
|
+ $transfer_detail = $this->merchant_evidence_stat($cid, $pay_time, $end);
|
|
|
$out = "0.0000";
|
|
|
$cname = $this->mMerchantNames[$cid];
|
|
|
|
|
@@ -125,14 +202,20 @@ class refill_balance
|
|
|
} else {
|
|
|
$transfer_detail = [];
|
|
|
$pid = $this->mStoreidPID[$cid];
|
|
|
- $out = $this->provider_amount_stat($pid, $start, $end);
|
|
|
+ $pay_time = $this->provider_paytime_finder($pid, $start);
|
|
|
+ $out = $this->provider_amount_stat($pid, $pay_time, $end);
|
|
|
$cname = $this->mProviderNames[$cid];
|
|
|
|
|
|
$in = $transfer_calcer($transfer_detail);
|
|
|
$balance = ncPriceFormat($in - $order_stat['channel_amounts']);
|
|
|
}
|
|
|
|
|
|
- $accumuter = function ($parent_id) {
|
|
|
+ if($start == 0) {
|
|
|
+ $start = min($start,$pay_time);
|
|
|
+ }
|
|
|
+
|
|
|
+ $accumuter = function ($parent_id)
|
|
|
+ {
|
|
|
if ($parent_id > 0) {
|
|
|
$item = Model('refill_balance')->getBalance(['balance_id' => $parent_id]);
|
|
|
} else {
|