edit-order-settle_brand

This commit is contained in:
lccsw
2022-07-29 15:02:39 +08:00
parent c97afc0f97
commit 9d22ca859d
9 changed files with 794 additions and 39 deletions
+174
View File
@@ -0,0 +1,174 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Seprice extends HD_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('biz/biz_model');
$this->load->model('biz/biz_settle_price_model');
$this->load->model('auto/auto_business_model');
}
public function index()
{
$this->lists();
}
public function lists()
{
$params = $this->input->get();
$page = $params['page'] ? $params['page'] : 1;
$size = $params['size'] ? $params['size'] : 50;
!strlen($params['status']) && $params['status'] = '';
!strlen($params['year']) && $params['year'] = date('Y');
!strlen($params['month']) && $params['month'] = '';
$biz_row = $this->biz_model->get(['id'=>$params['biz_id']]);
if(!$biz_row){
return $this->show_json(SYS_CODE_FAIL,'参数错误');
}
$where = [
'biz_id' => $biz_row['id'],
'status>=' => 0,
'year' => date('Y')
];
strlen($params['status']) && $where['status'] = $params['status'];
strlen($params['year']) && $where['year'] = $params['year'];
strlen($params['month']) && $where['month'] = $params['month'];
$lists = [];
$total = $this->biz_settle_price_model->count($where);
if($total){
$rows = $this->biz_settle_price_model->select($where,'id desc',$page,$size);
foreach ($rows as $item) {
$temp = [
'id' => $item['id'],
'money_json' => $this->biz_settle_price_model->get_jsondata($item['money_json']),
'show_time' => "{$item['year']}-{$item['month']}",
'status' => $item['status'],
'status_cn' => $item['status'] ? '正常' : '禁用',
'c_time' => date('Y-m-d H:i',$item['c_time'])
];
$lists[] = $temp;
}
}
$this->data['yearAry'] = $this->auto_business_model->year();
$this->data['monthAry'] = $this->auto_business_model->month();
$this->data['params'] = $params;
$this->data['lists'] = $lists;
$this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page,'totle'=>$total);
$this->data['_title'] = "{$biz_row['biz_name']}-费用管理";
$this->show_view('biz/seprice/lists',true);
}
public function get(){
$params = $this->input->get();
$row = $this->biz_settle_price_model->get(['id'=>$params['id']]);
$info = [];
if($row){
$info['id'] = $row['id'];
$info['money_json'] = json_decode($row['money_json'],true);
$info['year'] = $row['year'];
$info['month'] = $row['month'];
$info['action'] = '/biz/seprice/edit';
$biz_id = $params['biz_id'];
}else{
$biz_row = $this->biz_model->get(['id'=>$params['biz_id']]);
if(!$biz_row){
return $this->show_json(SYS_CODE_FAIL,'参数错误');
}
$biz_id = $biz_row['id'];
$info['money_json'] = [
'rent' => '',
'base_manager' => '',
'base_employees' => '',
'wat_ele' => '',
'media' => '',
'marketing' => '',
'drive' => '',
'commission' => '',
'trucking' => ''
];
$info['year'] = date('Y');
$info['month'] = intval(date('m'));
$info['action'] = '/biz/seprice/add';
}
$info['biz_id'] = $biz_id;
$this->data['info'] = $info;
$this->data['yearAry'] = $this->auto_business_model->year();
$this->data['monthAry'] = $this->auto_business_model->month();
$this->show_view('biz/seprice/get');
}
public function add(){
$info = $this->input->post('info');
$biz_row = $this->biz_model->get(['id'=>$info['biz_id']]);
if(!$biz_row){
return $this->show_json(SYS_CODE_FAIL,'参数错误');
}
$data = [
'money_json' => json_encode($info['money_json'],JSON_UNESCAPED_UNICODE),
'biz_id' => $info['biz_id'],
'year' => $info['year'],
'month' => $info['month'],
'c_time' => time()
];
$res = $this->biz_settle_price_model->add($data);
if($res){
return $this->show_json(SYS_CODE_SUCCESS,'保存成功');
}else{
return $this->show_json(SYS_CODE_FAIL,'保存失败');
}
}
public function edit(){
$info = $this->input->post('info');
$row = $this->biz_settle_price_model->get(['id'=>$info['id']]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL,'参数错误');
}
$data = [
'money_json' => json_encode($info['money_json'],JSON_UNESCAPED_UNICODE),
'year' => $info['year'],
'month' => $info['month'],
];
$res = $this->biz_settle_price_model->update($data,['id'=>$info['id']]);
if($res){
return $this->show_json(SYS_CODE_SUCCESS,'保存成功');
}else{
return $this->show_json(SYS_CODE_FAIL,'保存失败');
}
}
public function edit_status(){
$id = $this->input->post('id');
$value = $this->input->post('value');
$row = $this->biz_settle_price_model->get(['id'=>$id]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL,'参数错误');
}
$update = [
'status' => $value ? 0 : 1
];
$res = $this->biz_settle_price_model->update($update,['id'=>$id]);
if($res){
return $this->show_json(SYS_CODE_SUCCESS,'保存成功');
}else{
return $this->show_json(SYS_CODE_FAIL,'保存失败');
}
}
public function del()
{
}
public function batch()
{
}
public function export(){
}
}
+5 -6
View File
@@ -5,11 +5,6 @@ require_once COMMPATH.'third_party/PHPExcel.php';
class Settle extends HD_Controller
{
private $biz_type = [
1 => ['liche' => 0.25 , 'partner' => 0.75],
2 => ['liche' => 0.35 , 'partner' => 0.65],
];
public function __construct()
{
parent::__construct();
@@ -26,6 +21,8 @@ class Settle extends HD_Controller
$this->load->model('biz/biz_settle_static_model');
$this->load->model('biz/biz_info_model');
$this->load->model('biz/biz_trucking_model');
$_biz_type = $this->input->get('_biz_type');
$_SESSION['is_brand'] = $_biz_type==1 ? $_biz_type : '';
}
public function index()
@@ -370,6 +367,7 @@ class Settle extends HD_Controller
$temp['total_need'] = $v['rent'] + $v['wat_ele'] + $v['manager_wage'] + $v['employee_wage'] + $v['commission'] + $v['price_trucking'];
$temp['price_ml'] = $v['price_total'] - $temp['total_need'];
$temp['profix_partner'] = $v['profix_partner'] + $v['profix_partner_oflow'];
$temp['money_json'] = json_decode($v['money_json'],true);
$lists[] = $temp;
}
}
@@ -381,7 +379,8 @@ class Settle extends HD_Controller
$this->data['type_arr'] = $this->biz_settle_static_model->other_price_type();
$this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page,'totle'=>$total);
$this->data['_title'] = '商家结算管理';
$this->show_view('biz/settle/lists_static',true);
$view = $_SESSION['is_brand'] ? 'biz/settle/lists_static_brand' : 'biz/settle/lists_static';
$this->show_view($view,true);
}
+140
View File
@@ -0,0 +1,140 @@
<form id="vue-edit" class="am-form am-form-horizontal tab-content" action="/biz/seprice/edit" data-auto="true" method="post" style="width: 90%;padding:25px 30px 20px 0;margin: 0 auto;">
<div class="tab-pane fade in active">
<div class="am-form-group wp50 fl">
<label class="am-para-label">房租:</label>
<div class="am-para-input">
<input type="number" placeholder="房租" v-model="info.money_json.rent">
</div>
</div>
<div class="am-form-group wp50 fl">
<label class="am-para-label">店长底薪:</label>
<div class="am-para-input">
<input type="number" placeholder="店长底薪" v-model="info.money_json.base_manager"/>
</div>
</div>
<div class="am-form-group wp50 fl">
<label class="am-para-label">销售底薪:</label>
<div class="am-para-input">
<input type="number" placeholder="销售底薪" v-model="info.money_json.base_employees"/>
</div>
</div>
<div class="am-form-group wp50 fl">
<label class="am-para-label">水电物业:</label>
<div class="am-para-input">
<input type="number" placeholder="水电物业" v-model="info.money_json.wat_ele"/>
</div>
</div>
<div class="am-form-group wp50 fl">
<label class="am-para-label">垂直媒体:</label>
<div class="am-para-input">
<input type="number" placeholder="垂直媒体" v-model="info.money_json.media"/>
</div>
</div>
<div class="am-form-group wp50 fl">
<label class="am-para-label">市场营销费:</label>
<div class="am-para-input">
<input type="number" placeholder="市场营销费" v-model="info.money_json.marketing"/>
</div>
</div>
<div class="am-form-group wp50 fl">
<label class="am-para-label">试驾车租金:</label>
<div class="am-para-input">
<input type="number" placeholder="试驾车租金" v-model="info.money_json.drive"/>
</div>
</div>
<div class="am-form-group wp50 fl">
<label class="am-para-label">销售提成:</label>
<div class="am-para-input">
<input type="number" placeholder="销售提成" v-model="info.money_json.commission"/>
</div>
</div>
<div class="am-form-group wp50 fl">
<label class="am-para-label">拖车费:</label>
<div class="am-para-input">
<input type="number" placeholder="拖车费" v-model="info.money_json.trucking"/>
</div>
</div>
<div class="am-form-group wp50">
<label class="am-para-label">日期:</label>
<div class="am-para-input">
<select name="year" style="display: inline; width: 100px;" v-model="info.year">
<option value=""></option>
<option :value="v" v-for="(v,i) in yearAry">{{v}}</option>
</select>
<select name="month" style="display: inline; width: 100px;" v-model="info.month">
<option value="">月份</option>
<option :value="v" v-for="(v,i) in monthAry">{{v}}</option>
</select>
</div>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 2rem">
<div class="am-para-input"><button class="am-btn am-btn-secondary" type="button" @click="saveEdit">保存</button></div>
</div>
</form>
<script>
var loading = 0;
var vue_obj;
$(function(){
vue_obj = new Vue({
el: '#vue-edit',
data: {
info : [],
action:'',
yearAry:[],
monthAry:[],
},
mounted:function(){
var vm = this;
vm.info = <?=json_encode($info)?>;
vm.action = '<?=$info['action']?>';
vm.yearAry = <?=json_encode($yearAry)?>;
vm.monthAry = <?=json_encode($monthAry)?>;
},
methods:{
saveEdit:function(){
var vm = this;
if(1 == loading){
return 0;
}
loading = 1;
$.ajax({
url: vm.action,
type: 'post',
dataType: 'json',
data: {info:vm.info},
beforeSend: function () {
layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function (data) {
loading = 0;
if (data['code']) {
layer.msg(data.msg, {
icon: 1,
time: 2000
}, function () {
layer.closeAll();
$.form.reload();
});
} else {
layer.msg(data.msg, {icon: 2});
}
},
complete: function () {
loading = 0;
layer.closeAll('loading');
}
});
}
},
watch:{
}
});
});
</script>
+111
View File
@@ -0,0 +1,111 @@
<div class="coms-table-wrap mt10" id="vue-app">
<form class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="/biz/seprice/lists">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w80">状态:</label>
<div class="am-para-inline w100">
<select name="status" v-model="params.status">
<option value="">请选择</option>
<option value="1">正常</option>
<option value="0">禁用</option>
</select>
</div>
</div>
<div class="am-form-group fl">
<label class="am-para-label">年月:</label>
<div class="am-para-inline">
<div class="am-para-inline w70">
<select name="year" v-model="params.year">
<option value="">全部</option>
<option :value="v" v-for="(v,i) in yearAry">{{v}}</option>
</select>
</div>
<div class="am-para-inline w60">
<select name="month" v-model="params.month">
<option value="">全部</option>
<option :value="v" v-for="(v,i) in monthAry">{{v}}</option>
</select>
</div>
</div>
</div>
<div class="am-form-group fl ml20">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
<div class="am-form-group fl ml20">
<input type="hidden" name="biz_id" v-model="params.biz_id">
<button data-title="新增" type="button" :data-modal="'/biz/seprice/get?biz_id='+params.biz_id" class="am-btn am-btn-success am-btn-sm w100">
新增
</button>
</div>
</div>
</form>
<div class="coms-table-bd">
<div class="fr">共有<?= $pager['totle'] ?>条数据</div>
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="8%"><span>ID</span></th>
<th width="20%"><span>费用明细</span></th>
<th width="10%"><span>有效月份</span></th>
<th width="8%"><span>状态</span></th>
<th width="10%"><span>创建时间</span></th>
<th width="15%"><span>操作</span></th>
</tr>
</thead>
<tbody>
<tr v-for="item in lists">
<td>{{item.id}}</td>
<td>
<template v-for="(val,key) in item.money_json">{{key}}:{{val}}<br></template>
</td>
<td>{{item.show_time}}</td>
<td>{{item.status_cn}}</td>
<td>{{item.c_time}}</td>
<td>
<a href="javascript:void(0);" :data-modal="'/biz/seprice/get?id='+item.id" class="am-btn am-btn-primary am-btn-xs">编辑</a>
<template v-if="item.status==1">
<a :data-update="item.id" data-action="/biz/seprice/edit_status" :data-value="item.status" class="am-btn am-btn-danger am-btn-xs">禁用</a>
</template>
<template v-else>
<a :data-update="item.id" data-action="/biz/seprice/edit_status" :data-value="item.status" class="am-btn am-btn-success am-btn-xs">启用</a>
</template>
</td>
</tr>
</tbody>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
var vm = new Vue({
el: '#vue-app',
data: {
params: [],
lists:[],
yearAry:[],
monthAry:[],
},
mounted: function () {
var vm = this
vm.params = <?=json_encode($params,JSON_UNESCAPED_UNICODE)?>;
vm.lists = <?=json_encode($lists,JSON_UNESCAPED_UNICODE)?>;
vm.yearAry = <?=json_encode($yearAry)?>;
vm.monthAry = <?=json_encode($monthAry)?>;
},
methods: {
},
watch: {
'params.type': function (nv, ov) {
}
}
});
$(function () {
<?php page_script($pager) ?>
});
</script>
@@ -0,0 +1,133 @@
<div class="coms-table-wrap">
<div class="coms-table-hd clearfix no-border">
<form action="/biz/settle/lists_static" class="form-search" onsubmit="return false">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label">年月:</label>
<div class="am-para-inline">
<div class="am-para-inline w70">
<select name="year" v-model="params.year">
<option value="">全部</option>
<option :value="v" v-for="(v,i) in yearAry">{{v}}</option>
</select>
</div>
<div class="am-para-inline w60">
<select name="month" v-model="params.month">
<option value="">全部</option>
<option :value="v" v-for="(v,i) in monthAry">{{v}}</option>
</select>
</div>
</div>
</div>
<div class="am-form-group fl ml20">
<input type="hidden" value="<?=$params['id']?>" name="id">
<button type="submit" class="am-btn am-btn-sm am-btn-success w100">搜索</button>
</div>
<div class="am-form-group fl ml20">
<button type="button" id="export" class="am-btn am-btn-sm am-btn-success w100">导出</button>
</div>
</div>
</form> </div>
<div class="coms-table-bd">
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="5%">
<span>ID</span>
</th>
<th width="10%"><span>门店</span></th>
<th width="10%"><span>单车总毛利</span></th>
<th width="10%"><span>服务费</span></th>
<th width="10%"><span>佣金</span></th>
<th width="10%"><span>门店费用</span></th>
<th width="10%"><span>精品</span></th>
<th width="10%"><span>其它费用</span></th>
<th width="10%"><span>总利润</span></th>
<th width="10%"><span>分润</span></th>
<th width="6%"><span>时间</span></th>
</tr>
</thead>
<tbody>
<template v-for="(v,i) in lists">
<tr>
<td>
<span>{{v.id}}</span>
</td>
<td>{{v.biz_name}}</td>
<td>{{v.profix_car}}</td>
<td></td>
<td></td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>{{v.price_ml}}</td>
<td>
狸车分润:{{v.profix_liche}}<br>
品牌店分润:{{v.profix_partner}}
</td>
<td>{{v.month_str}}</td>
</tr>
<tr>
<td colspan="11">
<a :data-open="'biz/settle?biz_id='+v.biz_id+'&month='+v.month" href="javascript:;">查看明细</a>
</td>
</tr>
</template>
</tbody>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
require(['laydate'], function (laydate) {
laydate.render({
elem: '#id-time',
format:'yyyy-MM'
});
});
var vue_obj;
var loading = 0;
$(function(){
vue_obj = new Vue({
el: '.coms-table-wrap',
data: {
params:[],
lists:[],
yearAry :[],
monthAry :[],
type_arr : [],
},
mounted:function() {
var vm = this;
vm.lists = <?=json_encode($lists)?>;
vm.params = <?=json_encode($params)?>;
vm.yearAry = <?=json_encode($yearAry)?>;
vm.monthAry = <?=json_encode($monthAry)?>;
vm.type_arr = <?=json_encode($type_arr)?>;
},
methods:{
},
watch:{
}
});
$('#export').on('click', function () {
var href = $.menu.parseUri(window.location.href);
var count = <?=$pager['totle']?>;
layer.msg('导出中请耐心等待几秒钟......');
href = href.replace("lists_static?", "export?");
window.location.href = href;
});
<?php page_script($pager) ?>
});
</script>
+7 -1
View File
@@ -1,5 +1,6 @@
<form id="vue-edit" class="am-form am-form-horizontal" :action="action" data-auto="true" method="post"
style="width: 90%;padding-top: 10px">
<template v-if="info.biz_type==2">
<div class="am-form-group">
<label class="am-para-label">联系人:</label>
<div class="am-para-input w300">
@@ -20,13 +21,17 @@
</select>
</div>
</div>
</template>
<div class="am-form-group">
<label class="am-para-label">分佣比例:</label>
<div class="am-para-input">
合伙人:<input type="text" style="width:90px;display:inline" placeholder="0~100" name="" v-model="info.rate"/>%&nbsp;&nbsp;&nbsp;&nbsp;
<template v-if="info.biz_type==2">合伙人</template>
<template v-else>品牌店</template>
<input type="text" style="width:90px;display:inline" placeholder="0~100" name="" v-model="info.rate"/>%&nbsp;&nbsp;&nbsp;&nbsp;
狸车:<span>{{100-info.rate}}%</span> (说明:有效值0~100,输入数值的百分比)
</div>
</div>
<template v-if="info.biz_type==2">
<div class="am-form-group">
<label class="am-para-label">保证金:</label>
<div class="am-para-input w150">
@@ -101,6 +106,7 @@
autocomplete="off" v-model="info.e_time"/>
</div>
</div>
</template>
<div class="am-form-group" style="margin-bottom: 2rem">
<div class="am-para-input">
<button class="am-btn am-btn-secondary" type="button" @click="saveEdit">保存</button>
+6 -2
View File
@@ -159,15 +159,19 @@
<a data-open="/biz/fine/lists?id=<?= $v['id'] ?>"
class="am-btn am-btn-primary am-btn-xs">精品配置
</a>
<a data-open="/biz/seprice/lists?biz_id=<?= $v['id'] ?>"
class="am-btn am-btn-primary am-btn-xs">费用管理
</a>
<a data-open="/biz/srv/lists?id=<?= $v['id'] ?>"
class="am-btn am-btn-primary am-btn-xs">水平业务配置</a>
class="am-btn am-btn-primary am-btn-xs">水平业务配置
</a>
<?}?>
<?if(in_array($v['type'],[1,2])){?>
<a data-open="/biz/store/store/get_info?id=<?= $v['id'] ?>"
class="am-btn am-btn-primary am-btn-xs">基本信息</a>
<?}?>
<?if(in_array($v['type'],[1,2,3])){?>
<a data-open="/biz/settle/lists_static?id=<?= $v['id'] ?>"
<a data-open="/biz/settle/lists_static?id=<?= $v['id'] ?>&_biz_type=<?=$v['type']?>"
class="am-btn am-btn-primary am-btn-xs">结算统计</a>
<?}?>
<a data-open="/biz/situation/get?id=<?= $v['id'] ?>"
+163 -30
View File
@@ -16,6 +16,7 @@ class Biz extends HD_Controller
$this->load->model('biz/biz_settle_static_model');
$this->load->model('biz/biz_settle_srv_model');
$this->load->model('biz/biz_trucking_model');
$this->load->model('biz/biz_settle_price_model');
$this->load->model('sys/sys_finance_model');
$this->load->library('receiver/orders_v2_entity');
@@ -182,6 +183,7 @@ class Biz extends HD_Controller
//品牌店统计
public function settle_brand(){
$id = $this->input->get('id');
$size = $this->input->get('size');
!$size && $size = 5;
@@ -196,6 +198,7 @@ class Biz extends HD_Controller
"$t2.id is null" => null,
"$t3.type" => 1,
];
$id && $where["{$t1}.id"] = $id;
$this->db->from("$t1");
$this->db->join("$t2", "$t2.o_id=$t1.id",'left');
$this->db->join("$t3", "$t3.id=$t1.biz_id",'left');
@@ -209,31 +212,41 @@ class Biz extends HD_Controller
foreach($rows as $key=>$val){
$info_json = json_decode($val['info_json'],true);
$money_json = json_decode($val['money_json'],true);
$settle_money_json = [];
$settle_money_json['in'] = [ //收入
'profix_car' => 0, //整车
'srv_price' => $this->orders_v2_entity->order_srv_money($val['id']), //服务费
'commission' => 0, //佣金
];
$settle_money_json['out'] = [ //成本
// 'biz_price' => 0', //门店成本
'apply_price' => 0, //申请成本
'fine_price' => 0, //赠送精品成本
];
//获取创建订单时商务政策
$where = [
'id' => $info_json['business_id'],
];
$b_row_one = $this->auto_business_model->get($where);
$truck_row = $this->biz_trucking_model->get(['auto_b_id'=>$val['brand_id'],'biz_id'=>$val['biz_id'],'status'=>1]);
$price_trucking = $truck_row['money'] ? $truck_row['money'] : 0;
$settle_money_json['in']['profix_car'] = $b_row_one['profix_car'] ? $b_row_one['profix_car'] : 0;
//挂牌利润 = 实收 - 成本
$profix_carno = 0;
if($money_json['fee_carno']>0){
$where = [
'biz_id' => $val['biz_id'],
'type' => 1,
'status' => 1,
's_effect_time>=' => date('Y-m-01',$val['c_time']),
's_effect_time<=' => date('Y-m-t',$val['c_time']),
];
$free_row = $this->biz_settle_srv_model->get($where);
if(!$free_row){
$free_row = $this->biz_settle_srv_model->get(['biz_id'=>$val['biz_id'],'is_def'=>1,'status'=>1,'type'=>1]);
}
$free_jsondata = json_decode($free_row['jsondata'],true);
$cb_fee_carno = $free_jsondata['price'] ? $free_jsondata['price'] : 0;
$profix_carno = $money_json['fee_carno'] - $cb_fee_carno;
}
// $profix_carno = 0;
// if($money_json['fee_carno']>0){
// $where = [
// 'biz_id' => $val['biz_id'],
// 'type' => 1,
// 'status' => 1,
// 's_effect_time>=' => date('Y-m-01',$val['c_time']),
// 's_effect_time<=' => date('Y-m-t',$val['c_time']),
// ];
// $free_row = $this->biz_settle_srv_model->get($where);
// if(!$free_row){
// $free_row = $this->biz_settle_srv_model->get(['biz_id'=>$val['biz_id'],'is_def'=>1,'status'=>1,'type'=>1]);
// }
// $free_jsondata = json_decode($free_row['jsondata'],true);
// $cb_fee_carno = $free_jsondata['price'] ? $free_jsondata['price'] : 0;
// $profix_carno = $money_json['fee_carno'] - $cb_fee_carno;
// }
//保险利润 = 金额(是否含税) * 返点百分比(保险类型):保险生效日
$agent_row = $this->order_agents_model->get(['o_id'=>$val['id']]);
$agent_json = json_decode($agent_row['jsondata'],true);
@@ -259,7 +272,9 @@ class Biz extends HD_Controller
$profix_insuer_bis = floatval($money_json['business_risk'])*$bis_fd;
$profix_insuer = $profix_insuer_ins + $profix_insuer_bis;
//贷款利润 = 手续费 + 贷款金额 * 返点(对应产品)
$profix_loan = floatval($money_json['price_finance']);
// $profix_loan = floatval($money_json['price_finance']);
//贷款佣金 = 贷款金额 * 返点(对应产品)
$profix_loan = 0;
if($money_json['price_loan']>=0){
$loan_row = $this->order_loans_model->get(['o_id'=>$val['id']]);
$finance_id = $val['finance_id'];
@@ -276,8 +291,9 @@ class Biz extends HD_Controller
}
$fd_jsondata = json_decode($fd_row['jsondata'],true);
$loan_fd = $fd_jsondata['rebate'] ? $fd_jsondata['rebate']/100:0;
$profix_loan += $money_json['price_loan']*$loan_fd;
$profix_loan = $money_json['price_loan']*$loan_fd;
}
$settle_money_json['in']['commission'] = $profix_loan+$profix_insuer;
//实收 - 成本(赠送的也要算)
$profix_fine = 0;
$fines = json_decode($val['fines'],true);
@@ -289,21 +305,32 @@ class Biz extends HD_Controller
];
$fines_ids && $cb_sum = $this->receiver_fine_model->sum('price',$where);
$cb = $cb_sum['price'] ? $cb_sum['price'] : 0; //成本
$sh = 0; //实收
foreach ($fines as $f_val) {
$sh += floatval($f_val['price']);
}
$profix_fine = $sh-$cb;
// $sh = 0; //实收
// foreach ($fines as $f_val) {
// $sh += floatval($f_val['price']);
// }
$profix_fine = $cb;
}
$settle_money_json['out']['biz_price'] = $profix_fine;
// $biz_price = 0;//门店成本
// $p_where = [
// 'biz_id' => $val['biz_id'],
// 'status' => 1,
// 'year' => date('Y',$val['c_time']),
// 'month' => date('m',$val['c_time']),
// ];
// $price_row = $this->biz_settle_price_model->get($p_where);
// $price_row && $biz_price = $this->biz_settle_price_model->sum_jsondata($price_row['jsondata']);
// $settle_money_json['out']['biz_price'] = $biz_price;
$add_data = [
'biz_id' => $val['biz_id'],
'o_id' => $val['id'],
'profix_car' => $b_row_one['profix_car'] ? $b_row_one['profix_car'] : 0,
'profix_car' => $settle_money_json['in']['profix_car'],
'profix_insure' => $profix_insuer,
'profix_loan' => $profix_loan,
'profix_carno' => $profix_carno,
'price_trucking' => $price_trucking,
'profix_fine' => $profix_fine,
// 'profix_carno' => $profix_carno,
// 'profix_fine' => $profix_fine,
'money_json' => json_encode($settle_money_json,JSON_UNESCAPED_UNICODE),
'year' => date('Y'),
'month' => intval(date('m')),
'c_time' => time()
@@ -318,4 +345,110 @@ class Biz extends HD_Controller
}
}
//统计前一个月利润
public function merge_brand(){
$size = $this->input->get('size');
$page = 1;
!$size && $size = 5;
$where = [
"year" => date('Y',strtotime("last month")),
"month" => intval(date('m',strtotime('last day of - 1 months'))),
"stic_id" => 0
];
$rows = $this->biz_settle_model->select($where,'id asc',$page,$size);
if($rows){
foreach($rows as $key=>$val){
$settle_money_json = json_decode($val['money_json'],true);
$where = [
'biz_id' => $val['biz_id'],
'year' => $val['year'],
'month' => $val['month']
];
$static_row = $this->biz_settle_static_model->get($where);
$price_all = $val['profix_insure']+$val['profix_loan']+$val['profix_carno'];
if(!$static_row){
$data = [
'biz_id' => $val['biz_id'],
'profix_car' => $val['profix_car'],
'year' => $val['year'],
'month' => $val['month'],
'c_time' => time()
];
$add_money_json['in'] = [ //收入
'profix_car' => $val['profix_car'], //整车
'srv_price' => $settle_money_json['srv_price'], //服务费
'commission' => $settle_money_json['commission'], //佣金
];
$biz_price = 0;//门店成本
$p_where = [
'biz_id' => $val['biz_id'],
'status' => 1,
'year' => date('Y',$val['year']),
'month' => date('m',$val['month']),
];
$price_row = $this->biz_settle_price_model->get($p_where);
$price_row && $biz_price = $this->biz_settle_price_model->sum_jsondata($price_row['jsondata']);
$add_money_json['out'] = [ //成本
'biz_price' => $biz_price, //门店成本
'apply_price' => $settle_money_json['apply_price'], //申请成本
'fine_price' => $settle_money_json['fine_price'], //赠送精品成本
];
$data['money_json'] = json_encode($add_money_json,JSON_UNESCAPED_UNICODE);
$stic_id = $this->biz_settle_static_model->add($data);
if($stic_id){
$this->biz_settle_model->update(['stic_id'=>$stic_id],['id'=>$val['id']]);
}
}else{
$static_money_json = json_decode($static_row['money_json'],true);
$data = [
'profix_car' => $static_row['profix_car'] + $val['profix_car'],
];
$out = $static_money_json['out'];
$in = $static_money_json['in'];
$add_money_json['in'] = [ //收入
'profix_car' => $val['profix_car'] + $in['profix_car'], //整车
'srv_price' => $settle_money_json['srv_price'] + $in['profix_car'], //服务费
'commission' => $settle_money_json['commission'] + $in['commission'], //佣金
];
$add_money_json['out'] = [ //成本
'biz_price' => $out['biz_price'], //门店成本
'apply_price' => $settle_money_json['apply_price']+$out['apply_price'], //申请成本
'fine_price' => $settle_money_json['fine_price'] + $out['fine_price'], //赠送精品成本
];
$data['money_json'] = json_encode($add_money_json,JSON_UNESCAPED_UNICODE);
$res = $this->biz_settle_static_model->update($data,['id'=>$static_row['id']]);
if($res){
$this->biz_settle_model->update(['stic_id'=>$static_row['id']],['id'=>$val['id']]);
}
}
}
}else{
//计算分润
$where = [
'price_total' => 0.00
];
$rows = $this->biz_settle_static_model->select($where,'id asc',$page,$size);
if($rows){
foreach($rows as $val){
$money_json = json_decode($val['money_json'],true);
$biz_info = $this->biz_info_model->get(['biz_id'=>$val['biz_id']]);
$in = $money_json['in'];
$out = $money_json['out'];
$in_price = $in['profix_car']+$in['srv_price']+$in['commission'];
$out_price = $out['biz_price']+$out['apply_price']+$out['fine_price'];
$price_need = $in_price-$out_price;
$partner_rate = $biz_info['rate']/100;
$liche_rate = (100-$biz_info['rate'])/100;
$data['profix_liche'] = $price_need*$liche_rate;
$data['profix_partner'] = $price_need*$partner_rate;
$data['price_total'] = $in_price-$out_price;
$this->biz_settle_static_model->update($data,['id'=>$val['id']]);
}
}else{
echo 'finish';
}
}
}
}
@@ -0,0 +1,55 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Biz_settle_price_model extends HD_Model
{
private $table_name = 'lc_biz_settle_price';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
/**
* @param $jsondata
* @return array
*/
public function get_jsondata($jsondata){
$jsondata = json_decode($jsondata,true);
$jsondata_cn = [
'rent' => '房租',
'base_manager' => '店长底薪',
'base_employees' => '销售底薪',
'wat_ele' => '水电物业',
'media' => '垂直媒体',
'marketing' => '市场营销费',
'drive' => '试驾车租金',
'commission' => '销售提成',
'trucking' => '拖车费',
];
$res = [];
if($jsondata){
foreach ($jsondata as $key=>$val) {
$key_cn = $jsondata_cn[$key] ? $jsondata_cn[$key] : $key;
$res[$key_cn] = $val;
}
}
return $res;
}
/**
* @param $jsondata
* @return int|mixed
*/
public function sum_jsondata($jsondata=[]){
$jsondata = json_decode($jsondata,true);
$res = 0;
if($jsondata){
foreach ($jsondata as $key=>$val) {
$res += $val;
}
}
return $res;
}
}