拼团成本计算

feature/pay
lyt 7 years ago
parent dff41407ce
commit 02d03a9f8d

@ -39,31 +39,96 @@ class Order_finance extends CI_Controller {
*/
public function single_order_report($coli_sn=0)
{
$ret = new stdClass();
$ret->combine_cost = array();
$combineNo_arr = $this->OrderFinance_model->get_order_combineNo($coli_sn);
$group_type_arr = array_unique(array_map(function($ele){return $ele->GCI_groupType;}, $combineNo_arr));
// $this->output->set_content_type('application/json')->set_output(json_encode($combineNo_arr));
// $this->output->set_content_type('application/json')->set_output(json_encode($group_type_arr));
foreach ($combineNo_arr as $kc => $vc) {
if ($vc->GCI_groupType == 1) {
$pvt_cost = $this->pvt_basic($vc->GCI_combineNo);
$ret->pvt = $pvt_cost = $this->pvt_basic($vc->GCI_combineNo);
} else if ($vc->GCI_groupType == 2) {
$combine_cost = $this->combine_basic($vc->GCI_combineNo);
$ret->combine_cost[] = $this->combine_basic($vc->GCI_combineNo, $coli_sn);
}
}
$this->output->set_content_type('application/json')->set_output(json_encode($ret));
return;
}
/*!
* 基本拼团
* * 仅含有一个产品
* @example 180712534
* 拼团计算
* @example 180426360,180516007U
* @date 2018-07-18
* @param string $combineNo
* @return [type] [description]
*/
public function combine_basic($combineNo="")
public function combine_basic($combineNo="", $coli_sn=0)
{
# code...
$ret = new stdClass();
$all_orders = $this->OrderFinance_model->get_all_combine_order($combineNo);
if (empty($all_orders)) {
return null;
}
// $ret->s = $all_orders;
$all_pags = array_map(function($ele){ return $ele->PAG_Code;}, $all_orders);
$all_pag = array_unique($all_pags);
// $ret->c = $all_pag;
$combine_pag_arr = array();
if (count($all_pag) > 1) {
// 多个产品, 找出拼团产品号
$rid_code = array();
$value_count = array_count_values($all_pags);
foreach ($all_pag as $kp => $vp) {
$tmp = null;
$tmp = $this->get_allowed_combine($vp);
// $ret->b = array_diff($tmp, $all_pag);
if (empty(array_diff($tmp, $all_pag))) {
$combine_pag_arr[] = $tmp;
}
// $ret->e = $value_count;
if($value_count[$vp] > 1) {
$rid_code[] = $vp;
}
}
// $ret->d = $rid_code;
if ( ! empty($rid_code)) {
$combine_pag_arr[] = $rid_code;
}
} else {
// 单个产品
$combine_pag_arr[] = ($all_pag);
}
bcscale(2);
$ret->combine_pags = my_array_unique($combine_pag_arr);
$ret->combine_pags = $ret->combine_pags[0]; // 这里用0是因为一个拼团应该只有一组或一个产品
// $ret->q = my_array_unique($combine_pag_arr);
$ret->tour_count = $ret->person_num = 0;
$ret->PAG_Code = "";
$ret->order_cost = array();
foreach ($all_orders as $ko => $vo) {
if (in_array($vo->PAG_Code, $ret->combine_pags)) {
// $ret->tour_count++;
$ret->person_num += $vo->COLD_PersonNum + $vo->COLD_ChildNum;
$ret->startdate = $vo->COLD_StartDate;
$tour_s = new stdClass();
if ($vo->COLI_SN == $coli_sn) {
$tour_s->person_num = $vo->COLD_PersonNum + $vo->COLD_ChildNum;
$ret->order_cost[] = $tour_s;
}
}
}
$ret->PAG_Code = implode(",", $ret->combine_pags);
$ret->comment = "拼团" . $combineNo . ", 按" . $ret->person_num . "人等";
$combine_cost = $this->OrderFinance_model->get_combine_sumMoney($combineNo);
$ret->cost_category = $combine_cost->cost_category;
$ret->cost_sum = $combine_cost->cost_sum;
$ret->person_cost = bcdiv($ret->cost_sum, $ret->person_num);
foreach ($ret->order_cost as $kc => $voc) {
$ret->order_cost[$kc]->order_cost_sum = bcmul($voc->person_num, $ret->person_cost);
}
return $ret;
// return $this->output->set_content_type('application/json')->set_output(json_encode($ret, JSON_UNESCAPED_UNICODE));
}
/*!
@ -90,19 +155,19 @@ class Order_finance extends CI_Controller {
$tour_s->cost_category = $combine_cost->cost_category;
$tour_s->cost_sum = $combine_cost->cost_sum;
$tour_s->person_cost = bcdiv($tour_s->cost_sum, $ret->person_num);
$tour_s->comment = "PVT,共" . $ret->person_num . "人";// 150
$tour_s->comment = "PVT,共" . $ret->person_num . "人";// 150
$pag_sns = array_values(array_unique(array_map(function($ele) {return $ele->COLD_ServiceSN;}, $all_orders)));
$pags_info = $this->OrderFinance_model->get_pag_info(implode(',', $pag_sns));
$tour_s->PAG_Code = substr(implode(",", array_values(array_unique(array_map(function($ele) {return $ele->PAG_Code;}, $pags_info)))), 0, 50) ; // TODO 限制50
$tour_s->PAG_Code = implode(",", array_values(array_unique(array_map(function($ele) {return $ele->PAG_Code;}, $pags_info)))); // TODO 限制50
$tour_s->vendor_name = implode(",", array_values(array_unique(array_map(function($ele) {return $ele->VEI2_CompanyBN;}, $pags_info)))) ; // 50
$tour_s->pag_name = substr(implode(";\r\n", array_map(function($ele) {return $ele->PAG_Title;}, $pags_info)), 0, 200) ; // TODO 限制200
$tour_s->pag_name = implode(";\r\n", array_map(function($ele) {return $ele->PAG_Title;}, $pags_info)) ; // TODO 限制200 用mb_substr('UTF-8')
$ret->tour[0] = $tour_s;
if ( $ret->tour_count > 1 ) {
} else {
}
// if ( $ret->tour_count > 1 ) {
// } else {
// }
$ret->order_cost = array_sum(array_map(function($ele) {return $ele->cost_sum;}, $ret->tour));
$this->output->set_content_type('application/json')->set_output(json_encode($ret));
return;
return $ret;
// return $this->output->set_content_type('application/json')->set_output(json_encode($ret, JSON_UNESCAPED_UNICODE));
}
/*!

@ -55,6 +55,7 @@ class OrderFinance_model extends CI_Model {
$ret->cost_category['guiderOperations'] = 0;
$ret->cost_category['touristCarOperations'] = 0;
$ret->cost_category['sceneryOperations'] = 0;
$ret->cost_category['restraurantOperations'] = 0;
foreach ($ret->cost_detail as $key => $value) {
if ($value->GCOD_operationType=='otherCosts' && $value->GCOD_subType=='客人水费') {
$ret->cost_category['water'] += $value->cost;

Loading…
Cancel
Save