Commit b2fd82ed authored by hujun's avatar hujun

费用报销详情

parent 1cfdb83f
...@@ -18,6 +18,7 @@ use app\model\FApplyForFee; ...@@ -18,6 +18,7 @@ use app\model\FApplyForFee;
use app\model\FApplyForFeeCheck; use app\model\FApplyForFeeCheck;
use app\model\FImg; use app\model\FImg;
use app\model\FStoreCost; use app\model\FStoreCost;
use app\model\FStoreCostExt;
class Cost extends Basic class Cost extends Basic
{ {
...@@ -259,8 +260,8 @@ class Cost extends Basic ...@@ -259,8 +260,8 @@ class Cost extends Basic
} }
$cost_service = new CostService(); $cost_service = new CostService();
$fee_model = new FApplyForFee(); $fee_model = new FApplyForFee();
$m_store = new AStore();
$m_store_cost = new FStoreCost(); $m_store_cost = new FStoreCost();
$m_store_cost_ext = new FStoreCostExt();
$m_check = new FApplyForFeeCheck(); $m_check = new FApplyForFeeCheck();
$m_img = new FImg(); $m_img = new FImg();
...@@ -269,63 +270,60 @@ class Cost extends Basic ...@@ -269,63 +270,60 @@ class Cost extends Basic
$where['id'] = $this->params['id']; $where['id'] = $this->params['id'];
$data = $fee_model->findByOne($field, $where); $data = $fee_model->findByOne($field, $where);
$office_id = $m_store->getFieldOneValue('office_id', ['id' => $data['store_id']]); if (empty($data['id'])) {
if ($office_id) { return $this->response($code, '无该记录');
$store_field = 'a.id,a.store_name'; }
$office_store = $m_store->getStoreCostAll($store_field, ['a.office_id' => $office_id, 'a.status' => 0]);
$list = [];
$cost_ext_field = 'a.id,b.store_attendance_num,b.assume_fee';
$cost_ext_where['setting_date'] = $data['count_time'];
foreach ($office_store as $k => $v) {
$cost_ext_where['store_id'] = $v['id'];
$store_cost_data = $m_store_cost->getCostExt($cost_ext_field, $cost_ext_where);
if (!empty($store_cost_data)) {
$list[$k] = [
'id' => $store_cost_data['id'],
'store_name' => $v['store_name'],
'store_attendance_num' => $store_cost_data['store_attendance_num'],
'assume_fee' => $store_cost_data['assume_fee']
];
$store_cost_id[] = $store_cost_data['id'];
}
}
if (isset($store_cost_id)) {
$data['office_attendance_num'] = $m_store_cost->sumData('office_attendance_num', ['id'=>['in'=>$store_cost_id]]);
} else {
$data['office_attendance_num'] = 0;
}
$check_field = 'b.name,a.create_time,a.remark';
$data['check_log'] = $m_check->findByAll($check_field, ['apply_for_id' => $data['id']]);
$data['images_data'] = $m_img->findByAll('id,img_name,img_type', ['img_id' => $data['id']]);
$data['store_cost_data'] = $list;
$data['image_base_url'] = 'static/chat_image/';
$redis = new RedisCacheService();
$agent_data = $redis->getRedisCache(2, $data['id']);
$data['agent_name'] = $agent_data['name'];
$source = [
0 => 'app申请',
1 => 'excel导入'
];
$status = [
0 => '申请中',
1 => '总监通过',
2 => '一审通过',
3 => '二审通过',
4 => '三审通过',
];
$data['source_name'] = $source[$data['source']]; $data['store_cost_data'] = [];
$data['status_name'] = $status[$data['status']]; $data['office_attendance_num'] = 0;
$data['type_name'] = $cost_service->getFeeType($data['type']); //报销类型 1办公室成本 2总部成本 3分部成本 4门店独有成本
$data['fee_item_name'] = $cost_service->getFeeItem($data['fee_item']); switch($data['type']) {
case 1 :
$store_field = 'a.cost_id as id,a.assume_fee,a.store_attendance_num,c.store_name';
$data['store_cost_data'] = $m_store_cost_ext->getFeeStoreCost($store_field, ['a.apply_for_id'=>$data['id']]);
$ext_where['a.type'] = 1;
$ext_where['c.office_id'] = $data['office_id'];
$ext_where['b.setting_date'] = $data['count_time'];
$data['office_attendance_num'] = $m_store_cost_ext->getFeeOfficeCostSum('a.office_attendance_num', $ext_where);
break;
case 2 :
break;
case 3 :
break;
case 4 :
$cost_ext_field = 'a.id,b.store_attendance_num,b.assume_fee';
$where_cost['apply_for_id'] = $data['id'];
$store_cost_data = $m_store_cost->getCostExt($cost_ext_field, $where_cost);
$data['store_cost_data'] = [$store_cost_data];
break;
} }
$check_field = 'b.name,a.create_time,a.remark';
$data['check_log'] = $m_check->findByAll($check_field, ['apply_for_id' => $data['id']]);
$data['images_data'] = $m_img->findByAll('id,img_name,img_type', ['img_id' => $data['id']]);
$data['image_base_url'] = 'static/chat_image/';
$redis = new RedisCacheService();
$agent_data = $redis->getRedisCache(2, $data['id']);
$data['agent_name'] = $agent_data['name'];
$source = [
0 => 'app申请',
1 => 'excel导入'
];
$status = [
0 => '申请中',
1 => '总监通过',
2 => '一审通过',
3 => '二审通过',
4 => '三审通过',
];
$data['source_name'] = $source[$data['source']];
$data['status_name'] = $status[$data['status']];
$data['type_name'] = $cost_service->getFeeType($data['type']);
$data['fee_item_name'] = $cost_service->getFeeItem($data['fee_item']);
return $this->response(200, '', $data); return $this->response(200, '', $data);
} }
} }
\ No newline at end of file
...@@ -78,4 +78,18 @@ class FApplyForFee extends BaseModel ...@@ -78,4 +78,18 @@ class FApplyForFee extends BaseModel
->where($params) ->where($params)
->count('a.id'); ->count('a.id');
} }
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
*/
public function getFeeStoreCost($field, $where)
{
return $this->field($field)->alias('a')
->join('f_store_cost_ext b', 'a.id = b.apply_for_id', 'left')
->join('a_store c', 'a.store_id=c.id','left')
->where($where)
->select();
}
} }
...@@ -80,7 +80,31 @@ class FStoreCostExt extends BaseModel ...@@ -80,7 +80,31 @@ class FStoreCostExt extends BaseModel
return $result; return $result;
} }
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
*/
public function getFeeStoreCost($field, $where)
{
return $this->field($field)->alias('a')
->join('f_apply_for_fee b', 'a.apply_for_id = b.id', 'left')
->join('a_store c', 'b.store_id=c.id','left')
->where($where)
->select();
}
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
*/
public function getFeeOfficeCostSum($field, $where)
{
return $this->alias('a')
->join('f_store_cost b', 'a.cost_id = b.id', 'left')
->join('f_apply_for_fee c', 'a.apply_for_id = b.id', 'left')
->where($where)
->sum($field);
}
} }
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