Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
737962ba
Commit
737962ba
authored
Jul 23, 2019
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
5767d450
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
310 additions
and
36 deletions
+310
-36
StoreFeeService.php
application/api_broker/service/StoreFeeService.php
+186
-25
StoreFee.php
application/index/controller/StoreFee.php
+0
-0
FApplyForFee.php
application/model/FApplyForFee.php
+16
-0
FCompanyData.php
application/model/FCompanyData.php
+14
-0
FStoreCost.php
application/model/FStoreCost.php
+31
-9
FStoreData.php
application/model/FStoreData.php
+63
-2
No files found.
application/api_broker/service/StoreFeeService.php
View file @
737962ba
...
...
@@ -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
([
'i
mg_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
([
'i
s_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
application/index/controller/StoreFee.php
View file @
737962ba
This diff is collapsed.
Click to expand it.
application/model/FApplyForFee.php
View file @
737962ba
...
...
@@ -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
...
...
application/model/FCompanyData.php
View file @
737962ba
...
...
@@ -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
();
}
}
application/model/FStoreCost.php
View file @
737962ba
...
...
@@ -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
;
}
}
/**
...
...
application/model/FStoreData.php
View file @
737962ba
...
...
@@ -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
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment