Browse Source

糊盒报工计时

unknown 3 months ago
parent
commit
ef381e689b

+ 9 - 3
application/api/controller/EmployeeDailySalary.php

@@ -223,7 +223,7 @@ class EmployeeDailySalary extends Api
 //            ->where('j.异常停机工时','<>',0)
 //             ->where('j.达标定额','<>',0)
             ->where(['r.所在部门'=>['like',$req['department'].'%']])
-            ->group('j.bh,j.sczl_rq,j.sczl_gdbh')
+            ->group('j.bh,j.sczl_rq,j.sczl_gdbh,j.千件工价')
             ->select();
         //查询每月有达标定额的天数
 //        $arr3 = db('绩效工资汇总')->alias('j')
@@ -414,7 +414,7 @@ class EmployeeDailySalary extends Api
 
             $arr = array_merge($arr, $r);
         }
-        
+
         $list = [];
         foreach($arr as $v){
             if(isset($list[$v['wgjs_bh'].'-'.$v['wgjs_rq']])){
@@ -432,6 +432,7 @@ class EmployeeDailySalary extends Api
                 $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['日工资合计']=floatval(number_format($v['wgjs_js']*9.5,2, '.', ''));
             }
         };
+
         //计算包装计件计时工资
         foreach ($result as $v){
             if(isset($list[$v['sczl_bh'].'-'.$v['sczl_rq']])){
@@ -449,6 +450,7 @@ class EmployeeDailySalary extends Api
                 $list[$v['sczl_bh'].'-'.$v['sczl_rq']]['日工资合计']=floatval(number_format($v['计时时数']*9.5,2, '.', ''));
             }
         }
+
         $list1 = [];
         foreach($arr as $v){
             if(isset($list1[$v['wgjs_bh']])){
@@ -478,6 +480,7 @@ class EmployeeDailySalary extends Api
                 }
             }
         }
+
         //获取每个员工计时补差天数
         $arr1 = db('绩效工资汇总')->alias('j')
             ->field('j.bh,j.sczl_rq,j.法定天数')
