You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jy-platform/Application/Base/Factory/SpecialCompoentCaculateFact...

164 lines
6.7 KiB
PHP

<?php
namespace Base\Factory;
class SpecialCompoentCaculateFactory {
public function __construct(){}
/**
* 订单相关金额重算
* @param array $statement_info
* @param int $company_type
* @param int $company_id
* @return array|bool
*/
public function caculateStatementInfo($statement_info = [],$company_type = 2,$company_id = 0) {
if (!$statement_info) {
return false;
}
if (!$company_id) {
return false;
}
$platform_amount = 0;
$statement_amount = 0;
$promote_id = M("promote","tab_")
->field("id")
->where(['company_id'=>$company_id])
->select();
if ($promote_id) {
$map['promote_id'] = ['in',array_column($promote_id,'id')];
} else {
$map['promote_id'] = '-1';
}
$map['tab_spend.pay_status'] = 1;
if ($company_type == 2) {
foreach($statement_info as $key => $value) {
$game_list = $value["game_list"];
foreach ($game_list as $gk => $gv) {
$start_time = str_replace('.','-',$gv['statement_begin_time']);
$end_time = str_replace('.','-',$gv['statement_end_time']);
$map['relation_game_id'] = $gv['relation_game_id'];
$map['payed_time'] = ['between', [strtotime($start_time), strtotime($end_time)+86399]];
$amount = M("spend","tab_")
->field("sum(pay_amount) pay_amount")
->join("left join tab_game game on tab_spend.game_id=game.id")
->where($map)
->find()['pay_amount'];
$statement_info[$key]['game_list'][$gk]['pay_amount'] = floatval($amount);
$statement_info[$key]['game_list'][$gk]['sum_money'] = (string)(number_format($amount*($gv['increment_ratio']/100),2,'.',''));
$platform_amount += $amount;
$statement_amount += floatval($amount*($gv['increment_ratio']/100));
}
}
} else {
foreach($statement_info as $key => $value) {
$start_time = str_replace('.','-',$value['statement_begin_time']);
$end_time = str_replace('.','-',$value['statement_end_time']);
$map['relation_game_id'] = $value['relation_game_id'];
$map['payed_time'] = ['between', [strtotime($start_time), strtotime($end_time)+86399]];
$amount = M("spend","tab_")
->field("sum(pay_amount) pay_amount")
->join("left join tab_game game on tab_spend.game_id=game.id")
->where($map)
->find()['pay_amount'];
$statement_info[$key]['pay_amount'] = floatval($amount);
$statement_info[$key]['sum_money'] = (string)(number_format($amount*($value['increment_ratio']/100),2,'.',''));
$platform_amount += $amount;
$statement_amount += floatval($amount*($value['increment_ratio']/100));
}
}
return [$statement_info,$platform_amount,$statement_amount];
}
/**
* 公司信息更新
* @param int $company_id
* @param string $nickname
* @return array
*/
public function updateCompanyInfo($company_id = 0,$nickname = '') {
$company_data = M("promote_company","tab_")->where(['id'=>$company_id])->find();
$company_type = M("company_relation","tab_")
->where("(first_company_id={$company_id} and first_company_type =2) or (second_company_id={$company_id} and second_company_type=2)")
->find();
$proCompany_info['id'] = $company_data['id'];
$proCompany_info['partner'] =$company_data['company_name'];
$proCompany_info['link_man'] = $company_data['settlement_contact'];
$proCompany_info['link_phone'] =$company_data['contact_phone'];
$proCompany_info['address'] = $company_data['address'];
$proCompany_info['payee_name'] =$company_data['bank_address'];
$proCompany_info['bank_account'] = $company_data['bank_card'];
$proCompany_info['opening_bank'] =$company_data['bank_name'];
$proCompany_info['fax_ratio'] = $company_data['fax_ratio'];
$proCompany_info['taxation_rate'] = $company_data['taxation_rate'];
$proCompany_info['company_belong'] = $company_data['company_belong'];
$proCompany_info['company_type'] = $company_data['company_type'];
$proCompany_info['develop_type'] = $company_data['develop_type'];
$proCompany_info['ali_user'] = $company_data['ali_user'];
$proCompany_info['ali_account'] =$company_data['ali_account'];
$proCompany_info['has_server_fee'] = $company_data['has_server_fee'];
$proCompany_info['server_fee'] =$company_data['server_fee'];
$proCompany_info['has_ratio'] = $company_data['has_ratio'];
$proCompany_info['turnover_ratio'] =$company_data['turnover_ratio'];
$proCompany_info['invoice_type'] = $company_type['invoice_type'];
$proCompany_info['invoice_content'] = $company_type['invoice_content'];
$nickname?($proCompany_info['nickname'] = $nickname):'';
if ($company_type['first_company_id'] == $company_id) {
$weCompany = M("company_info","tab_")->where(['id'=>$company_type['second_company_id']])->find();
} elseif ($company_type['second_company_id'] == $company_id) {
$weCompany = M("company_info","tab_")->where(['id'=>$company_type['first_company_id']])->find();
}
$secord_info['id'] = $weCompany['id'];
$secord_info['partner'] =$weCompany['partner'];
$secord_info['link_man'] = $weCompany['link_man'];
$secord_info['link_phone'] =$weCompany['link_phone'];
$secord_info['address'] = $weCompany['address'];
$secord_info['company_tax_no'] = $weCompany['company_tax_no'];
$secord_info['payee_name'] =$weCompany['payee_name'];
$secord_info['bank_account'] = $weCompany['bank_account'];
$secord_info['opening_bank'] =$weCompany['opening_bank'];
$secord_info['invoice_type'] = $company_type['invoice_type'];
$secord_info['invoice_content'] = $company_type['invoice_content'];
if ($company_type['first_company_id'] == $company_id) {
$first_party_info = $proCompany_info;
$second_party_info = $secord_info;
} elseif ($company_type['second_company_id'] == $company_id) {
$second_party_info = $proCompany_info;
$first_party_info = $secord_info;
}
return [$first_party_info,$second_party_info];
}
}