|
@@ -89,54 +89,47 @@ class refill_balance
|
|
|
return intval($item['balance_id']);
|
|
|
}
|
|
|
|
|
|
- //system,provider,merchant
|
|
|
- //cid=0,mchid,store_id
|
|
|
- public function add_balance($type, $cid, $start, $end, $time_type, $parent_balance = 0,$remark = '系统自动生成')
|
|
|
+ private function balance_data($type, $cid, $start, $end, $time_type, $parent_balance, $remark)
|
|
|
{
|
|
|
- $order_stat = $this->order_stat($type,$cid,$start,$end,$time_type);
|
|
|
+ $order_stat = $this->order_stat($type, $cid, $start, $end, $time_type);
|
|
|
|
|
|
- if($type == 'system') {
|
|
|
- $in = $this->merchant_evidence_stat(0,$start,$end);
|
|
|
- $out = $this->provider_amount_stat(0,$start,$end);
|
|
|
+ if ($type == 'system') {
|
|
|
+ $in = $this->merchant_evidence_stat(0, $start, $end);
|
|
|
+ $out = $this->provider_amount_stat(0, $start, $end);
|
|
|
$cname = 'system';
|
|
|
|
|
|
$balance = ncPriceFormat($in - $out);
|
|
|
- }
|
|
|
- elseif($type == 'merchant') {
|
|
|
- $in = $this->merchant_evidence_stat($cid,$start,$end);
|
|
|
+ } elseif ($type == 'merchant') {
|
|
|
+ $in = $this->merchant_evidence_stat($cid, $start, $end);
|
|
|
$out = "0.0000";
|
|
|
$cname = $this->mMerchantNames[$cid];
|
|
|
|
|
|
$balance = ncPriceFormat($in - $order_stat['mch_amounts']);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
$in = "0.0000";
|
|
|
$pid = $this->mStoreidPID[$cid];
|
|
|
- $out = $this->provider_amount_stat($pid,$start,$end);
|
|
|
+ $out = $this->provider_amount_stat($pid, $start, $end);
|
|
|
$cname = $this->mProviderNames[$cid];
|
|
|
|
|
|
$balance = ncPriceFormat($in - $order_stat['channel_amounts']);
|
|
|
}
|
|
|
|
|
|
- $accumuter = function ($parent_id)
|
|
|
- {
|
|
|
+ $accumuter = function ($parent_id) {
|
|
|
if ($parent_id > 0) {
|
|
|
$item = Model('refill_balance')->getBalance(['balance_id' => $parent_id]);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
$item = [];
|
|
|
}
|
|
|
|
|
|
- if(empty($item)) {
|
|
|
+ if (empty($item)) {
|
|
|
return 0.00;
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
return $item['accumulate_balance'] + $item['balance'];
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- $data = ['parent_id' => $parent_balance, 'type' => $type, 'cid' => $cid, 'cname' => $cname,
|
|
|
- 'start_stamp' => $start,'end_stamp' => $end,'end_text' => date('Y-m-d H:i:s', $end),
|
|
|
+ return ['parent_id' => $parent_balance, 'type' => $type, 'cid' => $cid, 'cname' => $cname,
|
|
|
+ 'start_stamp' => $start, 'end_stamp' => $end, 'end_text' => date('Y-m-d H:i:s', $end),
|
|
|
'success_count' => intval($order_stat['order_counts']),
|
|
|
'refill_amount' => ncPriceFormat($order_stat['refill_amounts']),
|
|
|
'mch_amount' => ncPriceFormat($order_stat['mch_amounts']),
|
|
@@ -153,11 +146,35 @@ class refill_balance
|
|
|
'time_type' => $time_type,
|
|
|
'remark' => $remark,
|
|
|
];
|
|
|
+ }
|
|
|
|
|
|
+ //system,provider,merchant
|
|
|
+ //cid=0,mchid,store_id
|
|
|
+ public function add_balance($type, $cid, $start, $end, $time_type, $parent_balance = 0, $remark = '系统自动生成')
|
|
|
+ {
|
|
|
+ $data = $this->balance_data($type, $cid, $start, $end, $time_type, $parent_balance, $remark);
|
|
|
$ret = Model('refill_balance')->insert($data);
|
|
|
return $ret != false;
|
|
|
}
|
|
|
|
|
|
+ public function rebuild_balance($balance_id)
|
|
|
+ {
|
|
|
+ $balance = Model('refill_balance')->getBalance(['balance_id' => $balance_id]);
|
|
|
+ if(empty($balance)) return false;
|
|
|
+
|
|
|
+ $type = $balance['type'];
|
|
|
+ $cid = $balance['cid'];
|
|
|
+ $start = $balance['start_stamp'];
|
|
|
+ $end = $balance['end_stamp'];
|
|
|
+ $time_type = $balance['time_type'];
|
|
|
+ $parent_balance = $balance['parent_id'];
|
|
|
+ $remark = '记录重新生成';
|
|
|
+
|
|
|
+ $data = $this->balance_data($type, $cid, $start, $end, $time_type, $parent_balance, $remark);
|
|
|
+ $ret = Model('refill_balance')->where(['balance_id' => $balance_id])->update($data);
|
|
|
+ return $ret != false;
|
|
|
+ }
|
|
|
+
|
|
|
private function order_stat($type, $cid, $start, $end, $time_type)
|
|
|
{
|
|
|
$cond = [
|