Commit 0fff9cca authored by clone's avatar clone

1

parent 6401a0c2
...@@ -86,12 +86,12 @@ class StoreFeeService ...@@ -86,12 +86,12 @@ class StoreFeeService
* @throws \app\model\Exception * @throws \app\model\Exception
*/ */
public function addApplyForPC($type, $fee_item, $total_fee, $agent_id, $store_id, $purpose, $site_id, $card_name, public function addApplyForPC($type, $fee_item, $total_fee, $agent_id, $store_id, $purpose, $site_id, $card_name,
$bank, $card_no, $count_time, $img_arr, $id = 0, $office_id = 0, $status = 0) $bank, $card_no, $count_time, $img_arr, $id = 0, $office_id = 0, $status = 0)
{ {
$arr = $this->applyForFeeBin($id, $type, $fee_item, $total_fee, $agent_id, $store_id, $purpose, $site_id, $card_name, $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, $status); $bank, $card_no, $count_time, $office_id, $status);
if ($id) { if ($id) {
$this->applyForFeeModel->updateData($arr, ['id'=>$id]); $this->applyForFeeModel->updateData($arr, ['id' => $id]);
$feeId = $id; $feeId = $id;
} else { } else {
$feeId = $this->applyForFeeModel->saveData($arr); $feeId = $this->applyForFeeModel->saveData($arr);
...@@ -232,10 +232,19 @@ class StoreFeeService ...@@ -232,10 +232,19 @@ class StoreFeeService
return $result; return $result;
} }
/**
* @param $setting_date
* @param $agent_id
* @param $agent_name
* @return bool|int|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function calculateStoreFee($setting_date, $agent_id, $agent_name) public function calculateStoreFee($setting_date, $agent_id, $agent_name)
{ {
$storeCostModel = new FStoreCost(); $storeCostModel = new FStoreCost();
$storeCostModel->updateCost(["status" => 1], ["setting_date" => $setting_date]);// 修改掉之前的全部失效 $storeCostModel->updateCost(["setting_date" => $setting_date], ["status" => 1]);// 修改掉之前的全部失效
$id = $storeCostModel->addCost( $id = $storeCostModel->addCost(
$this->storeCostBin($setting_date, $agent_id, $agent_name) $this->storeCostBin($setting_date, $agent_id, $agent_name)
); );
...@@ -245,6 +254,14 @@ class StoreFeeService ...@@ -245,6 +254,14 @@ class StoreFeeService
return false; return false;
} }
/**
* @param $cost_id
* @param $setting_date
* @return int|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function creationStoreFeeDetail($cost_id, $setting_date) public function creationStoreFeeDetail($cost_id, $setting_date)
{ {
$storeSettingInfo = $this->getStoreData($setting_date); $storeSettingInfo = $this->getStoreData($setting_date);
...@@ -257,7 +274,7 @@ class StoreFeeService ...@@ -257,7 +274,7 @@ class StoreFeeService
} }
$tree = []; $tree = [];
foreach ($companyDataInfo as $i => $j) { foreach ($companyDataInfo as $i => $j) {
$tree[$j["type"]][] = $j; $tree[$j["type"]] = $j;
} }
//todo 计算公司总考勤数 和分部考勤数 //todo 计算公司总考勤数 和分部考勤数
$companyAttendanceNum = $this->sumAttendanceNum(0, 1, $setting_date); $companyAttendanceNum = $this->sumAttendanceNum(0, 1, $setting_date);
...@@ -266,8 +283,10 @@ class StoreFeeService ...@@ -266,8 +283,10 @@ class StoreFeeService
foreach ($storeSettingInfo as $key => $item) { foreach ($storeSettingInfo as $key => $item) {
$applyForFeeArr = $this->getApplyForFee($item["store_id"], $setting_date); $applyForFeeArr = $this->getApplyForFee($item["store_id"], $setting_date);
$site_id = $applyForFeeArr[0]["site_id"]; $site_id = $applyForFeeArr[0]["site_id"];
$districtNum = $districtAttendanceNum[$site_id]["num"];//区域考勤人数
$attendance_num = $item["attendance_num"];//门店参与考勤人数 $attendance_num = $item["attendance_num"];//门店参与考勤人数
$officeAttendanceNum = $this->sumAttendanceNum($item["store_id"], 3, $setting_date);//办公室参与考勤人数 $officeAttendanceNum = $this->sumAttendanceNum($item["store_id"], 3, $setting_date);//办公室参与考勤人数
$discountsNum = $discountsNum * $tree[0]["discounts"] * 0.01;
$insertArr = []; $insertArr = [];
if ($applyForFeeArr) { if ($applyForFeeArr) {
foreach ($applyForFeeArr as $k => $value) { foreach ($applyForFeeArr as $k => $value) {
...@@ -280,19 +299,8 @@ class StoreFeeService ...@@ -280,19 +299,8 @@ class StoreFeeService
$assume_fee = 0; $assume_fee = 0;
switch ($value["type"]) { switch ($value["type"]) {
case 1://办公室成本 case 1://办公室成本
$assume_fee = ceil($attendance_num / $officeAttendanceNum * 100) * $total_fee * 0.01; $assume_fee = ceil($attendance_num * 100 / $officeAttendanceNum) * $total_fee * 0.01;
break;
/* case 2:
//公司总考勤减去所有计算折扣的门店人数
$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; break;
case 3:
$assume_fee = ceil($attendance_num * 100 / $districtAttendanceNum) * $total_fee * 0.01;
break;*/
case 5://门店独有成本 case 5://门店独有成本
$assume_fee = $total_fee; $assume_fee = $total_fee;
break; break;
...@@ -301,7 +309,7 @@ class StoreFeeService ...@@ -301,7 +309,7 @@ class StoreFeeService
} }
array_push($insertArr, $this->storeCostExtBin( array_push($insertArr, $this->storeCostExtBin(
$cost_id, $type, $fee_item, $apply_for_id, $apply_for_time, $cost_id, $type, $fee_item, $apply_for_id, $apply_for_time,
$total_fee, $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum, $total_fee, $attendance_num, $officeAttendanceNum, $districtNum, $companyAttendanceNum,
$assume_fee, $purpose $assume_fee, $purpose
)); ));
} }
...@@ -309,82 +317,96 @@ class StoreFeeService ...@@ -309,82 +317,96 @@ class StoreFeeService
//门店租金 //门店租金
$storeModel = new AStore(); $storeModel = new AStore();
$rent = $storeModel->getStoreCost("b.id,b.rent", ["a.id" => $item["store_id"]]); $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"], array_push($insertArr, $this->storeCostExtBin($cost_id, 1, 100, 0, $item["create_time"],
$rent["rent"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum, $rent["rent"], $attendance_num, $officeAttendanceNum, $districtNum, $companyAttendanceNum,
ceil($attendance_num * 100 / $officeAttendanceNum) * $rent["rent"] * 0.01, "" ceil($attendance_num * 100 / $officeAttendanceNum) * $rent["rent"] * 0.01, ""
)); ));
//上海总部固定成本 门店是上海的只承担总部成本,否则承担总部和分部成本
//上海总部固定成本 门店是上海的只承担总部成本,否则承担总部和分部成本
//上海 //上海
$attendance_discount = $attendance_num;
if ($item["is_discounts"] == 1) {
$attendance_discount = $attendance_num * $tree[0]["discounts"] * 0.01;
}
$assume_fee1 = ceil($attendance_discount / ($companyAttendanceNum - $discountsNum) * $tree[0]["fixed_fee"] * 100) * 0.01;
$assume_fee2 = ceil($attendance_discount / ($companyAttendanceNum - $discountsNum) * $tree[0]["apply_for_fee"] * 100) * 0.01;
array_push($insertArr, $this->storeCostExtBin($cost_id, 2, 201, 0, $tree[0]["create_time"], array_push($insertArr, $this->storeCostExtBin($cost_id, 2, 201, 0, $tree[0]["create_time"],
$tree[0]["fixed_fee"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum - $discountsNum, $tree[0]["fixed_fee"], $attendance_discount, $officeAttendanceNum, $districtNum, $companyAttendanceNum - $discountsNum,
ceil($attendance_num * $tree[0]["discounts"] / $officeAttendanceNum - $discountsNum) * $tree[0]["fixed_fee"] * 0.01, "" $assume_fee1, ""
)); ));
array_push($insertArr, $this->storeCostExtBin($cost_id, 2, 202, 0, $tree[0]["create_time"], 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, $tree[0]["apply_for_fee"], $attendance_discount, $officeAttendanceNum, $districtNum, $companyAttendanceNum - $discountsNum,
ceil($attendance_num * $tree[0]["discounts"] / $officeAttendanceNum - $discountsNum) * $tree[0]["apply_for_fee"] * 0.01, "" $assume_fee2, ""
)); ));
$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;
if ($site_id != 10001) {
$create_time = "";
$rent_fixed = $apply_for_fee = 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;
}
//分部
$disc_assume_fee1 = ceil($attendance_num / $officeAttendanceNum * $apply_for_fee * 100) * 0.01;
$disc_assume_fee2 = ceil($attendance_num / $officeAttendanceNum * $apply_for_fee * 100) * 0.01;
array_push($insertArr, $this->storeCostExtBin($cost_id, 3, 301, 0, $create_time,
$rent_fixed, $attendance_num, $officeAttendanceNum, $districtNum, $companyAttendanceNum,
$disc_assume_fee1, ""
));
array_push($insertArr, $this->storeCostExtBin($cost_id, 3, 302, 0, $create_time,
$apply_for_fee, $attendance_num, $officeAttendanceNum, $districtNum, $companyAttendanceNum,
$disc_assume_fee2, ""
));
} }
//分部
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"], array_push($insertArr, $this->storeCostExtBin($cost_id, 4, 401, 0, $tree[4]["create_time"],
$tree[0]["fixed_fee"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum, 0, $attendance_num, $officeAttendanceNum, $districtNum, $companyAttendanceNum,
$attendance_num * $tree[4]["fixed_fee"], "" $attendance_num * $tree[4]["fixed_fee"], ""
)); ));
//社保报销费用 //社保报销费用
array_push($insertArr, $this->storeCostExtBin($cost_id, 5, 502, 0, $item["create_time"], 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"], $attendance_num, $officeAttendanceNum, $districtNum, $companyAttendanceNum,
$item["social_security_fee"], "" $item["social_security_fee"], ""
)); ));
//总经理基薪 //总经理基薪
array_push($insertArr, $this->storeCostExtBin($cost_id, 5, 503, 0, $tree[6]["create_time"], 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"], $attendance_num, $officeAttendanceNum, $districtNum, $companyAttendanceNum,
$tree[6]["fixed_fee"], "" $tree[6]["fixed_fee"], ""
)); ));
//手续费 //手续费
array_push($insertArr, $this->storeCostExtBin($cost_id, 5, 509, 0, $item["create_time"], array_push($insertArr, $this->storeCostExtBin($cost_id, 5, 509, 0, $item["create_time"],
$item["transfer_charge"], $attendance_num, $officeAttendanceNum, $districtAttendanceNum, $companyAttendanceNum, $item["transfer_charge"], $attendance_num, $officeAttendanceNum, $districtNum, $companyAttendanceNum,
$item["transfer_charge"], "" $item["transfer_charge"], ""
)); ));
} }
//insert
$storeCostExtModel = new FStoreCostExt(); $storeCostExtModel = new FStoreCostExt();
$is_ok = $storeCostExtModel->addCostExt($insertArr); $is_ok = $storeCostExtModel->addCostExt($insertArr);
if($is_ok){ if ($is_ok) {
return 1; return 1;
}else{ } else {
return "数据保存异常"; return "数据保存异常";
} }
...@@ -406,17 +428,25 @@ class StoreFeeService ...@@ -406,17 +428,25 @@ class StoreFeeService
$params["setting_date"] = $setting_date; $params["setting_date"] = $setting_date;
switch ($type) { switch ($type) {
case 1://公司 case 1://公司
return $storeDataModel->sumCompanyAttendance($params); $result = $storeDataModel->sumCompanyAttendance($params);
return $result[0]["num"];
case 2://分部 case 2://分部
return $storeDataModel->sumDistrictAttendance($params); $result = $storeDataModel->sumDistrictAttendance($params);
$data = [];
foreach ($result as $key => $value) {
$data[$value["site_id"]] = $value;
}
return $data;
case 3://办公室 case 3://办公室
$storeModel = new AStore(); $storeModel = new AStore();
$storeInfo = $storeModel->getStore(["id" => $id], "office_id"); $storeInfo = $storeModel->getStore(["id" => $id], "office_id");
$params["office_id"] = $storeInfo[0]["office_id"]; $params["office_id"] = $storeInfo[0]["office_id"];
return $storeDataModel->sumOfficeAttendance($params); $result = $storeDataModel->sumOfficeAttendance($params);
return $result[0]["num"];
case 4://参与折扣的人数 case 4://参与折扣的人数
$params["is_discounts"] = 1; $params["is_discounts"] = 1;
return $storeDataModel->sumCompanyAttendance($params); $result = $storeDataModel->sumCompanyAttendance($params);
return $result[0]["num"];
} }
return 0; return 0;
} }
...@@ -437,6 +467,8 @@ class StoreFeeService ...@@ -437,6 +467,8 @@ class StoreFeeService
$arr["total_attendance_num"] = $total_attendance_num; $arr["total_attendance_num"] = $total_attendance_num;
$arr["assume_fee"] = $assume_fee; $arr["assume_fee"] = $assume_fee;
$arr["purpose"] = $purpose; $arr["purpose"] = $purpose;
$arr["create_time"] = date("Y-m-d H:i:s", time());
$arr["update_time"] = date("Y-m-d H:i:s", time());
return $arr; return $arr;
} }
...@@ -470,7 +502,8 @@ class StoreFeeService ...@@ -470,7 +502,8 @@ class StoreFeeService
private function getStoreData($setting_date) private function getStoreData($setting_date)
{ {
$storeDataModel = new FStoreData(); $storeDataModel = new FStoreData();
$field = "id,setting_date,type,fixed_fee,apply_for_fee,discounts,create_time"; $field = "id,store_id,setting_date,is_discounts,social_security_fee,attendance_num,official_receipts,
last_official_receipts,deduct,transfer_charge,create_time";
$params["is_del"] = 0; $params["is_del"] = 0;
$params["setting_date"] = $setting_date; $params["setting_date"] = $setting_date;
return $storeDataModel->selectStoreFee($field, $params); return $storeDataModel->selectStoreFee($field, $params);
...@@ -486,8 +519,7 @@ class StoreFeeService ...@@ -486,8 +519,7 @@ class StoreFeeService
private function getCompanyData($setting_date) private function getCompanyData($setting_date)
{ {
$companyData = new FCompanyData(); $companyData = new FCompanyData();
$field = "id,store_id,setting_date,is_discounts,social_security_fee,attendance_num,official_receipts, $field = "id,setting_date,type,fixed_fee,apply_for_fee,discounts,create_time";
last_official_receipts,deduct,transfer_charge,create_time";
$params["is_del"] = 0; $params["is_del"] = 0;
$params["setting_date"] = $setting_date; $params["setting_date"] = $setting_date;
return $companyData->selectCompanyData($field, $params); return $companyData->selectCompanyData($field, $params);
......
...@@ -34,11 +34,11 @@ class StoreFee extends Basic ...@@ -34,11 +34,11 @@ class StoreFee extends Basic
public function creationStoreFee() public function creationStoreFee()
{ {
$params = $this->params; $params = $this->params;
$params = array( /* $params = array(
"setting_date" => "2019-06-01", "setting_date" => "2019-06-01",
"agent_id" => 1, "agent_id" => 1,
); );*/
if (!$params["setting_date"] || !$params["agent_id"]) { if (!$params["setting_date"] || !$params["agent_id"]) {
return $this->response("101", "请求参数错误 "); return $this->response("101", "请求参数错误 ");
} }
......
...@@ -87,12 +87,14 @@ class FApplyForFee extends BaseModel ...@@ -87,12 +87,14 @@ class FApplyForFee extends BaseModel
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getApplyForFeeList($field,$params){ public function getApplyForFeeList($field,$params){
return $this->db_ $result = $this->db_
->field($field) ->field($field)
->alias("a") ->alias("a")
->join("a_store b","a.store_id = b.id","left") ->join("a_store b","a.store_id = b.id","left")
->where($params) ->where($params)
->select(); ->select();
// echo $this->db_->getLastSql();
return $result;
} }
/** /**
......
...@@ -24,6 +24,7 @@ class FStoreCostExt extends BaseModel ...@@ -24,6 +24,7 @@ class FStoreCostExt extends BaseModel
Db::commit(); Db::commit();
return 1; return 1;
} catch (\Exception $e) { } catch (\Exception $e) {
dump($e);
Db::rollback(); Db::rollback();
return 0; return 0;
} }
......
...@@ -550,6 +550,7 @@ Route::group('index', [ ...@@ -550,6 +550,7 @@ Route::group('index', [
'getApplyForFeeStore' => ['index/StoreFee/getApplyForFeeStore', ['method' => 'GET']],//获取费用承担办公室 'getApplyForFeeStore' => ['index/StoreFee/getApplyForFeeStore', ['method' => 'GET']],//获取费用承担办公室
'addFeeImage' => ['index/StoreFee/addFeeImage', ['method' => 'POST']],//新增报销申请图片 'addFeeImage' => ['index/StoreFee/addFeeImage', ['method' => 'POST']],//新增报销申请图片
'getStoreOffice' => ['index/Store/getStoreOffice', ['method' => 'GET']],//获取费用承担办公室 'getStoreOffice' => ['index/Store/getStoreOffice', ['method' => 'GET']],//获取费用承担办公室
'creationStoreFee' => [ 'index/StoreFee/creationStoreFee', [ 'method' => 'POST|GET' ] ],
'getStoreCostParameterList' => [ 'index/CostParameter/getStoreCostParameterList', [ 'method' => 'POST|GET' ] ], 'getStoreCostParameterList' => [ 'index/CostParameter/getStoreCostParameterList', [ 'method' => 'POST|GET' ] ],
'editCostParameter' => [ 'index/CostParameter/editCostParameter', [ 'method' => 'POST|GET' ] ], 'editCostParameter' => [ 'index/CostParameter/editCostParameter', [ 'method' => 'POST|GET' ] ],
......
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