@@ -502,6 +505,7 @@ class EmployeeDailySalary extends Api
             // ->where(['人事_基本资料.所在部门'=>['like',$req['department'].'%']])
             ->column('bh,rtrim(xm) as 员工姓名,DATE_FORMAT(sczl_rq,"%Y/%m/%d") as sczl_rq,
             sum(异常停机工时) as 计时时数');
+
         //查询每条记录
         $arr2 = db('绩效工资汇总')->alias('j')
             ->field('j.bh, DATE_FORMAT(j.sczl_rq,"%Y/%m/%d") as sczl_rq,
@@ -511,8 +515,9 @@ class EmployeeDailySalary extends Api
             // ->where('j.达标定额','<>',0)
             ->where('j.bh',$req['search'])
             // ->where(['r.所在部门'=>['like',$req['department'].'%']])
-            ->group('j.bh,j.sczl_rq,j.sczl_gdbh')
+            ->group('j.bh,j.sczl_rq,j.sczl_gdbh,j.千件工价')
             ->select();
+
        //查询每月有达标定额的天数
 //        $arr3 = db('绩效工资汇总')->alias('j')
 //            ->join('人事_基本资料 r','r.员工编号=j.bh')
@@ -521,6 +526,7 @@ class EmployeeDailySalary extends Api
 //            ->where('j.bh',$req['search'])
 //            ->group('j.bh,j.sczl_rq')
 //            ->count();
+
         //计算每条记录的计时补差
         $brr = [];
         foreach($arr2 as $v){

+ 361 - 0
application/api/controller/GluChronographSheet.php

@@ -0,0 +1,361 @@
+<?php
+
+
+namespace app\api\controller;
+
+
+use app\common\controller\Api;
+use \think\Request;
+use \think\Db;
+
+/**
+ * 糊盒计时单维护
+ */
+class GluChronographSheet extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+
+    /**
+     * 获取计件工计时单侧边栏
+     * @ApiMethod (GET)
+     */
+    public function getTab()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $rows = db()->table('糊盒报工机时')
+            ->field('LEFT(wgjs_rq, 7) as date')
+            ->group('date')
+            ->order('UniqId desc')
+            ->limit(15)
+            ->select();
+        foreach($rows as $key=>$value){
+            $rows[$key]['date'] = str_replace('-', '', $rows[$key]['date']);
+        }
+        $this->success('成功',$rows);
+    }
+
+    /**
+     * 获取计件工计时单列表
+     * @ApiMethod (GET)
+     * @param string $date 时间
+     * @param string $Sczl_bh1 员工编号
+     */
+    public function getList()
+    {
+        // 验证请求方式
+        if (!$this->request->isGet()) {
+            $this->error('请求方式错误');
+        }
+
+        $req = $this->request->param();
+
+        // 必需参数校验
+        if (empty($req['date'])) {
+            $this->error('参数错误: 缺少日期参数');
+        }
+
+        $where['wgjs_rq'] = ['LIKE', $req['date'] . '%'];
+        $usePagination = isset($req['page'], $req['limit']) && $req['page'] > 0 && $req['limit'] > 0;
+
+        // 构建基础查询
+        $query = db()->table('糊盒报工机时')
+            ->field('LEFT(wgjs_rq, 10) as wgjs_rq, UniqId, 
+            wgjs_bh1, wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1, 
+            wgjs_bh2, wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2, 
+            wgjs_bh3, wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3, 
+            wgjs_bh4, wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4, 
+            wgjs_bh5, wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5, 
+            wgjs_bh6, wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6')
+            ->where($where)
+            ->order('wgjs_rq desc, UniqId asc');
+
+        // 执行分页/全量查询
+        if ($usePagination) {
+            $rows = $query->page($req['page'], $req['limit'])->select();
+            $total = db()->table('db_wgjs')->where($where)->count();
+        } else {
+            $rows = $query->select();
+            $total = count($rows);  // 避免额外COUNT查询
+        }
+
+        // 获取员工基础数据
+        $employees = db()->table('人事_基本资料')->column('员工编号, 员工姓名, 所在部门');
+
+        // 数据处理优化
+        foreach ($rows as &$row) {
+            // 处理主员工信息
+            $mainId = $row['wgjs_bh1'];
+            $hasMain = isset($employees[$mainId]);
+
+            $row['wgjs_js1'] = $row['wgjs_js1'] == 0 ? '' : $row['wgjs_js1'];
+            $row['department'] = $hasMain ? trim($employees[$mainId]['所在部门']) : '';
+            $row['name1'] = $hasMain ? trim($employees[$mainId]['员工姓名']) : '';
+
+            // 处理2-6号员工信息
+            for ($i = 2; $i <= 6; $i++) {
+                $fieldId = $row["wgjs_bh$i"];
+                $row["wgjs_js$i"] = $row["wgjs_js$i"] == '0.0' ? '' : $row["wgjs_js$i"];
+
+                $row["name$i"] = ($fieldId && isset($employees[$fieldId]))
+                    ? trim($employees[$fieldId]['员工姓名'])
+                    : ($fieldId === $mainId ? $row['name1'] : '');
+            }
+        }
+
+        $this->success('成功', [
+            'total' => $total,
+            'rows' => $rows
+        ]);
+    }
+    /**
+     * 获取计件工计时单信息
+     * @ApiMethod (GET)
+     * @param string $UniqId UniqId
+     */
+    public function getInfo()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        if (isset($req['UniqId']) && !empty($req['UniqId'])){
+            $UniqId = $req['UniqId'];
+        }else{
+            $this->error('参数错误');
+        }
+
+        $rows = db()->table('糊盒报工机时')->alias('d')
+            ->field('d.*, ')
+            ->join('工单_基本资料 g', 'd.')
+            ->where('d.UniqId',$UniqId)
+            ->select();
+
+
+        $this->success('成功',$rows);
+    }
+    /**
+     * 定位
+     * @ApiMethod GET
+     */
+    public function search(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $req = Request::instance()->param();
+        if (!isset($req['search']) || !isset($req['date'])){
+            $this->error('参数错误');
+        }
+        $page = 1;
+        $limit = 10;
+        if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
+        if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
+        $year=substr($req['date'],0,4);
+        $month=substr($req['date'],-2);
+        $start_time = $year . '-' . $month . '-01 00:00:00';
+        $end_time = date('Y-m-t', strtotime("$year-$month-01")) . ' 23:59:59';
+        $yg = db()->table('人事_基本资料')->where('员工姓名',$req['search'])->value('员工编号');
+        if($yg){
+            $req['search']=$yg;
+        }
+        $where = [
+            'a.wgjs_rq'=>['between',"$start_time,$end_time"],
+            'a.wgjs_bh1|a.wgjs_bh2|a.wgjs_bh3|a.wgjs_bh4|a.wgjs_bh5|a.wgjs_bh6'=>['like', '%'.$req['search'].'%']
+        ];
+        $rows = db()->table('糊盒报工机时')
+            ->alias('a')
+            ->field('LEFT(a.wgjs_rq, 10) as wgjs_rq, 
+        a.wgjs_bh1,trim(rs1.所在部门) as 所在部门, a.wgjs_js1, rtrim(a.wgjs_yy1) as wgjs_yy1, 
+        a.wgjs_bh2, a.wgjs_js2, rtrim(a.wgjs_yy2) as wgjs_yy2, 
+        a.wgjs_bh3, a.wgjs_js3, rtrim(a.wgjs_yy3) as wgjs_yy3, 
+        a.wgjs_bh4, a.wgjs_js4, rtrim(a.wgjs_yy4) as wgjs_yy4, 
+        a.wgjs_bh5, a.wgjs_js5, rtrim(a.wgjs_yy5) as wgjs_yy5, 
+        a.wgjs_bh6, a.wgjs_js6, rtrim(a.wgjs_yy6) as wgjs_yy6,
+        rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名) as name3,
+        rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名) as name6,
+        a.UniqId')
+            ->join('人事_基本资料 rs1','rs1.员工编号=a.wgjs_bh1','LEFT')
+            ->join('人事_基本资料 rs2','rs2.员工编号=a.wgjs_bh2','LEFT')
+            ->join('人事_基本资料 rs3','rs3.员工编号=a.wgjs_bh3','LEFT')
+            ->join('人事_基本资料 rs4','rs4.员工编号=a.wgjs_bh4','LEFT')
+            ->join('人事_基本资料 rs5','rs5.员工编号=a.wgjs_bh5','LEFT')
+            ->join('人事_基本资料 rs6','rs6.员工编号=a.wgjs_bh6','LEFT')
+            ->where($where)
+            ->order('wgjs_rq desc, UniqId asc')
+            ->page($page,$limit)
+            ->select();
+        $total = db()->table('糊盒报工机时')->where($where)->count();
+        $data = ['total'=> $total,'rows'=> $rows];
+        if($rows){
+            $this->success('成功',$data);
+        }else{
+            $this->error('失败');
+        }
+    }
+    /**
+     * 详情
+     * @ApiMethod (GET)
+     * @param string $wgjs_rq 日期
+     * @param string $wgjs_bh1 员工编号
+     */
+    public function detail(){
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
+            $this->error('参数错误','UniqId',100);
+        }
+        $rows = db('糊盒报工机时')
+            ->alias('a')
+            ->field('LEFT(a.wgjs_rq, 10) as wgjs_rq, a.UniqId, 
+            wgjs_bh1,  wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1, 
+            wgjs_bh2,  wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2, 
+            wgjs_bh3,  wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3, 
+            wgjs_bh4,  wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4, 
+            wgjs_bh5,  wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5, 
+            wgjs_bh6,  wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6,
+            rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名)
+            as name3,rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名)
+            as name6')
+            ->join('人事_基本资料 rs1','rs1.员工编号=a.wgjs_bh1','LEFT')
+            ->join('人事_基本资料 rs2','rs2.员工编号=a.wgjs_bh2','LEFT')
+            ->join('人事_基本资料 rs3','rs3.员工编号=a.wgjs_bh3','LEFT')
+            ->join('人事_基本资料 rs4','rs4.员工编号=a.wgjs_bh4','LEFT')
+            ->join('人事_基本资料 rs5','rs5.员工编号=a.wgjs_bh5','LEFT')
+            ->join('人事_基本资料 rs6','rs6.员工编号=a.wgjs_bh6','LEFT')
+            ->where('a.UniqId', $req['UniqId'])
+            ->find();
+        if($rows!==false){
+            $this->success('成功',$rows);
+        }else{
+            $this->error('失败');
+        }
+    }
+    /**
+     * 修改
+     * @ApiMethod POST
+     */
+    public function edit()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
+            $this->error('参数错误','UniqId',100);
+        }
+
+        $arr = [
+            'wgjs_rq',
+            'wgjs_bh1', 'wgjs_bh2', 'wgjs_bh3', 'wgjs_bh4', 'wgjs_bh5', 'wgjs_bh6',
+            'wgjs_js1', 'wgjs_js2', 'wgjs_js3', 'wgjs_js4', 'wgjs_js5', 'wgjs_js6',
+            'wgjs_yy1', 'wgjs_yy2', 'wgjs_yy3', 'wgjs_yy4', 'wgjs_yy5', 'wgjs_yy6'
+        ];
+        $data = [];
+        foreach ($arr as $key => $value){
+            if (!isset($req[$value])){
+                continue;
+            }
+            $data[$value] = $req[$value];
+        }
+
+        if (count($data)==0){
+            $this->error('参数错误','',111);
+        }
+        $data['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
+        $data['mod_rq'] = date('Y-m-d H:i:s');
+        //开启事务
+        db()->startTrans();
+        try{
+            $sql = db('糊盒报工机时')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
+            $bool = db()->query($sql);
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
+    }
+    /**
+     * 新增
+     * @ApiMethod POST
+     */
+    public function add()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) || !isset($req['sys_id']) ){
+            $this->error('参数错误');
+        }
+        if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1']) || empty($req['sys_id'])){
+            $this->error('参数不能为空');
+        }
+        $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
+        $req['sys_rq'] = date('Y-m-d H:i:s');
+        //开启事务
+        db()->startTrans();
+        try{
+            $sql = db()->table('糊盒报工机时')->fetchSql(true)->insert($req);
+            $res= db()->query($sql);
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($res===false) $this->error('失败');
+
+        $this->success('成功');
+    }
+    /**
+     * 删除
+     * @ApiMethod (GET)
+     * @param string $wgjs_rq 日期
+     * @param string $wgjs_bh1 员工编号
+     */
+    public function del(){
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
+            $this->error('参数错误','UniqId',100);
+        }
+        //开启事务
+        db()->startTrans();
+        try{
+            $bool = db('糊盒报工机时')->where('UniqId',$req['UniqId'])->delete();
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
+
+    }
+}