Commit 737962ba authored by clone's avatar clone

1

parent 5767d450
......@@ -3,7 +3,10 @@
namespace app\api_broker\service;
use app\model\FApplyForFee;
use app\model\FCompanyData;
use app\model\FImg;
use app\model\FStoreCost;
use app\model\FStoreData;
/**
* Created by PhpStorm.
......@@ -160,18 +163,18 @@ class StoreFeeService
{
$image_array = explode(',', $id_string);
$result['status'] = 'fail';
$result['msg'] = '';
$result['msg'] = '';
if (!is_array($image_array) && !is_numeric($id_string)) {
$result['msg'] = '参数错误';
return $result;
}
$img_data = $this->imgModel->findByAll('id,img_name', ['id'=>['in', $id_string]]);
$num = 0;
$path = ROOT_PATH . 'public/';
foreach($img_data as $v) {
$num += $this->imgModel->editData(['img_status'=>1], $v['id']);
@unlink($path.'static/chat_image/'.$v['img_name']);
$img_data = $this->imgModel->findByAll('id,img_name', ['id' => ['in', $id_string]]);
$num = 0;
$path = ROOT_PATH . 'public/';
foreach ($img_data as $v) {
$num += $this->imgModel->editData(['is_del' => 1], $v['id']);
@unlink($path . 'static/chat_image/' . $v['img_name']);
}
if ($num) {
......@@ -182,30 +185,187 @@ class StoreFeeService
return $result;
}
/**
* 新增费用审核
*
* @param $data
* @param $img_id
* @return int|string
*/
public function saveImageData($data, $img_id)
public function calculateStoreFee($setting_date, $agent_id, $agent_name)
{
$num = 0;
foreach($data as $k => $v) {
if (empty($v)) {
continue;
$storeCostModel = new FStoreCost();
$storeCostModel->updateCost(["status" => 1], ["setting_date" => $setting_date]);// 修改掉之前的全部失效
$id = $storeCostModel->addCost(
$this->storeCostBin($setting_date, $agent_id, $agent_name)
);
if ($id > 0) {
$this->creationStoreFeeDetail($id, $setting_date);
}
return false;
}
public function creationStoreFeeDetail($cost_id, $setting_date)
{
$storeSettingInfo = $this->getStoreData($setting_date);
if (!$storeSettingInfo) {
return "当月门店数据未设置";
}
$companyDataInfo = $this->getCompanyData($setting_date);
if (!$companyDataInfo) {
return "当月公司数据未设置";
}
//todo 计算公司总考勤数 和分部考勤数
$companyAttendanceNum = $this->sumAttendanceNum(0, 1, $setting_date);
$districtAttendanceNum = $this->sumAttendanceNum(0, 2, $setting_date);
foreach ($storeSettingInfo as $key => $item) {
$applyForFeeArr = $this->getApplyForFee($item["store_id"], $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"];
switch ($value["type"]) {
case 1://办公室成本
$assume_fee = ceil($attendance_num / $officeAttendanceNum * 100) * $total_fee * 0.01;
break;
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;
}
break;
case 3:
break;
case 4:
break;
}
array_push($insertArr, $this->storeCostExtBin(
$cost_id
));
}
}
//insert
$save_data[$k]['img_id'] = $img_id;
$save_data[$k]['img_name'] = $v;
$save_data[$k]['img_type'] = 1;
}
}
if (isset($save_data)) {
$num = $this->imgModel->insertDataAll($save_data);
/**
* @param $id
* @param $type
* @param $setting_date
* @return float|int
*/
private function sumAttendanceNum($id, $type, $setting_date)
{
$storeDataModel = new FStoreData();
$params["is_del"] = 0;
$params["setting_date"] = $setting_date;
switch ($type) {
case 1://公司
return $storeDataModel->sumCompanyAttendance($params);
case 2://分部
return $storeDataModel->sumDistrictAttendance($params);
case 3://办公室
$params["office_id"] = $id;
return $storeDataModel->sumOfficeAttendance($params);
}
return 0;
}
return $num;
private function storeCostExtBin($cost_id, $type, $fee_item, $apply_for_id, $apply_for_time, $total_fee, $store_attendance_num,
$office_attendance_num, $district_attendance_num, $total_attendance_num, $assume_fee, $purpose)
{
$arr = [];
$arr["cost_id"] = $cost_id;
$arr["type"] = $type;
$arr["fee_item"] = $fee_item;
$arr["apply_for_id"] = $apply_for_id;
$arr["apply_for_time"] = $apply_for_time;
$arr["total_fee"] = $total_fee;
$arr["store_attendance_num"] = $store_attendance_num;
$arr["office_attendance_num"] = $office_attendance_num;
$arr["district_attendance_num"] = $district_attendance_num;
$arr["total_attendance_num"] = $total_attendance_num;
$arr["assume_fee"] = $assume_fee;
$arr["purpose"] = $purpose;
return $arr;
}
/**
* @param $store_id
* @param $setting_date
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function getApplyForFee($store_id, $setting_date)
{
$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";
$params["b.id"] = $store_id;
$params["a.count_time"] = $setting_date;
$params["a.is_del"] = 0;
$params["a.status"] = 4;
return $applyForFeeModel->getApplyForFeeList($field, $params);
}
/**
* @param $setting_date
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function getStoreData($setting_date)
{
$storeDataModel = new FStoreData();
$field = "id,setting_date,type,fixed_fee,apply_for_fee,discounts";
$params["is_del"] = 0;
$params["setting_date"] = $setting_date;
return $storeDataModel->selectStoreFee($field, $params);
}
/**
* @param $setting_date
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function getCompanyData($setting_date)
{
$companyData = new FCompanyData();
$field = "id,store_id,setting_date,is_discounts,social_security_fee,attendance_num,official_receipts,
last_official_receipts,deduct,transfer_charge";
$params["is_del"] = 0;
$params["setting_date"] = $setting_date;
return $companyData->selectCompanyData($field, $params);
}
/**
* @param $setting_date
* @param $agent_id
* @param $agent_name
* @return array
*/
private function storeCostBin($setting_date, $agent_id, $agent_name)
{
$arr = [];
$arr["setting_date"] = $setting_date;
$arr["operator_id"] = $agent_id;
$arr["operator_name"] = $agent_name;
$arr["create_time"] = date("Y-m-d H:i:s", time());
$arr["update_time"] = date("Y-m-d H:i:s", time());
return $arr;
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -78,6 +78,22 @@ class FApplyForFee extends BaseModel
->where($params)
->count('a.id');
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getApplyForFeeList($field,$params){
return $this->db_
->field($field)
->alias("a")
->join("f_apply_for_fee b","a.store_id = b.id","left")
->where($params)
->select();
}
/**
* @param $field
......
......@@ -60,4 +60,18 @@ class FCompanyData extends BaseModel
{
return $this->db_->update($params);
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectCompanyData($field,$params){
return $this->db_
->field($field)
->where($params)
->select();
}
}
......@@ -18,16 +18,38 @@ class FStoreCost extends BaseModel
/**
* 新增数据
* @param $data
* @return mixed
* @param $params
* @return int
*/
public function saveOffice($data) {
$time = date("Y-m-d H:i:s", time());
$data["is_del"] = 0;
$data['create_time'] = $time;
$data['update_time'] = $time;
return $this->db_->insert($data);
public function addCost($params)
{
Db::startTrans();
try {
$id = $this->db_->insertGetId($params);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* @param $where
* @param $params
* @return int
*/
public function updateCost($where,$params)
{
Db::startTrans();
try {
$this->where($where)->update($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
......
......@@ -35,6 +35,9 @@ class FStoreData 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) {
$result = $this->db_
......@@ -44,13 +47,71 @@ class FStoreData extends BaseModel
return $result;
}
/**
* 更新数据
/**更新数据
* @param $params
* @return int|string
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function updateStoreData($params)
{
return $this->db_->update($params);
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectStoreFee($field,$params){
return $this->db_
->field($field)
->where($params)
->select();
}
public function sumCompanyAttendance($params){
return $this->db_
->field("sum(attendance_num) as num")
->where($params)
->select();
}
public function sumDistrictAttendance($params){
$where_ = [];
if(isset($params["is_del"])){
$where_["a.is_del"] = $params["is_del"];
}
if(isset($params["setting_date"])){
$where_["a.setting_date"] = $params["setting_date"];
}
return $this->db_
->field("sum(a.attendance_num) as num,b.site_id")
->alias("a")
->join("a_store b","a.store_id = b.id","left")
->where($where_)
->group("b.site_id")
->select();
}
public function sumOfficeAttendance($params){
$where_ = [];
if(isset($params["is_del"])){
$where_["a.is_del"] = $params["is_del"];
}
if(isset($params["setting_date"])){
$where_["a.setting_date"] = $params["setting_date"];
}
if(isset($params["office_id"])){
$where_["b.office_id"] = $params["office_id"];
}
return $this->db_
->field("sum(a.attendance_num) as num")
->alias("a")
->join("a_store b","a.store_id = b.id","left")
->where($where_)
->select();
}
}
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