Commit afc67398 authored by zhuwei's avatar zhuwei

成本明细表 excel

parent 777b1285
......@@ -4,6 +4,8 @@ namespace app\index\controller;
use app\index\extend\Basic;
use app\api\service\ActivityService;
use app\index\untils\ExportExcelUntil;
use app\model\AStore;
use app\model\CActivity;
use app\model\FStoreCostExt;
use think\Request;
......@@ -38,23 +40,228 @@ class CostDetail extends Basic
);*/
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
$conditions = [];
//计入月份
if (!empty($params["setting_date"])) {
$conditions["setting_date"] = $params["setting_date"];
}
// if (!empty($params["id"])) {
// $conditions["id"] = $params['id'];
// }
$conditions=$this->buildConditions($params);
$field = 'a.id,a.cost_id,b.setting_date,a.create_time,b.operator_name,
a.type,a.fee_item,a.purpose,b.store_id,a.assume_fee';
a.type,a.fee_item,a.purpose,b.store_id,a.assume_fee';
$list = $this->storeCostExt->getStoreCostExt($field, $conditions, $pageNo, $pageSize);
if(!$list)
return $this->response("200", "success", []);
foreach ($list as $k => $v) {
$list[$k]['type_name'] = $this->getTypeName($v['type']);
$list[$k]['fee_item_name'] = $this->getFeeItemName($v['fee_item']);
$list[$k]['store_name'] = $this->getStoreName($v['store_id']);
}
$count = $this->storeCostExt->getStoreCostExtTotal($field, $conditions);
$result["list"] = $list;
$result["total"] = $count;
return $this->response("200", "success", $result);
}
/**
* 成本明细表 excel
* @return \think\Response
*/
public function getCostDetailListExcel()
{
$params = $this->params;
$conditions=$this->buildConditions($params);
$field = 'a.id,a.cost_id,b.setting_date,a.create_time,b.operator_name,
a.type,a.fee_item,a.purpose,b.store_id,a.assume_fee';
$list = $this->storeCostExt->getStoreCostExtExcel($field, $conditions);
if(!$list)
return $this->response("101", "查无数据", []);
$export = new ExportExcelUntil();
$e_data_new = [];
foreach ($list as $k => $v) {
$excel_data_['id'] = $v['id'];
$excel_data_['cost_id'] = $v['cost_id'];
$excel_data_['setting_date'] = $v['setting_date'];
$excel_data_['create_time'] = $v['create_time'];
$excel_data_['operator_name'] = $v['operator_name'];
$excel_data_['type_name'] = $this->getTypeName($v['type']);
$excel_data_['fee_item_name'] = $this->getFeeItemName($v['fee_item']);
$excel_data_['purpose'] = $v['purpose'];
$excel_data_['store_name'] = $this->getStoreName($v['store_id']);
$excel_data_['assume_fee'] = $v['assume_fee'];
$excel_data[]=$excel_data_;
}
$title = [ '成本明细ID','费用总ID','计入月份','创建时间','提交人','费用类型','费用项目','费用用途','费用承担门店','费用承担金额(元)'];
$export->exportTable('成本明细', $excel_data, count($excel_data[0]) - 1, '成本明细表', $title);
return '';
}
/**
* 构建搜索条件
* @param $params
* @return array
*/
public function buildConditions($params)
{
$conditions = [];
//计入月份
if (!empty($params["setting_date"])) {
$conditions["b.setting_date"] = $params["setting_date"];
}
//创建时间
if (!empty($params['start_time']) && !empty($params['end_time'])) {
$where['a.create_time'] = ['between', [$params['start_time'] . ' 00:00:00', $params['end_time'] . ' 23:59:59']];
}
//门店id
if (!empty($params['store_id'])) {
$conditions["b.store_id"] = $params["store_id"];
}
//成本明细ID
if (!empty($params['id'])) {
$conditions["a.id"] = $params["id"];
}
//费用ID
if (!empty($params['cost_id'])) {
$conditions["b.cost_id"] = $params["cost_id"];
}
//费用类型
if (!empty($params['type'])) {
$conditions["a.type"] = $params["type"];
}
//费用项目
if (!empty($params['fee_item'])) {
$conditions["a.fee_item"] = $params["fee_item"];
}
//费用用途
if (!empty($params['purpose'])) {
$conditions["a.purpose"] = $params["purpose"];
}
return $conditions;
}
/**
* 费用类型
* @param $type
* @return string
*/
public function getTypeName($type)
{
//费用类型 0办公室成本 1上海总部成本 2分部成本 3同联发展基金 4门店单独成本
switch ($type) {
case 0 :
$str = '办公室成本';
break;
case 1 :
$str = '上海总部成本';
break;
case 2 :
$str = '分部成本';
break;
case 3 :
$str = '同联发展基金';
break;
case 4 :
$str = '门店单独成本';
break;
default :
$str = '暂无';
}
return $str;
}
/**
* 费用项目
* @param $fee_item
* @return string
*/
public function getFeeItemName($fee_item)
{
//费用项目
switch ($fee_item) {
case 100 :
$str = '房租租金';
break;
case 101 :
$str = '101水电费';
break;
case 102 :
$str = '102其他费用';
break;
case 201 :
$str = '201总部固定成本';
break;
case 301 :
$str = '301分部固定成本';
break;
case 401 :
$str = '同联发展基金';
break;
case 501 :
$str = '家庭基金报销';
break;
case 502 :
$str = '社保报销';
break;
case 503 :
$str = '总经理基薪';
break;
case 504 :
$str = '区域秘书基薪';
break;
case 505 :
$str = '招聘成本';
break;
case 506 :
$str = '区域经理基本工资平摊';
break;
case 507 :
$str = '宿舍成本';
break;
case 508 :
$str = '宿舍亏损';
break;
case 509 :
$str = '手续费';
break;
case 510 :
$str = '员工工资成本';
break;
case 511 :
$str = '网络报销';
break;
case 512 :
$str = '离职员工网络';
break;
case 513 :
$str = '门店独有成本其他费用';
break;
default :
$str = '暂无';
}
return $str;
}
/**
* 获取门店名
* @param $store_id
* @return false|\PDOStatement|string|\think\Collection
*/
public function getStoreName($store_id)
{
if(!$store_id)
return '';
$m_store = new AStore();
$store_params['id'] = $store_id;
$store_field = 'store_name';
$store_result = $m_store->getStore($store_params, $store_field);
return $store_result;
}
}
\ No newline at end of file
......@@ -49,6 +49,18 @@ class FStoreCostExt extends BaseModel
return $result;
}
public function getStoreCostExtExcel($field,$params)
{
$params["b.status"] = 0;
$result = $this->db_
->field($field)
->alias('a')
->join('f_store_cost b', 'a.cost_id = b.id', 'left')
->where($params)
->select();
return $result;
}
......
......@@ -538,7 +538,8 @@ Route::group('index', [
'checkCostFour/:check_status' => ['index/Cost/checkCost', ['method' => 'POST'], ['check_status' => 3]], //费用报销审核二审
'checkCostFive/:check_status' => ['index/Cost/checkCost', ['method' => 'POST'], ['check_status' => 4]], //费用报销审核三审
'getCostDetailList' => [ 'index/CostDetail/getCostDetailList', [ 'method' => 'POST|GET' ] ],
'getCostDetailList' => [ 'index/CostDetail/getCostDetailList', [ 'method' => 'POST|GET' ] ],
'getCostDetailListExcel' => [ 'index/CostDetail/getCostDetailListExcel', [ '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