load->library('trippest'); $this->load->helper('array'); $this->load->model('Vendor_money_model', 'money_model'); mb_regex_encoding("UTF-8"); bcscale(2); } public function settlement() { $data['default_date1'] = date('Y-m-01', strtotime("last month")); $data['default_date2'] = date('Y-m-d H:i:s', mktime(0,0,0,date('m'),1,date('Y'))-1); $vendor_sourcetype = $this->trippest->vendor_sourcetype(); $data['default_vendor'] = array_keys($vendor_sourcetype); $this->load->view('vendor_money_sum', $data); } public function index() { $this->permission->is_admin(true); $date_range = $this->input->post("date_range"); preg_match_all('/\d{4}\-\d{2}\-\d{2}/', $date_range, $date_range_arr); if (empty($date_range_arr[0])) { return $this->settlement(); } $start_date = $date_range_arr[0][0]; $end_date =$date_range_arr[0][1] . " 23:59:59"; if ($end_date == null) { $end_date = date("Y-m-d H:i:s", strtotime("+1 month", strtotime($start_date))-1); } $vendors = $this->input->post("vendors"); $vendor_sourcetype = $this->trippest->vendor_sourcetype(); $result = array( "default_date1" => $start_date ,"default_date2" => $end_date ,"default_vendor" => $vendors ,"trippest_order_vendor_money" => array() ,"transfer_sum" => 0 /** 列总计 */ ,"col_sum" => array( "trippest" => array( "sum_trippest_cost" => 0 ,"sum_vendor_cost" => 0 ,"sum_trippest_sum" => 0 ,"sum_vendor_sum" => 0 ,"sum_profit" => 0 ,"sum_trippest_profit" => 0 ,"sum_vendor_profit" => 0 ,"sum_payout" => 0 ,"sum_other" => 0 ), "vendor" => array( "sum_trippest_cost" => 0 ,"sum_vendor_cost" => 0 ,"sum_trippest_sum" => 0 ,"sum_vendor_sum" => 0 ,"sum_profit" => 0 ,"sum_trippest_profit" => 0 ,"sum_vendor_profit" => 0 ,"sum_payout" => 0 ,"sum_other" => 0 ) ) ); /** 团款 */ foreach ($vendors as $key => $vendor) { $sourcetype = $vendor_sourcetype[strval($vendor)]["sourcetype"]; $opi_summoney = $this->money_model->checked_group_list($vendor, $sourcetype, $start_date, $end_date, implode(',', $vendors)); $ret = array( "trippest" => array( "trippest_sum" => 0, "vendor_sum" => 0, "other_sum_cost" => 0, "other_sum" => 0 ), "vendor" => array( "trippest_sum" => 0, "vendor_sum" => 0, "transfer_sum" => 0, "other_sum_cost" => 0, "other_sum" => 0 ) ); // 按照海纳的算法 foreach ($opi_summoney as $key => $opi_money) { if (floatval($opi_money['vendor_sum']) > 0) { $ret["trippest"]['vendor_sum'] = bcadd(floatval($ret["trippest"]['vendor_sum']), floatval($opi_money['vendor_sum'])) ; } if (floatval($opi_money['trippest_sum']) > 0) { $ret["trippest"]['trippest_sum'] = bcadd(floatval($ret["trippest"]['trippest_sum']), floatval($opi_money['trippest_sum'])) ; } $ret['trippest']['other_sum'] = bcadd($ret['trippest']['other_sum'], $opi_money['other_price_sum']); $ret['trippest']['other_sum_cost'] = bcadd($ret['trippest']['other_sum_cost'], $opi_money['other_cost_sum']); $ret["trippest"]['trippest_sum'] = bcsub($ret["trippest"]['trippest_sum'], $opi_money['other_price_sum']); } // 按照图兰朵算法: Trippest自营订单的代收算在海纳收款 foreach ($opi_summoney as $kv => $opi_money_v) { if (strval($opi_money_v['COLI_OPI_ID']) === '435') { $ret["vendor"]['vendor_sum'] = bcadd(floatval($ret["vendor"]['vendor_sum']), floatval($opi_money_v['vendor_sum'])) ; } else { $ret["vendor"]['trippest_sum'] = bcadd(floatval($ret["vendor"]['trippest_sum']), floatval($opi_money_v['trippest_sum'])) ; $ret["vendor"]['trippest_sum'] = bcadd(floatval($ret["vendor"]['trippest_sum']), floatval($opi_money_v['vendor_sum'])) ; } $ret['vendor']['other_sum'] = bcadd($ret['vendor']['other_sum'], $opi_money_v['other_price_sum']); $ret['vendor']['other_sum_cost'] = bcadd($ret['vendor']['other_sum_cost'], $opi_money_v['other_cost_sum']); $ret["vendor"]['trippest_sum'] = bcsub($ret["vendor"]['trippest_sum'], $opi_money_v['other_price_sum']); } $ret["vendor"]["transfer_sum"] = bcsub($ret["vendor"]['vendor_sum'], $ret["trippest"]['vendor_sum']); if ($ret["vendor"]["transfer_sum"] != 0) { $result['transfer_sum'] = bcadd($result['transfer_sum'], $ret["vendor"]["transfer_sum"]); $result['trippest_order_vendor_money'] = array_merge($result['trippest_order_vendor_money'], $this->money_model->trippest_order_with_vendormoney($vendor, $sourcetype, $start_date, $end_date)); } $result["money"][strval($vendor)] = $ret; $result["money"][strval($vendor)]["vendor_code"] = $vendor; $result["money"][strval($vendor)]["vendor_name"] = $vendor_sourcetype[strval($vendor)]["vendor_name"]; /** 团款合计 */ $result['col_sum']['trippest']['sum_trippest_sum'] = bcadd( bcadd($result['col_sum']['trippest']['sum_trippest_sum'], $ret["trippest"]['trippest_sum']) ,$ret['trippest']['other_sum']); $result['col_sum']['trippest']['sum_vendor_sum'] = bcadd($result['col_sum']['trippest']['sum_vendor_sum'], $ret["trippest"]['vendor_sum']); $result['col_sum']['trippest']['sum_other'] = bcadd($result['col_sum']['trippest']['sum_other'], $ret['trippest']['other_sum']); $result['col_sum']['vendor']['sum_trippest_sum'] = bcadd( bcadd($result['col_sum']['vendor']['sum_trippest_sum'], $ret["vendor"]['trippest_sum']) ,$ret['vendor']['other_sum']); $result['col_sum']['vendor']['sum_vendor_sum'] = bcadd($result['col_sum']['vendor']['sum_vendor_sum'], $ret["vendor"]['vendor_sum']); $result['col_sum']['vendor']['sum_other'] = bcadd($result['col_sum']['vendor']['sum_other'], $ret['vendor']['other_sum']); } /** 成本 */ $vendors_cost = $this->money_model->vendor_cost(implode(',', $vendors), $start_date, $end_date); foreach ($result['money'] as $km => &$vm) { $vm['vendor_cost'] = $vm['trippest_cost'] = 0; foreach ($vendors_cost as $kvc => $vvc) { if (strval($vm['vendor_code']) === strval($vvc['vendor_code'])) { $vm['vendor_cost'] = $vvc['vendor_cost']; } } // 成本总计 $result['col_sum']['trippest']['sum_trippest_cost'] = $result['col_sum']['vendor']['sum_trippest_cost'] = bcadd($result['col_sum']['trippest']['sum_trippest_cost'], $vm['trippest_cost']); $result['col_sum']['trippest']['sum_vendor_cost'] = $result['col_sum']['vendor']['sum_vendor_cost'] = bcadd( bcadd($result['col_sum']['trippest']['sum_vendor_cost'], $vm['vendor_cost']) ,$vm['trippest']['other_sum_cost']); } foreach ($result['money'] as $kmi => &$vmi) { /** 利润 */ $vmi['trippest']['total_profit'] = bcsub( bcadd(bcadd($vmi['trippest']['trippest_sum'], $vmi['trippest']['vendor_sum']),$vmi['trippest']['other_sum']), bcadd(bcadd($vmi['trippest_cost'], $vmi['vendor_cost']),$vmi['trippest']['other_sum_cost'])); $vmi['vendor']['total_profit'] = bcsub( bcadd(bcadd($vmi['vendor']['trippest_sum'], $vmi['vendor']['vendor_sum']),$vmi['vendor']['other_sum']), bcadd(bcadd($vmi['trippest_cost'], $vmi['vendor_cost']),$vmi['vendor']['other_sum_cost'])); /** 利润分成 */ $vmi['trippest']['vendor_profit'] = bcmul($vmi['trippest']['total_profit'], $vendor_sourcetype[strval($vmi['vendor_code'])]["profit_rate"]); $vmi['trippest']['trippest_profit'] = bcmul($vmi['trippest']['total_profit'], bcsub(1, $vendor_sourcetype[strval($vmi['vendor_code'])]["profit_rate"]) ); $vmi['vendor']['vendor_profit'] = bcmul($vmi['vendor']['total_profit'], $vendor_sourcetype[strval($vmi['vendor_code'])]["profit_rate"]); $vmi['vendor']['trippest_profit'] = bcmul($vmi['vendor']['total_profit'], bcsub(1, $vendor_sourcetype[strval($vmi['vendor_code'])]["profit_rate"]) ); /** Trippest应付地接 */ $vmi['trippest']['payout'] = bcsub(bcadd($vmi['vendor_cost'], $vmi['trippest']['vendor_profit'] ), $vmi['trippest']['vendor_sum']); $vmi['vendor']['payout'] = bcsub(bcadd($vmi['vendor_cost'], $vmi['vendor']['vendor_profit'] ), $vmi['vendor']['vendor_sum']); /** 利润总计 */ $result['col_sum']['trippest']['sum_profit'] = bcadd($result['col_sum']['trippest']['sum_profit'], $vmi['trippest']['total_profit']); $result['col_sum']['trippest']['sum_trippest_profit'] = bcadd($result['col_sum']['trippest']['sum_trippest_profit'], $vmi['trippest']['trippest_profit']); $result['col_sum']['trippest']['sum_vendor_profit'] = bcadd($result['col_sum']['trippest']['sum_vendor_profit'], $vmi['trippest']['vendor_profit']); $result['col_sum']['vendor']['sum_profit'] = bcadd($result['col_sum']['vendor']['sum_profit'], $vmi['vendor']['total_profit']); $result['col_sum']['vendor']['sum_trippest_profit'] = bcadd($result['col_sum']['vendor']['sum_trippest_profit'], $vmi['vendor']['trippest_profit']); $result['col_sum']['vendor']['sum_vendor_profit'] = bcadd($result['col_sum']['vendor']['sum_vendor_profit'], $vmi['vendor']['vendor_profit']); /** 应付总计 */ $result['col_sum']['trippest']['sum_payout'] = bcadd($result['col_sum']['trippest']['sum_payout'], $vmi['trippest']['payout']); $result['col_sum']['vendor']['sum_payout'] = bcadd($result['col_sum']['vendor']['sum_payout'], $vmi['vendor']['payout']); } // return $this->output->set_content_type('application/json')->set_output(json_encode($result)); $this->load->view('vendor_money_sum', $result); return ; } } /* End of file vendor_money.php */ /* Location: ./third_party/trippestOrderSync/controllers/vendor_money.php */