| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use \think\Request;
- use think\Db;
- /**
- * 员工工资查询
- */
- class StaffSalary extends Api
- {
-
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 查询报工数据月份
- * @ApiMethod (GET)
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function GetReportingWorkMonth()
- {
- if (!$this->request->isGet()) {
- $this->error('请求方法错误');
- }
- $data = db('设备_工分计酬')
- ->where('del_rq', null)
- ->field('DISTINCT DATE_FORMAT(date, "%Y-%m") as month')
- ->order('date desc')
- ->select();
-
- //获取员工部门
- $big_process = db('人员_基本资料')
- ->field('DISTINCT big_process')
- ->select();
- foreach ($big_process as $v) {
- $big_process_name[] = $v['big_process'];
- }
- $result = [];
- foreach ($data as $v) {
- $result[$v['month']] = $big_process_name;
- }
- $this->success('成功', $result);
- }
- /**
- * 查询员工工资列表
- * @ApiMethod (GET)
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function GetStaffSalaryList()
- {
- if (!$this->request->isGet()) {
- $this->error('请求方法错误');
- }
- $param = $this->request->param();
- if (empty($param['month'])) {
- $this->error('请选择月份');
- }
- if (empty($param['big_process'])) {
- $this->error('请选择部门');
- }
- //获取大工序员工列表
- $staff = db('人员_基本资料')
- ->alias('a')
- ->join('设备_工分计酬 b','a.staff_no = b.staff_no','left')
- ->where('a.big_process',$param['big_process'])
- ->where('a.status',1)
- ->where('b.date', 'like', $param['month'] . '%')
- ->field('a.staff_no,a.staff_name,sum(b.salary) as salary')
- ->group('a.staff_no,a.staff_name')
- ->select();
- if(empty($staff)){
- $this->error('该部门没有员工');
- }
- $staffMap = [];
- $staffNos = [];
- foreach ($staff as $item) {
- $staffMap[$item['staff_no']] = $item['staff_name'];
- $staffNos[] = $item['staff_no'];
- }
- $salaryRows = db('设备_工分计酬')
- ->where('del_rq', null)
- ->where('date', 'like', $param['month'] . '%')
- ->where('staff_no', 'in', $staffNos)
- ->field('staff_no,staff_name,DATE_FORMAT(date, "%Y-%m-%d") as date,sum(salary) as salary')
- ->group('staff_no,DATE_FORMAT(date, "%Y-%m-%d")')
- ->order('staff_no asc,date asc')
- ->select();
- $grouped = [];
- foreach ($salaryRows as $row) {
- $staffNo = $row['staff_no'];
- if (!isset($grouped[$staffNo])) {
- $name = !empty($row['staff_name']) ? $row['staff_name'] : (isset($staffMap[$staffNo]) ? $staffMap[$staffNo] : '');
- $grouped[$staffNo] = [
- 'staff' => $staffNo . '-' . $name,
- 'total_salary' => 0,
- 'children' => [],
- ];
- }
- $grouped[$staffNo]['children'][] = [
- '员工编号' => $staffNo,
- '员工姓名' => !empty($row['staff_name']) ? $row['staff_name'] : (isset($staffMap[$staffNo]) ? $staffMap[$staffNo] : ''),
- '日期' => $row['date'],
- '工资' => $row['salary'],
- ];
- $grouped[$staffNo]['total_salary'] += $row['salary'];
- }
- $this->success('成功', array_values($grouped));
-
- }
-
- /**
- * 查询员工工资详情
- *
- */
- public function GetStaffSalaryDetail()
- {
- if (!$this->request->isGet()){
- $this->error('请求方法错误');
- }
- $param = $this->request->param();
- if (empty($param['staff_no'])) {
- $this->error('请选择员工');
- }
- if(empty($param['date'])){
- $this->error('请选择日期');
- }
- $where = [
- 'a.staff_no' => $param['staff_no'],
- 'a.date' => ['like', $param['date'] . '%'],
- 'a.del_rq' => null,
- ];
- $list = db('设备_工分计酬')
- ->alias('a')
- ->join('工单_部件资料 b', 'a.work_order = b.work_order and a.part_code = b.part_code', 'left')
- ->field('a.work_order as 订单编号,DATE_FORMAT(a.date, "%Y-%m-%d") as 日期,b.part_name as 部件名称,
- a.part_code as 部件编号,a.salary as 工资,a.number as 数量,a.production_hour as 生产工时,a.production_score as 生产分数,
- a.machine as 设备名称,a.process_name as 工序名称,a.standard_hour as 标准工时,a.standard_score as 标准分数,
- a.coefficient as 系数')
- ->where($where)
- ->order('a.date asc,a.process_code asc')
- ->select();
- if(empty($list)){
- $this->error('没有数据');
- }
- $this->success('成功', $list);
- }
- /**
- * 查询月份员工工资数据
- * @ApiMethod (GET)
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function GetStaffSalaryMonth()
- {
- if (!$this->request->isGet()){
- $this->error('请求方法错误');
- }
- $param = $this->request->param();
- if (empty($param['month'])) {
- $this->error('请选择月份');
- }
- $where = [
- 'date' => ['like', $param['month'] . '%'],
- 'del_rq' => null,
- ];
- if (!empty($param['search'])) {
- $where['staff_no|staff_name'] = ['like', '%' . $param['search'] . '%'];
- }
- $list = db('设备_工分计酬')
- ->where($where)
- ->field('staff_no,staff_name,sum(salary) as salary')
- ->group('staff_no,staff_name')
- ->field('staff_no,staff_name,DATE_FORMAT(date, "%Y-%m-%d") as date,sum(salary) as salary')
- ->group('staff_no,DATE_FORMAT(date, "%Y-%m-%d")')
- ->order('staff_no asc,date asc')
- ->select();
- if(empty($list)){
- $this->error('没有数据');
- }
- $this->success('成功', $list);
- }
- }
|