修复导出问题 修复显示金额问题

This commit is contained in:
mkm 2023-05-30 15:37:10 +08:00
parent a61a729ae3
commit 0126357d76
3 changed files with 241 additions and 165 deletions

View File

@ -298,7 +298,7 @@ class FinancialRecordRepository extends BaseRepository
* @author Qinii
* @day 3/23/21
*/
public function getAdminList(array $where,int $page,int $limit)
public function getAdminList(array $where, int $page, int $limit, $merchant = [])
{
//日
if ($where['type'] == 1) {
@ -318,12 +318,11 @@ class FinancialRecordRepository extends BaseRepository
$query = $this->dao->search($where)->field($field)->group("time")->order('create_time DESC');
$count = $query->count();
$list = $query->page($page,$limit)->select()->each(function ($item) use($where){
$list = $query->page($page, $limit)->select()->each(function ($item) use ($where, $merchant) {
$key = $where['is_mer'] ? $where['is_mer'] . '_financial_record_list_' . $item['time'] : 'sys_financial_record_list_' . $item['time'];
if (($where['type'] == 1 && ($item['time'] == date('Y-m-d', time()))) || ($where['type'] == 2 && ($item['time'] == date('Y-m', time())))) {
$income = ($this->countIncome($where['type'],$where,$item['time']))['number'] ;
$expend = ($this->countExpend($where['type'],$where,$item['time']))['number'] ;
$income = ($this->countIncome($where['type'], $where, $item['time'],$merchant))['number'];
$expend = ($this->countExpend($where['type'], $where, $item['time'],$merchant))['number'];
$ret = [
'income' => $income,
'expend' => $expend,
@ -331,8 +330,8 @@ class FinancialRecordRepository extends BaseRepository
];
} else {
if (!$ret = Cache::get($key)) {
$income = ($this->countIncome($where['type'],$where,$item['time']))['number'] ;
$expend = ($this->countExpend($where['type'],$where,$item['time']))['number'] ;
$income = ($this->countIncome($where['type'], $where, $item['time'],$merchant))['number'];
$expend = ($this->countExpend($where['type'], $where, $item['time'],$merchant))['number'];
$ret = [
'income' => $income,
'expend' => $expend,
@ -359,7 +358,8 @@ class FinancialRecordRepository extends BaseRepository
*/
public function adminDetail(int $type, array $where)
{
$date_ = strtotime($where['date']);unset($where['date']);
$date_ = strtotime($where['date']);
unset($where['date']);
$date = ($type == 1) ? date('Y-m-d', $date_) : date('Y-m', $date_);
$income = $this->countIncome($type, $where, $date);
$bill = $this->countBill($type, $date);
@ -411,12 +411,13 @@ class FinancialRecordRepository extends BaseRepository
* @author Qinii
* @day 5/6/21
*/
public function merDetail(int $type,array $where)
public function merDetail(int $type, array $where,$merchant=[])
{
$date_ = strtotime($where['date']); unset($where['date']);
$date_ = strtotime($where['date']);
unset($where['date']);
$date = ($type == 1) ? date('Y-m-d', $date_) : date('Y-m', $date_);
$income = $this->countIncome($type,$where,$date);
$expend = $this->countExpend($type,$where,$date);
$income = $this->countIncome($type, $where, $date,$merchant);
$expend = $this->countExpend($type, $where, $date,$merchant);
$charge = bcsub($income['number'], $expend['number'], 2);
$data['date'] = $date;
@ -488,9 +489,33 @@ class FinancialRecordRepository extends BaseRepository
* @author Qinii
* @day 3/23/21
*/
public function countIncome($type, $where, $date)
public function countIncome($type, $where, $date, $merchant = [])
{
$financialType = ['order', 'order_presell', 'presell', 'mer_presell'];
if ($merchant){
switch ($merchant['type_id']) {
case 16:
$financialType1 = ['commission_to_town'];
break;
case 15:
$financialType1 = ['commission_to_village'];
break;
case 14:
$financialType1 = ['commission_to_service_team'];
break;
case 11:
$financialType1 = ['commission_to_cloud_warehouse'];
break;
case 10:
$financialType1 = ['commission_to_entry_merchant'];
break;
default:
$financialType1 = [];
}
$financialType = array_merge($financialType, $financialType1);
}
[$data['count_order'], $data['number_order']] = $this->dao->getDataByType($type, $where, $date, $financialType);
if ($where['is_mer']) {
$financialType = ['order_platform_coupon'];
@ -508,7 +533,6 @@ class FinancialRecordRepository extends BaseRepository
$data['count'] = $data['count_order'];
$data['number'] = bcadd($data['number_coupon'], $data['number_order'], 2);
return $data;
}
@ -546,7 +570,7 @@ class FinancialRecordRepository extends BaseRepository
* @author Qinii
* @day 3/23/21
*/
public function countExpend($type, $where, $date)
public function countExpend($type, $where, $date,$merchant=[])
{
/**
* 平台支出
@ -563,6 +587,32 @@ class FinancialRecordRepository extends BaseRepository
$financialType = ['refund_charge'];
[$data['count_charge'], $data['number_charge']] = $this->dao->getDataByType($type, $where, $date, $financialType);
if ($merchant){
switch ($merchant['type_id']) {
case 16:
$financialType1 = ['commission_to_town_refund'];
break;
case 15:
$financialType1 = ['commission_to_village_refund'];
break;
case 14:
$financialType1 = ['commission_to_service_team_refund'];
break;
case 11:
$financialType1 = ['commission_to_cloud_warehouse_refund'];
break;
case 10:
$financialType1 = ['commission_to_entry_merchant_refund'];
break;
default:
$financialType1 = [];
}
}else{
//退款的
$refund=['commission_to_town_refund','commission_to_village_refund','commission_to_service_team_refund','commission_to_cloud_warehouse_refund','commission_to_entry_merchant_refund'];
//分成的
$commission=['commission_to_town','commission_to_village','commission_to_service_team','commission_to_cloud_warehouse','commission_to_entry_merchant'];
}
if ($where['is_mer']) { //商户的
//退回 收入
$financialType = ['refund_order'];
@ -575,7 +625,10 @@ class FinancialRecordRepository extends BaseRepository
//商户保证金
$financialType = ['auto_margin'];
[$data['count_auto_margin'], $data['number_auto_margin']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//商户保证金退回
$financialType = ['auto_margin_refund'];
[$data['count_auto_margin_refund'], $data['number_auto_margin_refund']] = $this->dao->getDataByType($type, $where, $date, $financialType);
$number3 = bcsub($data['number_auto_margin'], $data['number_auto_margin_refund'], 3);
//退回佣金
$financialType = ['refund_brokerage_two', 'refund_brokerage_one'];
[$data['count_refund_brokerage'], $data['number_refund_brokerage']] = $this->dao->getDataByType($type, $where, $date, $financialType);
@ -587,6 +640,12 @@ class FinancialRecordRepository extends BaseRepository
$financialType = ['refund_svip_coupon'];
[$data['count_svipcoupon'], $data['number_svipcoupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
if (!empty($financialType1)){
[$data['count_commission'], $data['number_commission']] = $this->dao->getDataByType($type, $where, $date, $financialType1);
$data['count_brokerage']+=$data['count_commission'];
$data['number_brokerage']+=$data['number_commission'];
}
//佣金 brokerage_one,brokerage_two - 退回佣金 refund_brokerage_two,refund_brokerage_one
$number = bcsub($data['number_brokerage'], $data['number_refund_brokerage'], 3);
@ -596,12 +655,12 @@ class FinancialRecordRepository extends BaseRepository
//退回收入 refund_order + 退回佣金
$number_2 = bcadd(bcadd($data['number_refund'], $data['number_coupon'], 2), $data['number_svipcoupon'], 2);
$data['count'] = $data['count_brokerage'] + $data['count_refund'] + $data['count_order_charge'] + $data['count_refund_brokerage'] + $data['count_svipcoupon'] + $data['count_auto_margin'];
$data['number'] =bcadd(bcadd($number_2,$number,3),$number_1,2);
$data['number'] = bcadd(bcadd($number3,bcadd($number_2, $number, 3),3), $number_1, 2);
} else { //平台的
// 退回 订单实际获得金额
$financialType = ['order_true','presell_true'];
$financialType = ['order_true', 'presell_true','auto_margin'];
[$data['count_order'], $data['number_order']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//付给商户的优惠券抵扣金额
@ -612,6 +671,12 @@ class FinancialRecordRepository extends BaseRepository
$financialType = ['order_svip_coupon'];
[$data['count_svipcoupon'], $data['number_svipcoupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//付给服务团队和其他的佣金
[$data['count_refund'], $data['number_refund']] = $this->dao->getDataByType($type, $where, $date, $refund);
[$data['count_commission'], $data['number_commission']] = $this->dao->getDataByType($type, $where, $date, $commission);
$data['count_brokerage']+=$data['count_commission']-$data['count_refund'];
$data['number_brokerage']+=$data['number_commission']-$data['number_refund'];
$number = bcadd($data['number_brokerage'], $data['number_order'], 2);
$number_1 = bcadd(bcadd($number, $data['number_coupon'], 2), $data['number_svipcoupon'], 2);

View File

@ -96,7 +96,12 @@ class FinancialRecord extends BaseController
[$page, $limit] = $this->getPage();
$where = $this->request->params([['type',1],'date']);
$where['is_mer'] = $this->request->merId() ?? 0 ;
$data = $this->repository->getAdminList($where,$page, $limit);
try {
$merchant = $this->request->merchant();
}catch (\Exception $e){
$merchant = [];
}
$data = $this->repository->getAdminList($where,$page, $limit,$merchant);
return app('json')->success($data);
}
@ -114,7 +119,8 @@ class FinancialRecord extends BaseController
$where['date'] = empty($date) ? date('Y-m-d',time()) : $date ;
$where['is_mer'] = $this->request->merId() ?? 0 ;
if($this->request->merId()){
$data = $this->repository->merDetail($type,$where);
$merchant = $this->request->merchant();
$data = $this->repository->merDetail($type,$where,$merchant);
}else{
$data = $this->repository->adminDetail($type,$where);
}

View File

@ -352,6 +352,7 @@ class ExcelService
'order_presell' => '预售订单(定金)',
'refund_platform_coupon' => '退回优惠券补贴',
'order_platform_coupon' => '优惠券补贴',
'auto_margin'=> '保证金',
'commission_to_service_team'=>'订单平台佣金',
'commission_to_platform'=>'订单剩余平台手续费',
'commission_to_village'=>'订单平台佣金',
@ -360,6 +361,11 @@ class ExcelService
'commission_to_platform_refun'=>'退回剩余平台手续费',
'commission_to_village_refun'=>'退回平台佣金',
'commission_to_town_refun'=>'退回平台佣金',
'auto_margin_refun'=>'退回保证金',
'commission_to_entry_merchant'=>'订单平台佣金',
'commission_to_cloud_warehouse'=> '订单平台佣金',
'commission_to_entry_merchant_refund'=> '退回平台佣金',
'commission_to_cloud_warehouse_refund'=> '退回平台佣金',
];
$sys_pm_1 = ['order','presell','order_charge','order_presell','presell_charge','refund_brokerage_one','refund_brokerage_two'];
$mer_pm_1 = ['order','presell','refund_charge','refund_brokerage_one','refund_brokerage_two','mer_presell','order_platform_coupon'];
@ -438,7 +444,6 @@ class ExcelService
$i++;
$mer_name = $mer_name ? $mer_name : ($value['merchant']['mer_name'] ?? '');
}
$count_brokeage = $expend['count_brokerage'] + $expend['count_refund_brokerage'];
$number_brokeage = bcsub($expend['number_brokerage'],$expend['number_refund_brokerage'],2);
$count_charge = $expend['count_charge']+$expend['count_order_charge'];