Commit f44defd7 authored by hujun's avatar hujun

批量操作

parent 79a43efa
...@@ -98,6 +98,76 @@ class CostService ...@@ -98,6 +98,76 @@ class CostService
return $result; return $result;
} }
/**
* 批量费用报销审核
* status 审核状态 1总监审核 2一审审核 3二审审核 4三审审核
*
* @param $params
* @param $agent_id
* @return mixed
*/
public function checkArray($params, $agent_id)
{
$result['status'] = 'fail';
$result['msg'] = '';
if (count($params['id_array']) > 30) {
$result['msg'] = '批量操作数量超过限制';
return $result;
}
$check_['apply_for_id'] = $where['id'] = ['in', $params['id_array']];
$check_['is_del'] = $where['is_del'] = $is_update_apply = 0;
$cost_data = $this->apply_model->findByAll('id,status,agent_id', $where);
if (empty($cost_data)) {
$result['msg'] = '无该记录';
return $result;
}
$check_['type'] = $params['status'];
$cost_check_data = $this->check_model->findColumn('apply_for_id', $check_);
foreach ($cost_data as $v) {
if ($v['status'] == $params['status'] || in_array($v['id'], $cost_check_data)) {
continue;//已审跳过
}
$save_check[] = [
'apply_for_id' => $v['id'],
'agent_id' => $agent_id,
'type' => $params['status'],
'remark' => $params['remark'],
]; //插入审核记录
$apply_for_id[] = $v['id']; //记录更新状态
}
$this->apply_model->startTrans();
try {
if (isset($apply_for_id)) {
$is_update_apply = $this->apply_model->updateData(['status' => $params['status']], ['id' => ['in', $apply_for_id]]);
}
if (isset($save_check)) {
$this->check_model->insertDataAll($save_check);
}
$this->apply_model->commit();
} catch (\Exception $e) {
$this->apply_model->rollback();
$is_update_apply = 0;
}
if ($is_update_apply) {
$result['status'] = 'successful';
$result['msg'] = '审核成功';
} else {
$result['msg'] = '审核失败';
}
return $result;
}
/** /**
* 获取费用项目 * 获取费用项目
* *
......
...@@ -149,4 +149,17 @@ class FApplyForFee extends BaseModel ...@@ -149,4 +149,17 @@ class FApplyForFee extends BaseModel
->where($where) ->where($where)
->select(); ->select();
} }
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function findByAll($field, $params)
{
return $this->db_
->field($field)
->where($params)
->select();
}
} }
...@@ -97,4 +97,13 @@ class FApplyForFeeCheck extends BaseModel ...@@ -97,4 +97,13 @@ class FApplyForFeeCheck extends BaseModel
->select(); ->select();
return $result; return $result;
} }
/**
* @param $data
* @return int|string
*/
public function insertDataAll($data)
{
return $this->db_->insertAll($data);
}
} }
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