Commit 737962ba authored by clone's avatar clone

1

parent 5767d450
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
namespace app\api_broker\service; namespace app\api_broker\service;
use app\model\FApplyForFee; use app\model\FApplyForFee;
use app\model\FCompanyData;
use app\model\FImg; use app\model\FImg;
use app\model\FStoreCost;
use app\model\FStoreData;
/** /**
* Created by PhpStorm. * Created by PhpStorm.
...@@ -166,12 +169,12 @@ class StoreFeeService ...@@ -166,12 +169,12 @@ class StoreFeeService
return $result; return $result;
} }
$img_data = $this->imgModel->findByAll('id,img_name', ['id'=>['in', $id_string]]); $img_data = $this->imgModel->findByAll('id,img_name', ['id' => ['in', $id_string]]);
$num = 0; $num = 0;
$path = ROOT_PATH . 'public/'; $path = ROOT_PATH . 'public/';
foreach($img_data as $v) { foreach ($img_data as $v) {
$num += $this->imgModel->editData(['img_status'=>1], $v['id']); $num += $this->imgModel->editData(['is_del' => 1], $v['id']);
@unlink($path.'static/chat_image/'.$v['img_name']); @unlink($path . 'static/chat_image/' . $v['img_name']);
} }
if ($num) { if ($num) {
...@@ -182,30 +185,187 @@ class StoreFeeService ...@@ -182,30 +185,187 @@ class StoreFeeService
return $result; return $result;
} }
public function calculateStoreFee($setting_date, $agent_id, $agent_name)
{
$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
}
}
/** /**
* 新增费用审核 * @param $id
* * @param $type
* @param $data * @param $setting_date
* @param $img_id * @return float|int
* @return int|string
*/ */
public function saveImageData($data, $img_id) private function sumAttendanceNum($id, $type, $setting_date)
{ {
$num = 0; $storeDataModel = new FStoreData();
foreach($data as $k => $v) { $params["is_del"] = 0;
if (empty($v)) { $params["setting_date"] = $setting_date;
continue; 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;
} }
$save_data[$k]['img_id'] = $img_id; private function storeCostExtBin($cost_id, $type, $fee_item, $apply_for_id, $apply_for_time, $total_fee, $store_attendance_num,
$save_data[$k]['img_name'] = $v; $office_attendance_num, $district_attendance_num, $total_attendance_num, $assume_fee, $purpose)
$save_data[$k]['img_type'] = 1; {
$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);
} }
if (isset($save_data)) { /**
$num = $this->imgModel->insertDataAll($save_data); * @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);
} }
return $num; /**
* @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
<?php <?php
namespace app\index\controller; namespace app\index\controller;
/** /**
* Created by PhpStorm. * Created by PhpStorm.
...@@ -8,6 +9,7 @@ namespace app\index\controller; ...@@ -8,6 +9,7 @@ namespace app\index\controller;
*/ */
use app\api_broker\service\RedisCacheService;
use app\api_broker\service\StoreFeeService; use app\api_broker\service\StoreFeeService;
use app\api_broker\validate\StoreFeeValidate; use app\api_broker\validate\StoreFeeValidate;
use app\index\extend\Basic; use app\index\extend\Basic;
...@@ -29,22 +31,32 @@ class StoreFee extends Basic ...@@ -29,22 +31,32 @@ class StoreFee extends Basic
$this->service_ = new StoreFeeService(); $this->service_ = new StoreFeeService();
} }
public function createStoreFee(){ 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", "请求参数错误 ");
} }
$setting_date = $params["setting_date"]; $setting_date = $params["setting_date"];
$agent_id = $params["agent_id"]; $agent_id = $params["agent_id"];
//todo 验证用户数据
$cache = new RedisCacheService();
$agent_info = $cache->getRedisCache(2, $agent_id);
if(!$agent_info){
return $this->response("101", "用户不存在 ");
}
$agent_name = $agent_info["name"];
//todo 1.判断是否都审核过, //todo 1.判断是否都审核过,
//todo 2.计算门店成本 3.总部成本,4.分部成本,5.同联发展基金 6门店单独成本 //todo 2.计算门店成本 3.总部成本,4.分部成本,5.同联发展基金 6门店单独成本
$this->service_->calculateStoreFee($setting_date,$agent_id); $this->service_->calculateStoreFee($setting_date, $agent_id,$agent_name);
} }
/** /**
...@@ -67,7 +79,7 @@ class StoreFee extends Basic ...@@ -67,7 +79,7 @@ class StoreFee extends Basic
return $this->response("101", $checkResult); return $this->response("101", $checkResult);
} }
$office = $this->getOffice('id',['office_name'=>$params['office_name']]); $office = $this->getOffice('id', ['office_name' => $params['office_name']]);
if ($office) { if ($office) {
return $this->response("101", '已存在该办公室!'); return $this->response("101", '已存在该办公室!');
} }
...@@ -109,7 +121,7 @@ class StoreFee extends Basic ...@@ -109,7 +121,7 @@ class StoreFee extends Basic
return $this->response("101", $checkResult); return $this->response("101", $checkResult);
} }
$office = $this->getOffice('id',['id'=>$params['id']]); $office = $this->getOffice('id', ['id' => $params['id']]);
if (!$office) { if (!$office) {
return $this->response("101", '不存在该办公室!'); return $this->response("101", '不存在该办公室!');
} }
...@@ -136,14 +148,14 @@ class StoreFee extends Basic ...@@ -136,14 +148,14 @@ class StoreFee extends Basic
$conditions = []; $conditions = [];
if (!empty($params['office_name'])) { if (!empty($params['office_name'])) {
$conditions['office_name'] = ['LIKE', '%'.$params['office_name'].'%']; $conditions['office_name'] = ['LIKE', '%' . $params['office_name'] . '%'];
} }
if (!empty($params['office_address'])) { if (!empty($params['office_address'])) {
$conditions['office_address'] = ['LIKE', '%'.$params['office_address'].'%']; $conditions['office_address'] = ['LIKE', '%' . $params['office_address'] . '%'];
} }
$field = 'id,rent,office_name,office_address,create_time,site_id'; $field = 'id,rent,office_name,office_address,create_time';
$result = $this->f_office->getOffice($field, $conditions,$pageNo, $pageSize); $result = $this->f_office->getOffice($field, $conditions, $pageNo, $pageSize);
if(!$result) if (!$result)
return $this->response("200", "成功", []); return $this->response("200", "成功", []);
$m_store = new AStore(); $m_store = new AStore();
...@@ -190,7 +202,7 @@ class StoreFee extends Basic ...@@ -190,7 +202,7 @@ class StoreFee extends Basic
* @param $conditions * @param $conditions
* @return array|false|\PDOStatement|string|\think\Model * @return array|false|\PDOStatement|string|\think\Model
*/ */
public function getOffice($field,$conditions) public function getOffice($field, $conditions)
{ {
$result = $this->f_office->findByOne($field, $conditions); $result = $this->f_office->findByOne($field, $conditions);
return $result; return $result;
...@@ -210,7 +222,7 @@ class StoreFee extends Basic ...@@ -210,7 +222,7 @@ class StoreFee extends Basic
if (true !== $checkResult) { if (true !== $checkResult) {
return $this->response("101", $checkResult); return $this->response("101", $checkResult);
} }
$office = $this->getOffice('id',['id'=>$params['id']]); $office = $this->getOffice('id', ['id' => $params['id']]);
if (!$office) { if (!$office) {
return $this->response("101", '不存在该办公室!'); return $this->response("101", '不存在该办公室!');
} }
...@@ -279,8 +291,8 @@ class StoreFee extends Basic ...@@ -279,8 +291,8 @@ class StoreFee extends Basic
$m_store = new AStore(); $m_store = new AStore();
$store_result = $m_store->getStore(['id'=>$params['store_id']], 'id'); $store_result = $m_store->getStore(['id' => $params['store_id']], 'id');
if(!$store_result) if (!$store_result)
return $this->response("101", "该门店不存在"); return $this->response("101", "该门店不存在");
if ($params['office_id'] == 0) { if ($params['office_id'] == 0) {
...@@ -290,9 +302,9 @@ class StoreFee extends Basic ...@@ -290,9 +302,9 @@ class StoreFee extends Basic
$return = $m_store->updateStore($conditions); $return = $m_store->updateStore($conditions);
} else { } else {
$store_params['id'] = $params['store_id']; $store_params['id'] = $params['store_id'];
$store_params['office_id'] = array('gt',0); $store_params['office_id'] = array('gt', 0);
$store_result = $m_store->getStore($store_params, 'id'); $store_result = $m_store->getStore($store_params, 'id');
if($store_result) if ($store_result)
return $this->response("101", "该门店已绑定或已绑定其他办公室"); return $this->response("101", "该门店已绑定或已绑定其他办公室");
//绑定 //绑定
...@@ -319,16 +331,16 @@ class StoreFee extends Basic ...@@ -319,16 +331,16 @@ class StoreFee extends Basic
$conditions = []; $conditions = [];
if (!empty($params['store_name'])) { if (!empty($params['store_name'])) {
$conditions['store_name'] = ['LIKE', '%'.$params['store_name'].'%']; $conditions['store_name'] = ['LIKE', '%' . $params['store_name'] . '%'];
} }
$m_store = new AStore(); $m_store = new AStore();
$store_field = 'id,store_name'; $store_field = 'id,store_name';
$store_result = $m_store->getStore($conditions, $store_field); $store_result = $m_store->getStore($conditions, $store_field);
if(!$store_result) if (!$store_result)
return $this->response("101", "成功",[]); return $this->response("101", "成功", []);
return $this->response("200", "成功",$store_result); return $this->response("200", "成功", $store_result);
} }
/** /**
...@@ -409,17 +421,18 @@ class StoreFee extends Basic ...@@ -409,17 +421,18 @@ class StoreFee extends Basic
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getApplyForFeeStore(){ public function getApplyForFeeStore()
{
$params = $this->params; $params = $this->params;
/* $params = array( /* $params = array(
"store_id" => 1 "store_id" => 1
);*/ );*/
$storeModel = new AStore(); $storeModel = new AStore();
$field = "a.id,b.office_address"; $field = "a.id,b.office_address";
$office_info = $storeModel->getStoreAndOffice($field,["store_id"=> $params["store_id"]]); $office_info = $storeModel->getStoreAndOffice($field, ["store_id" => $params["store_id"]]);
if($office_info){ if ($office_info) {
return $this->response("200", "request success", $office_info); return $this->response("200", "request success", $office_info);
}else{ } else {
return $this->response("101", "null"); return $this->response("101", "null");
} }
} }
......
...@@ -78,6 +78,22 @@ class FApplyForFee extends BaseModel ...@@ -78,6 +78,22 @@ class FApplyForFee extends BaseModel
->where($params) ->where($params)
->count('a.id'); ->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 * @param $field
......
...@@ -60,4 +60,18 @@ class FCompanyData extends BaseModel ...@@ -60,4 +60,18 @@ class FCompanyData extends BaseModel
{ {
return $this->db_->update($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 selectCompanyData($field,$params){
return $this->db_
->field($field)
->where($params)
->select();
}
} }
...@@ -18,16 +18,38 @@ class FStoreCost extends BaseModel ...@@ -18,16 +18,38 @@ class FStoreCost extends BaseModel
/** /**
* 新增数据 * @param $params
* @param $data * @return int
* @return mixed
*/ */
public function saveOffice($data) { public function addCost($params)
$time = date("Y-m-d H:i:s", time()); {
$data["is_del"] = 0; Db::startTrans();
$data['create_time'] = $time; try {
$data['update_time'] = $time; $id = $this->db_->insertGetId($params);
return $this->db_->insert($data); 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 ...@@ -35,6 +35,9 @@ class FStoreData extends BaseModel
* @param $field * @param $field
* @param $params * @param $params
* @return array|false|\PDOStatement|string|Model * @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) { public function findByOne($field,$params) {
$result = $this->db_ $result = $this->db_
...@@ -44,13 +47,71 @@ class FStoreData extends BaseModel ...@@ -44,13 +47,71 @@ class FStoreData extends BaseModel
return $result; return $result;
} }
/** /**更新数据
* 更新数据
* @param $params * @param $params
* @return int|string * @return int|string
* @throws \think\Exception
* @throws \think\exception\PDOException
*/ */
public function updateStoreData($params) public function updateStoreData($params)
{ {
return $this->db_->update($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