Commit aeda6327 authored by clone's avatar clone

1

parent 70f4307d
......@@ -2,10 +2,13 @@
namespace app\api_broker\service;
use app\model\AStore;
use app\model\FApplyForFee;
use app\model\FCompanyData;
use app\model\FImg;
use app\model\FOffice;
use app\model\FStoreCost;
use app\model\FStoreCostExt;
use app\model\FStoreData;
/**
......@@ -49,7 +52,7 @@ class StoreFeeService
$arr = $this->applyForFeeBin($id, $type, $fee_item, $total_fee, $agent_id, $store_id, $purpose, $site_id, $card_name,
$bank, $card_no, $count_time, $office_id);
if ($id) {
$this->applyForFeeModel->updateData($arr, ['id'=>$id]);
$this->applyForFeeModel->updateData($arr, ['id' => $id]);
$feeId = $id;
} else {
$feeId = $this->applyForFeeModel->saveData($arr);
......@@ -237,7 +240,7 @@ class StoreFeeService
$this->storeCostBin($setting_date, $agent_id, $agent_name)
);
if ($id > 0) {
$this->creationStoreFeeDetail($id, $setting_date);
return $this->creationStoreFeeDetail($id, $setting_date);
}
return false;
}
......@@ -252,54 +255,144 @@ class StoreFeeService
if (!$companyDataInfo) {
return "当月公司数据未设置";
}
$tree = [];
foreach ($companyDataInfo as $i => $j) {
$tree[$j["type"]][] = $j;
}
//todo 计算公司总考勤数 和分部考勤数
$companyAttendanceNum = $this->sumAttendanceNum(0, 1, $setting_date);
$districtAttendanceNum = $this->sumAttendanceNum(0, 2, $setting_date);
$discountsNum = $this->sumAttendanceNum(0, 4, $setting_date);
foreach ($storeSettingInfo as $key => $item) {
$applyForFeeArr = $this->getApplyForFee($item["store_id"], $setting_date);
//门店
$site_id = $applyForFeeArr[0]["site_id"];
$attendance_num = $item["attendance_num"];//门店参与考勤人数
$officeAttendanceNum = $this->sumAttendanceNum($item["store_id"], 3, $setting_date);//办公室参与考勤人数
$insertArr = [];
if ($applyForFeeArr) {
foreach ($applyForFeeArr as $k => $value) {
$type = $value["type"];
$fee_item = $value["fee_item"];
$attendance_num = $value["attendance_num"];//门店参与考勤人数
$apply_for_id = $value["id"];
$apply_for_time = $value["create_time"];
$total_fee = $value["total_fee"];
$store_id = $value["old_store_id"];
$office_id = $value["old_office_id"];
$officeAttendanceNum = $this->sumAttendanceNum($office_id, 3, $setting_date);//办公室参与考勤人数
$purpose = $value["purpose"];
$assume_fee = 0;
switch ($value["type"]) {
case 1://办公室成本
$assume_fee = ceil($attendance_num / $officeAttendanceNum * 100) * $total_fee * 0.01;
break;
case 2:
/* case 2:
//公司总考勤减去所有计算折扣的门店人数
if($item["is_discounts"] == 1){
$attendance_num = $value["attendance_num"]/2;
$assume_fee = ceil($attendance_num / $officeAttendanceNum - 12312 * 100) * $total_fee * 0.01;
$companyAttendanceNum = $companyAttendanceNum - $discountsNum;
if ($item["is_discounts"] == 1) {
$attendance_num = $value["attendance_num"] / $tree[0]["discounts"] * 0.01;
}
$assume_fee = ceil($attendance_num * 100 / $companyAttendanceNum) * $total_fee * 0.01;
break;
case 3:
break;
case 4:
$assume_fee = ceil($attendance_num * 100 / $districtAttendanceNum) * $total_fee * 0.01;
break;*/
case 5://门店独有成本
$assume_fee = $total_fee;
break;
default:
continue;
}
array_push($insertArr, $this->storeCostExtBin(
$cost_id
$cost_id, $type, $fee_item, $apply_for_id, $apply_for_time,
$total_fee, $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum,
$assume_fee, $purpose
));
}
//todo 处理 房租租金 上海固定成本分部固定成本 发展基金社保报销 总经理薪资 手续费
//门店租金
$storeModel = new AStore();
$rent = $storeModel->getStoreCost("b.id,b.rent", ["a.id" => $item["store_id"]]);
array_push($insertArr, $this->storeCostExtBin($cost_id, 1, 100, 0, $item["create_time"],
$rent["rent"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum,
ceil($attendance_num * 100 / $officeAttendanceNum) * $rent["rent"] * 0.01, ""
));
//上海总部固定成本 门店是上海的只承担总部成本,否则承担总部和分部成本
//上海
array_push($insertArr, $this->storeCostExtBin($cost_id, 2, 201, 0, $tree[0]["create_time"],
$tree[0]["fixed_fee"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum - $discountsNum,
ceil($attendance_num * $tree[0]["discounts"] / $officeAttendanceNum - $discountsNum) * $tree[0]["fixed_fee"] * 0.01, ""
));
array_push($insertArr, $this->storeCostExtBin($cost_id, 2, 202, 0, $tree[0]["create_time"],
$tree[0]["apply_for_fee"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum - $discountsNum,
ceil($attendance_num * $tree[0]["discounts"] / $officeAttendanceNum - $discountsNum) * $tree[0]["apply_for_fee"] * 0.01, ""
));
$create_time = "";
$rent_fixed = 0;
switch ($site_id) {
case 10002:
$create_time = $tree[1]["create_time"];
$rent_fixed = $tree[1]["fixed_fee"];
$apply_for_fee = $tree[1]["apply_for_fee"];
break;
case 10003:
$create_time = $tree[2]["create_time"];
$rent_fixed = $tree[2]["fixed_fee"];
$apply_for_fee = $tree[2]["apply_for_fee"];
break;
case 10004:
$create_time = $tree[3]["create_time"];
$rent_fixed = $tree[3]["fixed_fee"];
$apply_for_fee = $tree[3]["apply_for_fee"];
break;
case 10005:
$create_time = $tree[4]["create_time"];
$rent_fixed = $tree[4]["fixed_fee"];
$apply_for_fee = $tree[4]["apply_for_fee"];
break;
}
//分部
array_push($insertArr, $this->storeCostExtBin($cost_id, 3, 301, 0, $create_time,
$rent_fixed, $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum,
ceil($attendance_num * 100 / $officeAttendanceNum) * $rent_fixed * 0.01, ""
));
array_push($insertArr, $this->storeCostExtBin($cost_id, 3, 302, 0, $create_time,
$apply_for_fee, $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum,
ceil($attendance_num * 100 / $officeAttendanceNum) * $apply_for_fee * 0.01, ""
));
//同联发展基金
array_push($insertArr, $this->storeCostExtBin($cost_id, 4, 401, 0, $tree[4]["create_time"],
$tree[0]["fixed_fee"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum,
$attendance_num * $tree[4]["fixed_fee"], ""
));
//社保报销费用
array_push($insertArr, $this->storeCostExtBin($cost_id, 5, 502, 0, $item["create_time"],
$item["social_security_fee"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum,
$item["social_security_fee"], ""
));
//总经理基薪
array_push($insertArr, $this->storeCostExtBin($cost_id, 5, 503, 0, $tree[6]["create_time"],
$tree[6]["fixed_fee"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum,
$tree[6]["fixed_fee"], ""
));
//手续费
array_push($insertArr, $this->storeCostExtBin($cost_id, 5, 509, 0, $item["create_time"],
$item["transfer_charge"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum,
$item["transfer_charge"], ""
));
}
//insert
$storeCostExtModel = new FStoreCostExt();
$is_ok = $storeCostExtModel->addCostExt($insertArr);
if($is_ok){
return 1;
}else{
return "数据保存异常";
}
}
}
/**
* @param $id
* @param $type
......@@ -317,8 +410,13 @@ class StoreFeeService
case 2://分部
return $storeDataModel->sumDistrictAttendance($params);
case 3://办公室
$params["office_id"] = $id;
$storeModel = new AStore();
$storeInfo = $storeModel->getStore(["id" => $id], "office_id");
$params["office_id"] = $storeInfo[0]["office_id"];
return $storeDataModel->sumOfficeAttendance($params);
case 4://参与折扣的人数
$params["is_discounts"] = 1;
return $storeDataModel->sumCompanyAttendance($params);
}
return 0;
}
......@@ -354,7 +452,7 @@ class StoreFeeService
{
$applyForFeeModel = new FApplyForFee();
$field = "a.id,a.type,a.fee_item,a.purpose,a.total_fee,a.office_id,a.agent_id,a.store_id,a.assume_fee,
a.status,a.count_time,a.site_id,a.create_time,b.id as old_store_id,b.office_id as old_office_id";
a.status,a.count_time,a.site_id,a.create_time,b.id as old_store_id,b.office_id as old_office_id,b.site_id";
$params["b.id"] = $store_id;
$params["a.count_time"] = $setting_date;
$params["a.is_del"] = 0;
......@@ -372,7 +470,7 @@ class StoreFeeService
private function getStoreData($setting_date)
{
$storeDataModel = new FStoreData();
$field = "id,setting_date,type,fixed_fee,apply_for_fee,discounts";
$field = "id,setting_date,type,fixed_fee,apply_for_fee,discounts,create_time";
$params["is_del"] = 0;
$params["setting_date"] = $setting_date;
return $storeDataModel->selectStoreFee($field, $params);
......@@ -389,7 +487,7 @@ class StoreFeeService
{
$companyData = new FCompanyData();
$field = "id,store_id,setting_date,is_discounts,social_security_fee,attendance_num,official_receipts,
last_official_receipts,deduct,transfer_charge";
last_official_receipts,deduct,transfer_charge,create_time";
$params["is_del"] = 0;
$params["setting_date"] = $setting_date;
return $companyData->selectCompanyData($field, $params);
......
......@@ -56,7 +56,12 @@ class StoreFee extends Basic
//todo 1.判断是否都审核过,
//todo 2.计算门店成本 3.总部成本,4.分部成本,5.同联发展基金 6门店单独成本
$this->service_->calculateStoreFee($setting_date, $agent_id,$agent_name);
$msg = $this->service_->calculateStoreFee($setting_date, $agent_id,$agent_name);
if($msg != 1){
return $this->response("101", $msg);
}else{
return $this->response("200", "success");
}
}
/**
......
......@@ -90,7 +90,7 @@ class FApplyForFee extends BaseModel
return $this->db_
->field($field)
->alias("a")
->join("f_apply_for_fee b","a.store_id = b.id","left")
->join("a_store b","a.store_id = b.id","left")
->where($params)
->select();
}
......
......@@ -35,6 +35,9 @@ class FOffice extends BaseModel
* @param $field
* @param $params
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function findByOne($field,$params) {
$params["is_del"] = 0;
......@@ -46,12 +49,15 @@ class FOffice extends BaseModel
return $result;
}
/**
* 查询数据
/**查询数据
* @param $field
* @param $params
* @param $pageNo
* @param $pageSize
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getOffice($field,$params,$pageNo, $pageSize)
{
......@@ -65,6 +71,11 @@ class FOffice extends BaseModel
return $result;
}
/**
* @param $field
* @param $params
* @return int|string
*/
public function getOfficeTotal($field,$params)
{
$params['is_del'] = 0;
......@@ -75,10 +86,11 @@ class FOffice extends BaseModel
return $result;
}
/**
* 更新数据
/**更新数据
* @param $params
* @return int|string
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function updateOffice($params)
{
......
......@@ -16,6 +16,18 @@ class FStoreCostExt extends BaseModel
$this->db_ = Db::name($this->table);
}
public function addCostExt($params)
{
Db::startTrans();
try {
$this->db_->insertAll($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* 查询数据
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment