Commit b05eaf7e authored by zhuwei's avatar zhuwei

门店费用参数

parent 09b0cd91
...@@ -6,10 +6,13 @@ use app\api_broker\service\RedisCacheService; ...@@ -6,10 +6,13 @@ use app\api_broker\service\RedisCacheService;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\api\service\ActivityService; use app\api\service\ActivityService;
use app\index\untils\ExportExcelUntil; use app\index\untils\ExportExcelUntil;
use app\model\AAgents;
use app\model\AStore; use app\model\AStore;
use app\model\CActivity; use app\model\CActivity;
use app\model\FApplyForFeeCheck; use app\model\FApplyForFeeCheck;
use app\model\FStoreCostExt; use app\model\FStoreCostExt;
use app\model\FStoreData;
use app\model\OPartialCommission;
use think\Request; use think\Request;
/** /**
...@@ -22,11 +25,13 @@ use think\Request; ...@@ -22,11 +25,13 @@ use think\Request;
class CostParameter extends Basic class CostParameter extends Basic
{ {
private $m_store; private $m_store;
private $m_store_data;
public function __construct(Request $request = null) public function __construct(Request $request = null)
{ {
parent::__construct($request); parent::__construct($request);
$this->m_store = new AStore(); $this->m_store = new AStore();
$this->m_store_data = new FStoreData();
} }
...@@ -38,9 +43,7 @@ class CostParameter extends Basic ...@@ -38,9 +43,7 @@ class CostParameter extends Basic
public function getStoreCostParameterList() public function getStoreCostParameterList()
{ {
$params = $this->params; $params = $this->params;
/* $params = array(
);*/
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo']; $pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize']; $pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
...@@ -51,25 +54,207 @@ class CostParameter extends Basic ...@@ -51,25 +54,207 @@ class CostParameter extends Basic
$conditions["a.id"] = $params["store_id"]; $conditions["a.id"] = $params["store_id"];
} }
$field = 'a.id,a.store_name,b.office_name,d.name,d.phone,c.is_discounts,
$field = 'a.id,a.store_name,b.office_name'; c.transfer_charge,c.social_security_fee,c.attendance_num,c.official_receipts,
c.last_official_receipts,c.deduct';
$list = $this->m_store->getStoreCostParameterList($field, $conditions, $pageNo, $pageSize); $list = $this->m_store->getStoreCostParameterList($field, $conditions, $pageNo, $pageSize);
if(!$list) if(!$list)
return $this->response("200", "success", []); return $this->response("200", "success", []);
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
// $list[$k]['type_name'] = $this->getTypeName($v['type']); $transfer_charge = $this->getTransferCharge(730);
$list[$k]['transfer_charge'] = $transfer_charge;//手续费
$social_security_fee = $this->getLastSocialSecurityFee(730);
$list[$k]['social_security_fee'] = $social_security_fee;//当月社保报销
$list[$k]['attendance_num'] = 0;//当月考勤
$list[$k]['official_receipts'] = 0;//当月合计总实收
$list[$k]['last_official_receipts'] = 0;//当月守护者实收
$list[$k]['deduct'] = 0;//盈利不足2万扣除
} }
$count = $this->m_store->getStoreCostParameterListTotal($field, $conditions); $count = $this->m_store->getStoreCostParameterListTotal($field, $conditions);
$result["list"] = $list; $result["list"] = $list;
$result["total"] = $count; $result["total"] = $count;
return $this->response("200", "success", $result); return $this->response("200", "success", $result);
} }
/**
* 获取该门店上个月的社保报销金额
* @param $store_id
* @return int|mixed
*/
public function getLastSocialSecurityFee($store_id){
$f_params['store_id'] = $store_id;
$f_params['setting_date'] = date('Y-m-01', strtotime('-2 month'));
$store_data_res = $this->m_store_data->findByOne('social_security_fee',$f_params);
if(
(isset($store_data_res['social_security_fee'])) &&
($store_data_res['social_security_fee']) &&
($store_data_res['social_security_fee'] > 0)
){
return $store_data_res['social_security_fee'];
}
return 0;
}
/**
* 获取手续费
* @param $store_id
* @return int
*/
public function getTransferCharge($store_id)
{
$agent_ids = $this->getUserIDList($store_id);
$transfer_charge = 0;
foreach ($agent_ids as $k => $v) {
$m_partial = new OPartialCommission();
$start_date = date('Y-m-01', strtotime('-1 month'));
$end_date = date('Y-m-t', strtotime('-1 month'));
$fields = 'sum( a.service_charge ) as service_charge';
$where['b.status']=array('in','10,11,13');
$where['a.is_del']=0;
$where['a.agent_id']=$v;
$where['a.create_time'] = ['between', [$start_date, $end_date]];
$list = $m_partial->getSumMoney($fields, $where);
if((isset($list['service_charge'])) && ($list['service_charge'] > 0))
$transfer_charge += $list['service_charge'];
}
return $transfer_charge;
}
/**
* 获取经纪人ID数组
* @param $store_id
* @return array
*/
public function getUserIDList($store_id)
{
$params = [];
$params["store_id"] = $store_id;
$params["status"] = 0;
$agentModel = new AAgents();
$agentsArr = $agentModel->getAgentsByStoreId($params);
$agent_total = count($agentsArr);
$agentIds = [];
if ($agent_total > 0) {
foreach ($agentsArr as $key1 => $value1) {
$agentIds[] = $value1["id"];
}
}
return $agentIds;
}
/**
* 编辑参数
* @return \think\Response
*/
public function editCostParameter()
{
$params = $this->params;
$params = array(
"store_id" => '1',
"setting_date" => '2019-07-23',
);
$checkResult = $this->validate($params, "CostParameterValidate.editCostParameter");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$f_params['store_id'] = $params['store_id'];
$f_params['setting_date'] = $params['setting_date'];
$store_data_res = $this->m_store_data->findByOne('id',$params);
if ($store_data_res) {//修改
$this->updateStoreData($store_data_res['id'],$params);
} else {//新增
$this->saveStoreData($params);
}
return $this->response("200", "成功");
}
/**
* 新增数据
* @param $params
* @return mixed
*/
public function saveStoreData($params){
$data['store_id'] = $params['store_id'];
$data['setting_date'] = $params['setting_date'];
$data['is_del'] = 0;
if((isset($params['is_discounts'])) && ($params['is_discounts'] > 0))
$data['is_discounts'] = $params['is_discounts'];
if((isset($params['transfer_charge'])) && ($params['transfer_charge'] > 0))
$data['transfer_charge'] = $params['transfer_charge'];
if((isset($params['social_security_fee'])) && ($params['social_security_fee'] > 0))
$data['social_security_fee'] = $params['social_security_fee'];
if((isset($params['attendance_num'])) && ($params['attendance_num'] > 0))
$data['attendance_num'] = $params['attendance_num'];
if((isset($params['official_receipts'])) && ($params['official_receipts'] > 0))
$data['official_receipts'] = $params['official_receipts'];
if((isset($params['last_official_receipts'])) && ($params['last_official_receipts'] > 0))
$data['last_official_receipts'] = $params['last_official_receipts'];
if((isset($params['deduct'])) && ($params['deduct'] > 0))
$data['deduct'] = $params['deduct'];
$res = $this->m_store_data->saveStoreData($data);
return $res;
}
/**
* 更新数据
* @param $id
* @param $params
* @return int|string
*/
public function updateStoreData($id,$params){
$data['id'] = $id;
if((isset($params['is_discounts'])) && ($params['is_discounts'] > 0))
$data['is_discounts'] = $params['is_discounts'];
if((isset($params['transfer_charge'])) && ($params['transfer_charge'] > 0))
$data['transfer_charge'] = $params['transfer_charge'];
if((isset($params['social_security_fee'])) && ($params['social_security_fee'] > 0))
$data['social_security_fee'] = $params['social_security_fee'];
if((isset($params['attendance_num'])) && ($params['attendance_num'] > 0))
$data['attendance_num'] = $params['attendance_num'];
if((isset($params['official_receipts'])) && ($params['official_receipts'] > 0))
$data['official_receipts'] = $params['official_receipts'];
if((isset($params['last_official_receipts'])) && ($params['last_official_receipts'] > 0))
$data['last_official_receipts'] = $params['last_official_receipts'];
if((isset($params['deduct'])) && ($params['deduct'] > 0))
$data['deduct'] = $params['deduct'];
$res = $this->m_store_data->updateStoreData($data);
return $res;
}
} }
\ No newline at end of file
<?php
namespace app\index\validate;
use think\Validate;
class CostParameterValidate extends Validate {
protected $rule = [
'store_id' => 'require|number|gt:0',
'setting_date' => 'require|number',
];
protected $message = [
'store_id.require' => 'id为必填字段',
'store_id.number' => 'id只能为数字',
'store_id.gt' => 'id必须大于0',
'setting_date.require' => '时间为必填字段',
];
protected $scene = [
'editCostParameter' => [ 'store_id', 'setting_date'],
];
}
\ No newline at end of file
...@@ -22,7 +22,7 @@ class FStoreData extends BaseModel ...@@ -22,7 +22,7 @@ class FStoreData extends BaseModel
* @param $data * @param $data
* @return mixed * @return mixed
*/ */
public function saveOffice($data) { public function saveStoreData($data) {
$time = date("Y-m-d H:i:s", time()); $time = date("Y-m-d H:i:s", time());
$data["is_del"] = 0; $data["is_del"] = 0;
$data['create_time'] = $time; $data['create_time'] = $time;
...@@ -32,6 +32,9 @@ class FStoreData extends BaseModel ...@@ -32,6 +32,9 @@ class FStoreData extends BaseModel
/** /**
* 查询单条数据 * 查询单条数据
* @param $field
* @param $params
* @return array|false|\PDOStatement|string|Model
*/ */
public function findByOne($field,$params) { public function findByOne($field,$params) {
$result = $this->db_ $result = $this->db_
...@@ -40,4 +43,14 @@ class FStoreData extends BaseModel ...@@ -40,4 +43,14 @@ class FStoreData extends BaseModel
->find(); ->find();
return $result; return $result;
} }
/**
* 更新数据
* @param $params
* @return int|string
*/
public function updateStoreData($params)
{
return $this->db_->update($params);
}
} }
...@@ -217,7 +217,7 @@ class OPartialCommission extends BaseModel ...@@ -217,7 +217,7 @@ class OPartialCommission extends BaseModel
*/ */
public function getCommissionTotalList($pageNo = 1, $pageSize = 15, $field = '', $params = '') public function getCommissionTotalList($pageNo = 1, $pageSize = 15, $field = '', $params = '')
{ {
return $this->alias('a') $res = $this->alias('a')
->field($field) ->field($field)
->join('o_real_income b', 'a.real_income_id = b.id', 'left') ->join('o_real_income b', 'a.real_income_id = b.id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left') ->join('a_agents d', 'a.agent_id = d.id', 'left')
...@@ -227,15 +227,18 @@ class OPartialCommission extends BaseModel ...@@ -227,15 +227,18 @@ class OPartialCommission extends BaseModel
->page($pageNo) ->page($pageNo)
->group('a.agent_id') ->group('a.agent_id')
->select(); ->select();
return $res;
} }
public function getSumMoney($field, $where) { public function getSumMoney($field, $where) {
return $this->alias('a') $res = $this->alias('a')
->field($field) ->field($field)
->join('o_bargain b', 'a.bargain_id = b.id', 'left') ->join('o_bargain b', 'a.bargain_id = b.id', 'left')
->join('o_real_income c', ' a.real_income_id = c.id', 'left') ->join('o_real_income c', ' a.real_income_id = c.id', 'left')
->where($where) ->where($where)
->find(); ->find();
big_log($this->getLastSql());
return $res;
} }
/** /**
...@@ -534,4 +537,17 @@ class OPartialCommission extends BaseModel ...@@ -534,4 +537,17 @@ class OPartialCommission extends BaseModel
return $date; return $date;
} }
public function getCommissionTotal($field = '', $params = '')
{
return $this->alias('a')
->field($field)
->join('o_real_income b', 'a.real_income_id = b.id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->join('o_bargain e', 'a.bargain_id = e.id', 'left')
->where($params)
->group('a.agent_id')
->select();
}
} }
\ No newline at end of file
...@@ -546,7 +546,8 @@ Route::group('index', [ ...@@ -546,7 +546,8 @@ Route::group('index', [
'editApplyFor' => ['index/StoreFee/addApplyFor', ['method' => 'POST']],//修改报销申请 'editApplyFor' => ['index/StoreFee/addApplyFor', ['method' => 'POST']],//修改报销申请
'getApplyForFeeStore' => ['index/StoreFee/getApplyForFeeStore', ['method' => 'GET']],//获取费用承担办公室 'getApplyForFeeStore' => ['index/StoreFee/getApplyForFeeStore', ['method' => 'GET']],//获取费用承担办公室
'getStoreCostParameterList' => ['index/CostParameter/getStoreCostParameterList', ['method' => 'POST|GET']], 'getStoreCostParameterList' => ['index/CostParameter/getStoreCostParameterList', ['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