Browse Source

Merge branch 'master' of https://git.7in6.com/Minong/mes-server-api

曹鹤洋 1 year ago
parent
commit
466e73d1b6

+ 533 - 0
application/api/controller/EmployeeDailySalary.php

@@ -0,0 +1,533 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use \think\Request;
+use \think\Db;
+/**
+ * 员工日工资查询接口
+ */
+class EmployeeDailySalary extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 首页
+     *
+     */
+    public function index()
+    {
+        $this->success('请求成功');
+    }
+
+    /**
+     * 员工日工资查询侧边栏
+     * @ApiMethod (GET)
+     */
+    public function getTab()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        // $rows = db()->table('绩效工资汇总')
+        // ->whereTime('sczl_rq', '>=', strtotime('-15 months'))
+        // ->group('sys_ny')
+        // ->order('sys_ny desc')
+        // ->limit(15)
+        // ->column('sys_ny');
+        $rows = db()->table('db_大废品')
+        ->whereTime('sys_rq', '>=', strtotime('-15 months'))
+        ->group("DATE_FORMAT(`sys_rq`, '%Y%m')")
+        ->order('sys_rq desc')
+        ->limit(15)
+        ->column("DATE_FORMAT(`sys_rq`, '%Y%m')");
+        // $row = db()->table('绩效工资汇总')
+        // ->field('sys_ny,人事_基本资料.所在部门')
+        // ->join('人事_基本资料','人事_基本资料.员工编号=绩效工资汇总.bh','LEFT')
+        // ->group('sys_ny,人事_基本资料.所在部门')
+        // ->where(['sys_ny'=>['between',"$rows[14],$rows[0]"]])
+        // ->order('sys_ny desc')
+        // ->fetchSql(true)
+        // ->select();
+        foreach($rows as $k=>$v){
+            $res[$k]['ny']=$v;
+            $res[$k]['bh']=db()->table('绩效工资汇总')
+            ->group('bh')
+            ->where('sys_ny',$v)
+            ->column('bh');
+        }
+        $rs = db()->table('人事_基本资料')->column('员工编号,所在部门');
+        foreach($res as $k=>$v){
+            foreach($v['bh'] as $value){
+                $res[$k]['bm'][]=rtrim($rs[$value]);
+            }
+        }
+        foreach($res as &$v){
+            unset($v['bh']);
+            $v['bm']=array_unique($v['bm']);
+            usort($v['bm'], function($a, $b) {
+                $order = array(
+                    '胶印车间',
+                    '凹印车间',
+                    '丝印车间',
+                    '模切车间',
+                    '检验车间',
+                    '精品试验车间',
+                    '品保部',
+                    '人力资源部',
+                    '生产部',
+                    '营销部'
+                );
+                $a_index = array_search($a, $order);
+                $b_index = array_search($b, $order);
+                return $a_index - $b_index;
+            });
+        }
+        foreach($res as $k=>$v){
+            $data[$k]['lable']=$v['ny'];
+            foreach($v['bm'] as $value){
+                $data[$k]['children'][]['lable']=$value;
+            }
+        }
+        $this->success('成功',$data);
+    }
+    
+
+    /**
+     * 员工日工资查询列表
+     * @ApiMethod (GET)
+     * @param string $date 年月
+     * @param string $department 部门
+     */
+    public function getList()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $res=db()->table('绩效工资汇总')
+            ->join('人事_基本资料','人事_基本资料.员工编号=绩效工资汇总.bh','LEFT')
+            ->field('bh,xm as 员工姓名,LEFT(sczl_rq, 10) as sczl_rq,sum(个人计件工资) as 计件工资,
+            sum(个人加班工资) as 加班工资,(sum(个人计件工资)+sum(个人加班工资)) as 日工资合计')
+            ->group('绩效工资汇总.bh,LEFT(sczl_rq, 10)')
+            ->where('sys_ny',$req['date'])
+            ->where('人事_基本资料.所在部门',$req['department'])
+            ->select();
+        if(!$res){
+            $this->error('失败');
+        }
+        $year=substr($req['date'],0,4);
+        $month=substr($req['date'],-2);
+        if($month==12){
+            $start_time=$year.'-12-01 00:00:00';
+            $end_time=($year+1).'-01-01 00:00:00';
+        }else{
+            $start_time=$year.'-'.$month.'-01 00:00:00';
+            $end_time=$year.'-'.($month+1).'-01 00:00:00';
+        }
+        $res1=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh1 as wgjs_bh,wgjs_js1 as wgjs_js')
+        ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh1','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
+        ->select();
+        $res2=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh2 as wgjs_bh,wgjs_js2 as wgjs_js')
+        ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh2','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
+        ->select();
+        $res3=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh3 as wgjs_bh,wgjs_js3 as wgjs_js')
+        ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh3','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
+        ->select();
+        $res4=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh4 as wgjs_bh,wgjs_js4 as wgjs_js')
+        ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh4','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
+        ->select();
+        $res5=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh5 as wgjs_bh,wgjs_js5  as wgjs_js')
+        ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh5','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
+        ->select();
+        $res6=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh6 as wgjs_bh,wgjs_js6 as wgjs_js')
+        ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh6','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
+        ->select();
+        $arr=array_merge($res1,$res2,$res3,$res4,$res5,$res6);
+        foreach($arr as $v){
+            if(isset($list[$v['wgjs_rq']][$v['wgjs_bh']])){
+                $list[$v['wgjs_rq']][$v['wgjs_bh']]+=$v['wgjs_js'];
+            }else{
+                $list[$v['wgjs_rq']][$v['wgjs_bh']]=$v['wgjs_js'];
+            }
+        }
+        foreach($res as &$v){
+            $v['sczl_rq']=str_replace('-','.',$v['sczl_rq']);
+            if(isset($list[$v['sczl_rq']][$v['bh']])){
+                $v['计时']=$list[$v['sczl_rq']][$v['bh']];
+            }else{
+                $v['计时']='';
+            }  
+        }
+        $this->success('成功',$res);
+    }
+    /**
+     * 员工日工资查询列表
+     * @ApiMethod (GET)
+     * @param string $date 年月
+     * @param string $code 员工编号
+     */
+    public function getAllList()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $res=db()->table('绩效工资汇总')
+            ->field('LEFT(sczl_rq, 10) as sczl_rq,sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc,sczl_yjno,sczl_gxh,sczl_type,
+            sczl_jtbh,sum(班组车头产量) as 班组车头产量,sum(班组换算产量) as 班组换算产量,工序难度系数,sum(个人计件工资)
+            as 个人计件工资,sum(个人加班工资) as 个人加班工资,sum(装版工时) as 装版工时,sum(保养工时) as 保养工时,
+            sum(打样工时) as 打样工时,sum(异常停机工时) as 异常停机工时,sum(车头产量占用机时) as 车头产量占用机时,日定额,
+            sum(达标定额) as 达标定额,千件工价,补产标准,bh,rtrim(xm) as xm,Rate')
+            ->join('工单_基本资料 g','g.Gd_gdbh=绩效工资汇总.sczl_gdbh','LEFT')
+            ->group('LEFT(sczl_rq, 10),sczl_gdbh')
+            ->where(['sys_ny'=>$req['date'],'bh'=>$req['code']])
+            ->select();
+        if(!$res){
+            $this->error('失败');
+        }
+        foreach($res as &$v){
+            $v['sczl_rq']=str_replace('-','.',$v['sczl_rq']);
+            if($v['sczl_yjno']>9){
+                $sczl_yjno=$v['sczl_yjno'];
+            }else{
+                $sczl_yjno='0'.$v['sczl_yjno'];
+            }
+            unset($v['sczl_yjno']);
+            if($v['sczl_gxh']>9){
+                $sczl_gxh=$v['sczl_gxh'];
+            }else{
+                $sczl_gxh='0'.$v['sczl_gxh'];
+            }
+            unset($v['sczl_gxh']);
+            $v['sczl_type']=$sczl_yjno.'-'.$sczl_gxh.'-->'.$v['sczl_type'];
+        }
+        $this->success('成功',$res);
+    }
+     /**
+     * 员工日工资查询详情
+     * @ApiMethod (GET)
+     * @param string $date 日期
+     * @param string $code 员工编号
+     */
+    public function getDetail()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $start_time=$req['date'].' 00:00:00';
+        $end_time=$req['date'].' 23:59:59';
+        $res=db()->table('绩效工资汇总')
+            ->field('LEFT(sczl_rq, 10) as sczl_rq,sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc,sczl_yjno,sczl_gxh,sczl_type,
+            sczl_jtbh,sum(班组车头产量) as 班组车头产量,sum(班组换算产量) as 班组换算产量,工序难度系数,sum(个人计件工资)
+            as 个人计件工资,sum(个人加班工资) as 个人加班工资,sum(装版工时) as 装版工时,sum(保养工时) as 保养工时,
+            sum(打样工时) as 打样工时,sum(异常停机工时) as 异常停机工时,sum(车头产量占用机时) as 车头产量占用机时,日定额,
+            sum(达标定额) as 达标定额,千件工价,补产标准,bh,rtrim(xm) as xm,Rate')
+            ->join('工单_基本资料 g','g.Gd_gdbh=绩效工资汇总.sczl_gdbh','LEFT')
+            ->group('LEFT(sczl_rq, 10),sczl_gdbh')
+            ->where(['sczl_rq'=>['between',"$start_time,$end_time"],'bh'=>$req['code']])
+            ->select();
+        if(!$res){
+            $this->error('失败');
+        }
+        foreach($res as &$v){
+            $v['sczl_rq']=str_replace('-','.',$v['sczl_rq']);
+            if($v['sczl_yjno']>9){
+                $sczl_yjno=$v['sczl_yjno'];
+            }else{
+                $sczl_yjno='0'.$v['sczl_yjno'];
+            }
+            unset($v['sczl_yjno']);
+            if($v['sczl_gxh']>9){
+                $sczl_gxh=$v['sczl_gxh'];
+            }else{
+                $sczl_gxh='0'.$v['sczl_gxh'];
+            }
+            unset($v['sczl_gxh']);
+            $v['sczl_type']=$sczl_yjno.'-'.$sczl_gxh.'-->'.$v['sczl_type'];
+        }
+        $this->success('成功',$res);
+    }
+
+    /**
+     * 获取计件工计时单信息
+     * @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('db_wgjs')->alias('d')
+            ->field('d.*, ')
+            ->join('工单_基本资料 g', 'd.')
+            ->where('d.UniqId',$UniqId)
+            ->select();
+
+
+        $this->success('成功',$rows);
+    }
+    /**
+     * 定位
+     * @ApiMethod GET
+    */
+    public function search(){
+        
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        $yg = db()->table('人事_基本资料')->where('员工姓名',$req['search'])->value('员工编号');
+        if($yg){
+            $req['search']=$yg;
+        }
+        $res=db()->table('绩效工资汇总')
+            // ->join('人事_基本资料','人事_基本资料.员工编号=绩效工资汇总.bh','LEFT')
+            ->field('bh,xm as 员工姓名,LEFT(sczl_rq, 10) as sczl_rq,sum(个人计件工资) as 计件工资,
+            sum(个人加班工资) as 加班工资,(sum(个人计件工资)+sum(个人加班工资)) as 日工资合计')
+            ->group('绩效工资汇总.bh,LEFT(sczl_rq, 10)')
+            ->where('sys_ny',$req['date'])
+            ->where('bh',$req['search'])
+            // ->where('人事_基本资料.所在部门',$req['department'])
+            ->select();
+        if(!$res){
+            $this->error('失败');
+        }
+        $year=substr($req['date'],0,4);
+        $month=substr($req['date'],-2);
+        if($month==12){
+            $start_time=$year.'-12-01 00:00:00';
+            $end_time=($year+1).'-01-01 00:00:00';
+        }else{
+            $start_time=$year.'-'.$month.'-01 00:00:00';
+            $end_time=$year.'-'.($month+1).'-01 00:00:00';
+        }
+        $res1=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh1 as wgjs_bh,wgjs_js1 as wgjs_js')
+        // ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh1','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'wgjs_bh1'=>$req['search']])
+        ->select();
+        $res2=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh2 as wgjs_bh,wgjs_js2 as wgjs_js')
+        // ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh2','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'wgjs_bh2'=>$req['search']])
+        ->select();
+        $res3=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh3 as wgjs_bh,wgjs_js3 as wgjs_js')
+        // ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh3','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'wgjs_bh3'=>$req['search']])
+        ->select();
+        $res4=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh4 as wgjs_bh,wgjs_js4 as wgjs_js')
+        // ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh4','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'wgjs_bh4'=>$req['search']])
+        ->select();
+        $res5=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh5 as wgjs_bh,wgjs_js5  as wgjs_js')
+        // ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh5','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'wgjs_bh5'=>$req['search']])
+        ->select();
+        $res6=db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh6 as wgjs_bh,wgjs_js6 as wgjs_js')
+        // ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh6','LEFT')
+        ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'wgjs_bh6'=>$req['search']])
+        ->select();
+        $arr=array_merge($res1,$res2,$res3,$res4,$res5,$res6);
+        foreach($arr as $v){
+            if(isset($list[$v['wgjs_rq']][$v['wgjs_bh']])){
+                $list[$v['wgjs_rq']][$v['wgjs_bh']]+=$v['wgjs_js'];
+            }else{
+                $list[$v['wgjs_rq']][$v['wgjs_bh']]=$v['wgjs_js'];
+            }
+        }
+        foreach($res as &$v){
+            $v['sczl_rq']=str_replace('-','.',$v['sczl_rq']);
+            if(isset($list[$v['sczl_rq']][$v['bh']])){
+                $v['计时']=$list[$v['sczl_rq']][$v['bh']];
+            }else{
+                $v['计时']='';
+            }  
+        }
+        $this->success('成功',$res);
+    }
+    /**
+     * 详情
+     * @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['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
+            $this->error('参数错误');
+        }else{
+        }
+        if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
+            $this->error('参数不能为空');
+        }
+        $rows = db()->table('db_wgjs1')
+        ->field('LEFT(wgjs_rq, 10) as wgjs_rq, 
+        wgjs_bh1, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1, 
+        wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2, 
+        wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3, 
+        wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4, 
+        wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5, 
+        wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as 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,wgjs_冲定额1,wgjs_冲定额2,wgjs_冲定额3,wgjs_冲定额4,wgjs_冲定额5,wgjs_冲定额6')
+        ->join('人事_基本资料 rs1','rs1.员工编号=db_wgjs1.wgjs_bh1','LEFT')
+        ->join('人事_基本资料 rs2','rs2.员工编号=db_wgjs1.wgjs_bh2','LEFT')
+        ->join('人事_基本资料 rs3','rs3.员工编号=db_wgjs1.wgjs_bh3','LEFT')
+        ->join('人事_基本资料 rs4','rs4.员工编号=db_wgjs1.wgjs_bh4','LEFT')
+        ->join('人事_基本资料 rs5','rs5.员工编号=db_wgjs1.wgjs_bh5','LEFT')
+        ->join('人事_基本资料 rs6','rs6.员工编号=db_wgjs1.wgjs_bh6','LEFT')
+        ->where(['wgjs_rq'=>$req['wgjs_rq'].' 00:00:00','wgjs_bh1'=>$req['wgjs_bh1']])
+        ->find();
+        if($rows){
+        $this->success('成功',$rows);
+        }else{
+            $this->error('失败');
+        }   
+    }
+     /**
+     * 修改
+     * @ApiMethod POST
+    */
+    public function edit()
+    {
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        // $req = ['wgjs_js1'=>12,'wgjs_rq'=>'2023-10-12','wgjs_bh1'=>'ZM01269'];
+
+        if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
+            $this->error('参数错误');
+        }
+        if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
+            $this->error('参数不能为空');
+        }
+
+        $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
+        $req['mod_rq'] = date('Y-m-d H:i:s');
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $sql = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'],'wgjs_bh1'=>$req['wgjs_bh1']])
+            ->fetchSql(true)->update($req);
+            $res= db()->query($sql);
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($res===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']) ){
+            $this->error('参数错误');
+        }
+        if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
+            $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('db_wgjs1')->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['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
+            $this->error('参数错误');
+        }else{
+        }
+        if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
+            $this->error('参数不能为空');
+        }
+        $rows = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'].' 00:00:00','wgjs_bh1'=>$req['wgjs_bh1']])
+        ->delete();
+        if($rows){
+        $this->success('成功');
+        }else{
+            $this->error('失败');
+        }   
+    }
+}

+ 254 - 5
application/api/controller/Facility.php

@@ -289,7 +289,7 @@ class Facility extends Api
         $lastTechonUniqId = Db::table('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
         $startTechonUniqId = $lastTechonUniqId['UniqId']-10000;
         $lastYieldUniqId = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
-        $startYieldUniqId = $lastYieldUniqId['UniqId']-10000;
+        $startYieldUniqId = $lastYieldUniqId['UniqId']-100000;
         $workOrder = Db::table('设备_产量计酬')->where('sczl_jtbh',$machine)->field('sczl_gdbh')->where('UniqId','>',$startYieldUniqId)->order('UniqId desc')->find();
         $startTime = Db::table('工单_工艺资料')->where('Gy0_gdbh',$workOrder['sczl_gdbh'])->where('Gy0_sbbh',$machine)->where('UniqId','>',$startTechonUniqId)->field('Gy0_sj1')->order('UniqId desc')->find();
         $where = [
@@ -375,7 +375,6 @@ class Facility extends Api
         $this->success('成功',$data);
     }
 
-    //
 
     /**
      * 班组人员及分配比例
@@ -402,7 +401,8 @@ class Facility extends Api
         $field = 'rtrim(sczl_bzdh) as 班组号,rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
         rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
         rtrim(sczl_bh10) as bh10,rtrim(sczl_rate1) as rate1,rtrim(sczl_rate2) as rate2,rtrim(sczl_rate3) as rate3,rtrim(sczl_rate4) as rate4,
-        rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10';
+        rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
+        rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
         $team = Db::table('设备_产量计酬')
             ->where('sczl_jtbh',$machine)
             ->field($field)
@@ -416,9 +416,10 @@ class Facility extends Api
             }else{
                 $data[$k]['status'] = 0;
             }
+            $data[$k]['ID'] = $v['ID'];
             $data[$k]['班组号'] = $v['班组号'];
             for ($i=1;$i<11;$i++){
-                if ($v['bh'.$i] != ''){
+                if ($v['bh'.$i] != '' && $v['bh'.$i] != '000000'){
                     $name = Db::table('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
                     $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
                 }
@@ -427,7 +428,6 @@ class Facility extends Api
         $this->success('成功',$data);
     }
 
-    //当班产量明细
 
     /**
      * 当班产量明细
@@ -553,4 +553,253 @@ class Facility extends Api
         $data['inspectiontime'] = $InspectionTime;
         $this->success('成功',$data);
     }
+
+    //班组维护
+
+    public function TeamMaintenance()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+        $data = $this->request->param();
+        if (empty($data)){
+            $this->error('参数错误');
+        }
+        $field = 'rtrim(sczl_bzdh) as sczl_bzdh,rtrim(sczl_bh1) as sczl_bh1,rtrim(sczl_bh2) as sczl_bh2,rtrim(sczl_bh3) as sczl_bh3,rtrim(sczl_bh4) as sczl_bh4,
+        rtrim(sczl_bh5) as sczl_bh5,rtrim(sczl_bh6) as sczl_bh6,rtrim(sczl_bh7) as sczl_bh7,rtrim(sczl_bh8) as sczl_bh8,rtrim(sczl_bh9) as sczl_bh9,
+        rtrim(sczl_bh10) as sczl_bh10,rtrim(sczl_rate1) as sczl_rate1,rtrim(sczl_rate2) as sczl_rate2,rtrim(sczl_rate3) as sczl_rate3,rtrim(sczl_rate4) as sczl_rate4,
+        rtrim(sczl_rate5) as sczl_rate5,rtrim(sczl_rate6) as sczl_rate6,rtrim(sczl_rate7) as sczl_rate7,rtrim(sczl_rate8) as sczl_rate8,
+        rtrim(sczl_rate9) as sczl_rate9,rtrim(sczl_rate10) as sczl_rate10';
+        $TeamList = Db::table('设备_班组资料')->where('UniqId',$data['ID'])->field($field)->find();
+
+    }
+
+
+    /**
+     * 机台编号列表
+     * @ApiMethod  (GET)
+     * @return void
+     */
+    public function MachineList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $list = Db::table('设备_基本资料')->column('设备编号');
+        if (empty($list)){
+            $this->error('未找到机台编号');
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 删除班组信息
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function teamDel()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $res = Db::table('设备_班组资料')
+            ->where('UniqId',$param['UniqId'])
+            ->delete();
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+
+    }
+
+    //制程检验记录->指标检验
+
+    public function ProcessInspectionRecords()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+//        $filed = ''
+    }
+
+    /**
+     * 管理人员现场巡检记录->展示
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function FieldInspectionRecord()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $last_id = Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
+        $startId = $last_id['UniqId']-100000;
+        $date = date('Y-m-d H:i:s',time());
+        $startTime = date('Y-m-d 08:30:00',time());
+        if ($date<$startTime){
+            $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
+        }
+        $where = [
+            '工单编号' => $param['workOrder'],
+            '开工时间' => $startTime,
+            '类别' => '现场巡查记录',
+            '班组编号' => $param['team']
+        ];
+        $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
+        rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
+        rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
+        $list = Db::table('制程检验_记录')->where($where)->where('UniqId','>',$startId)->field($filed)->select();
+        if (empty($list)){
+            $this->error('未找到该工单当前班次巡检记录');
+        }
+        foreach ($list as $key=>$value){
+            $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
+            $list[$key]['归属时段'] = $value['开工时间'];
+            $list[$key]['分钟差数'] = $number;
+            if ($number != 0){
+                $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
+            }
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 管理人员现场巡检记录->添加
+     * @ApiMethod (POST)
+     * @param  void
+     * @return void
+     */
+
+    public function FieldInspectionRecordAdd()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        if ($param['processCode']<10){
+            $param['processCode'] = '0'.$param['processCode'];
+        }
+        $date = date('Y-m-d H:i:s',time());
+        $startTime = date('Y-m-d 08:30:00',time());
+        if ($date<$startTime){
+            $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
+        }
+        $data = [
+            '类别' => $param['category'],
+            '工单编号' => $param['workOrder'],
+            '印件号' => $param['printCode'],
+            '工序名称' => $param['processCode'].'-'.$param['process'],
+            '流程单号' => $param['flowCode'],
+            '设备编号' => $param['machine'],
+            '班组编号' => $param['team'],
+            '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
+            '相关标准' => '',
+            '量测仪器' => '',
+            '检验结果' => '',
+            '检验备注' => $param['remark'],
+            '提交时间' => date('Y-m-d H:i:s',time()),
+            '开工时间' => $startTime,
+            'sys_id' => '',
+            'sys_rq' => date('Y-m-d H:i:s',time()),
+            'mod_rq' => '',
+            'UniqId' => Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
+        ];
+        $sql = Db::table('制程检验_记录')->fetchSql(true)->insert($data);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 设备点检->左侧菜单栏
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     */
+    public function SpotCheckItem()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = Db::table('设备_点检项目')
+            ->where('适用机型','LIKE','%;'.$param['machine'].';%')
+            ->distinct(true)
+            ->column('部件名称','部件编号');
+        if (empty($list)){
+            $this->error('未找到检验项目');
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 设备点检->检测项目
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function  InspectionItem()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = Db::table('设备_点检项目')
+            ->where('部件名称',$param['unitName'])
+            ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
+            ->select();
+        if (empty($list)){
+            $this->error('未找到检测项目');
+        }
+        $this->success('成功',$list);
+    }
+
+    //设备点检->检测记录添加
+
+    public  function InspectionItemAdd()
+    {
+        if ($this->request->isPost()  === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+
+    }
 }

+ 372 - 7
application/api/controller/Manufacture.php

@@ -14,6 +14,34 @@ class Manufacture extends Api
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
 
+    //查找工单
+    public function WorkOrderSearch(){
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $workOder = input('workOrder');
+        $printName = input('printName');
+        if (empty($workOder)){
+            $this->error('参数错误');
+        }
+        $where = [
+            'Gd_gdbh' => $workOder
+        ];
+        if (!empty($printName)){
+            $where['成品名称'] = $printName;
+        }
+        $field = 'rtrim(Gd_生产分类) as 生产分类,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,
+        rtrim(接单日期) as 接单日期,rtrim(交货日期) as 交货日期,rtrim(订单数量) as 订单数量,rtrim(计量单位) as 计量单位,rtrim(Gd_khmc) as 客户名称,
+        rtrim(Gd_客户代号) as 客户编号,rtrim(Gd_desc) as 备注,rtrim(客户料号) as 客户料号,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,
+        rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID,rtrim(投料率) as 投料率,rtrim(销售订单号) as 销售订单号';
+        $list = Db::table('工单_基本资料')->where($where)->field($field)->find();
+        if (empty($list)){
+            $this->error('未找到该工单');
+        }
+        $this->success('成功',$list);
+    }
+
+
     /**
      * 计划中工单
      * @ApiMethod (GET)
@@ -40,8 +68,6 @@ class Manufacture extends Api
             $this->error('失败');
         }
         foreach ($list as $key=>$value){
-//                $cateGory = Db::table('产品_基本资料')->where('产品编号',$value['产品代号'])->find();
-//                $list[$key]['产品类别'] = $cateGory['产品类别'];
             $list[$key]['订单数量'] = rtrim((float)$value['订单数量']);
         }
         $this->success('成功',$list);
@@ -87,7 +113,7 @@ class Manufacture extends Api
             }else{
                 $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
             }
-            unset($list[$key]['Gy0_yjno'],$list[$key]['Gy0_gxh'],$list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
+            unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
         }
         $this->success('成功',$list);
     }
@@ -190,7 +216,7 @@ class Manufacture extends Api
             }else{
                 $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
             }
-            unset($list[$key]['Gy0_yjno'],$list[$key]['Gy0_gxh'],$list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
+            unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
             $list[$key]['机组'] = $value['设备编号'];
             $orderDetail = Db::table('工单_基本资料')->where('Gd_gdbh',$list[$key]['工单编号'])->field('rtrim(计划投料) as 计划投料')->find();
             $list[$key]['工序产量'] = $orderDetail['计划投料'];
@@ -215,16 +241,16 @@ class Manufacture extends Api
             $this->error('请求错误');
         }
         $data = [];
-        $department = Db::table('设备_基本资料')->distinct(true)->column('使用部门');
+        $department = Db::table('设备_基本资料')->distinct(true)->cache(true)->column('使用部门');
         if (empty($department)){
             $this->error('为获取到机台数据');
         }
         foreach ($department as $value){
             if (rtrim($value) !== '研发中心'){
-                $benchClass = Db::table('设备_基本资料')->where('使用部门',$value)->distinct(true)->column('设备编组');
+                $benchClass = Db::table('设备_基本资料')->where('使用部门',$value)->distinct(true)->cache(true)->column('设备编组');
                 foreach ($benchClass as $v){
                     if (rtrim($v) !== ''){
-                        $machine = Db::table('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
+                        $machine = Db::table('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
                         foreach ($machine as $kk=>$vv){
                             $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
                         }
@@ -234,4 +260,343 @@ class Manufacture extends Api
         }
         $this->success('成功',$data);
     }
+
+
+    /**
+     * 工单状态设置
+     * @ApiMethod (GET)
+     * @param string $workOrder  工单编号
+     * @param string $status   工单状态
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function StatusEdit()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+        $workOrder = input('workOrder');
+        $status = input('status');
+        if (empty($workOrder) || empty($status)){
+            $this->error('参数错误');
+        }
+        $sql = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->fetchSql(true)->update(['gd_statu'=>$status]);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 更改工序状态
+     * @ApiMethod (GET)
+     * @param void
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function complete()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $data = $this->request->param();
+        if (empty($data)){
+            $this->error('参数错误');
+        }
+        $where = [
+            'Gy0_gdbh' => $data['workOrder'],
+            'Gy0_gxh'  => $data['processCode']
+        ];
+        $sql = Db::table('工单_工艺资料')->where($where)->fetchSql(true)->update(['PD_WG'=>date('Y-m-d H:i:s',time())]);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 加入排产
+     * @ApiMethod (POST)
+     * @param void $data
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+
+    public function ProductionSchedulingAdd()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+        $data = $this->request->param();
+        if (empty($data)){
+            $this->error('参数错误');
+        }
+        $where = [
+            'Gy0_gdbh' => $data['workOrder'],
+            'Gy0_sbbh' => $data['machine'],
+            'Gy0_yjno' => $data['printCode'],
+            'Gy0_gxh'  => $data['processCode']
+        ];
+        $lastTime = Db::table('工单_工艺资料')
+            ->where(['Gy0_sbbh'=>$where['Gy0_sbbh'],'Gy0_sj2'=>['<>','1900-01-01 00:00:00'],'Gy0_sj2'=>['<','2099-01-01 00:00:00']])
+            ->field('rtrim(Gy0_sj2) as sj2')
+            ->order('Gy0_sj2 desc')
+            ->find();
+        $row = Db::table('工单_工艺资料')
+            ->where($where)
+            ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
+            ->find();
+        $endTime = date('Y-m-d H:i:s',strtotime($lastTime['sj2']) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
+        $sql = Db::table('工单_工艺资料')
+            ->where($where)
+            ->fetchSql(true)
+            ->update(['Gy0_sj1'=>$lastTime['sj2'],'Gy0_sj2'=>$endTime,'Mod_rq'=>date('Y-m-d H:i:s',time())]);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 暂停排产
+     * @ApiMethod (POST)
+     * @param  void  $data
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+
+    public function ProductionSchedulingPause()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+        $data = $this->request->param();
+        if (empty($data)){
+            $this->error('参数错误');
+        }
+        $where = [
+            'Gy0_gdbh' => $data['workOrder'],
+            'Gy0_sbbh' => $data['machine'],
+            'Gy0_yjno' => $data['printCode'],
+            'Gy0_gxh'  => $data['processCode']
+        ];
+        $machine = $where['Gy0_sbbh'];
+        $endTime = Db::table('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2')->find()['sj2'];
+        if ($endTime <= '1900-01-01 00:00:00' || $endTime >= '2099-01-01 00:00:00'){
+            $this->error('该工单不是制程中工单');
+        }
+        $sql = Db::table('工单_工艺资料')
+            ->where($where)
+            ->fetchSql(true)
+            ->update(['Gy0_sj1'=>'1900-01-01 00:00:00','Gy0_sj2'=>'1900-01-01 00:00:00','Mod_rq'=>date('Y-m-d H:i:s')]);
+        $row = Db::table('工单_工艺资料')
+            ->where($where)
+            ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
+            ->find();
+        $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'];
+        $res = Db::query($sql);
+        $rechSql = "UPDATE `工单_工艺资料` SET Gy0_sj1 = DATE_ADD(Gy0_sj1, INTERVAL {$number} HOUR),Gy0_sj2 = DATE_ADD(Gy0_sj2, INTERVAL {$number} HOUR) WHERE Gy0_sbbh = '{$machine}' AND Gy0_sj1 >= '{$endTime}' AND Gy0_sj1 < '2099-01-01 00:00:00'";
+        $rechres = Db::query($rechSql);
+        if ($res !== false && $rechres !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 工序状态更正
+     * @ApiMethod (GET)
+     * @param  void $param
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function ProcessStatusCorrection()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $where = [
+            'Gy0_gdbh' => $param['workOrder'],
+            'Gy0_sbbh' => ['<>','']
+        ];
+        $workOrder = $where['Gy0_gdbh'];
+        $field = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_sbbh) as 设备代号,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_ls) as ls,rtrim(PD_WG) as 完工时间';
+        $list = Db::table('工单_工艺资料')->where($where)->field($field)->order('Gy0_gxh')->select();
+        if (empty($list)){
+            $this->error('未找到该工单工艺资料');
+        }
+        $yieldSql = "SELECT a.Gy0_gxh as gxh,SUM(b.sczl_cl) as cl FROM `工单_工艺资料` AS a JOIN `设备_产量计酬` as b ON a.Gy0_gxh = b.sczl_gxh WHERE a.Gy0_gdbh = '{$workOrder}' AND b.sczl_gdbh = '{$workOrder}' GROUP BY a.Gy0_gxh";
+        $yield = Db::query($yieldSql);
+        foreach ($list as $key=>$value){
+            if ($value['yjno']<10){
+                $value['yjno'] = '0'.$value['yjno'];
+            }
+            if ($value['gxh']<10){
+                $value['gxh'] = '0'.$value['gxh'];
+            }
+            $list[$key]['印件及工序'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
+            foreach ($yield as $k=>$v){
+                if ($v['gxh'] === $list[$key]['gxh']){
+                    $list[$key]['计划产量/已完成'] = ($value['计划接货数']/$value['ls']).'/'.$v['cl'];
+                    $list[$key]['完成率'] = number_format($v['cl']/($value['计划接货数']/$value['ls']),4)*100 . '%';
+                }else{
+                    $list[$key]['计划产量/已完成'] = ($value['计划接货数']/$value['ls']).'/0';
+                    $list[$key]['完成率'] = '';
+                }
+            }
+            if ($value['完工时间'] == '1900-01-01 00:00:00') {
+                $list[$key]['完工时间'] = '';
+            }
+            unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['计划接货数'],$list[$key]['ls']);
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 班次选择
+     * @ApiMethod (GET)
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function ScheduleSelection()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $list = Db::table('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
+        if (empty($list)){
+            $this->error('未找到班次数据');
+        }
+        foreach ($list as $key=>$value){
+            $list[$key]['detail'] = $value['班次代号'].'||'.$value['desc_'].'||'.$value['stdtime'];
+            unset($list[$key]['desc_'],$list[$key]['stdtime']);
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 车间设备排程展示
+     * @ApiMethod (GET)
+     * @param  void $param
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+
+    public function EquipmentScheduling()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('参数错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $where = [
+            'Gy0_sbbh' => $param['machine'],
+            'Gy0_sj1' => ['between',['1900-01-01 00:00:01','2098-12-31 23:59:59']],
+            'PD_WG' => '1900-01-01 00:00:00'
+        ];
+        $machine = $where['Gy0_sbbh'];
+        if (isset($param['class'])){
+            $where['Gy0_班次安排'] = $param['class'];
+        }
+        $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,
+        rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,rtrim(Gy0_班次安排) as 班次安排,rtrim(工序备注) as 排单备注,
+        rtrim(Gy0_最早开工时间) as 最早开工时间,rtrim(Gy0_sj1) as 计划开工时间,rtrim(Gy0_sj2) as 计划完工时间,rtrim(Gy0_yjno) as yjno,
+        rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_ls) as ls';
+        $list = Db::table('工单_工艺资料')->where($where)->field($filed)->cache(true)->select();
+        if (empty($list)){
+            $this->error('未找到该机台制程中产品');
+        }
+        $Sql = "SELECT SUM(c.sczl_cl) as 已完成,rtrim(c.sczl_gdbh) as gdbh
+                FROM `工单_工艺资料` AS a  JOIN `设备_产量计酬` AS c ON a.Gy0_gdbh = c.sczl_gdbh 
+                AND a.Gy0_gxh = c.sczl_gxh WHERE a.Gy0_sbbh = '{$machine}' AND a.Gy0_sj1 > '1900-01-01 00:00:00' 
+                AND a.Gy0_sj1 < '2099-01-01 00:00:00' AND a.PD_WG = '1900-01-01 00:00:00' GROUP BY a.Gy0_gdbh";
+        $res = Db::query($Sql);
+        foreach ($list as $key=>$value){
+            $list[$key]['计划接货数'] = (int)round($value['计划接货数']/$value['ls']);
+            if ($value['yjno']<10){
+                $value['yjno'] = '0'.$value['yjno'];
+            }
+            if ($value['gxh']<10){
+                $value['gxh'] = '0'.$value['gxh'];
+            }
+            $list[$key]['印件/工序'] = $value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
+            unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['ls']);
+            $list[$key]['已完成'] = 0;
+            foreach ($res as $k=>$v){
+                if ($value['工单编号'] === $v['gdbh']){
+                    $list[$key]['已完成'] = $v['已完成'];
+                }
+            }
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 车间设备排程编辑
+     * @ApiMethod (POST)
+     * @param  void $param
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function EquipmentSchedulingEdit()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $data = [
+            'Gy0_小时产能' => $param['capacity'],
+            'Gy0_生产工时' => $param['ProductionHours'],
+            'Gy0_辅助工时' => $param['AuxiliaryHours'],
+            'Gy0_班次安排' => $param['shift'],
+            '工序备注' => $param['remark'],
+            'Gy0_最早开工时间' => $param['start']=''?'1900-01-01 00:00:00':$param['start'],
+            'Gy0_sj1' => date('Y-m-d H:i:s',strtotime($param['projectTime'])),
+            'Gy0_sj2' => date('Y-m-d HY-m-d',strtotime($param['projectTime'])+(ceil($param['ProductionHours'])+ceil($param['AuxiliaryHours']))*3600),
+        ];
+        $sql = Db::table('工单_工艺资料')
+            ->where(['Gy0_gdbh'=>$param['workOrder'],'Gy0_sbbh'=>$param['machine']])
+            ->fetchSql(true)
+            ->update($data);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
 }

+ 1 - 1
application/api/controller/Product.php

@@ -154,7 +154,7 @@ class Product extends Api
             $option['a.Gy0_方案'] = $params['plan'];
         }
         $gy_field = 'rtrim(a.Gy0_方案) as programme,a.Gy0_yjno,a.Gy0_gxh,rtrim(a.gy0_gxmc) as gy0_gxmc,a.A类产能 as A_power,rtrim(a.Gy0_shdh) as Gy0_shdh,rtrim(a.Gy0_sbbh) as Gy0_sbbh,
-        a.工价系数 as difficulty_coe,a.损耗系数 as loss_coe,a.Gy0_Ms as ms_coe,a.Gy0_Ks,a.Gy0_ls,rtrim(a.Gy0_site) as Gy0_site,rtrim(a.Add_gxmc) as Add_gxmc,a.UniqID,
+        a.工价系数 as difficulty_coe,a.损耗系数 as loss_coe,a.Gy0_Ms as ms_coe,a.Gy0_Ks,a.Gy0_ls,rtrim(a.Gy0_site) as Gy0_site,rtrim(a.Add_gxmc) as Add_gxmc,a.UniqID,a.Gy0_辅助工时,
         rtrim(a.工序备注) as remark,a.人工检_正品板 as artificial_zp,a.人工检_次品板 as artificial_cp,a.人工检_废检 as artificial_fj,a.机检_正品板 as machine_zp,a.机检_次品板 as machine_cp,
         a.机检_废检 as machine_fj,rtrim(b.客户名称) as custom_name,rtrim(b.产品名称) as product_name';
         $gyRes = Db::name('产品_工艺资料')->alias('a')

+ 1 - 1
application/api/controller/Staff.php

@@ -59,7 +59,7 @@ class Staff extends Api
         if (empty($pages)){
             $pages = 1;
         }
-        $field = '员工编号,rtrim(员工姓名) as 员工姓名,性别,聘用日期,转正日期,rtrim(所在部门) as 所在部门,rtrim(职称职务) as 职称职务,rtrim(身份证号) as 身份证号,出生日期,
+        $field = '员工编号,rtrim(员工姓名) as 员工姓名,性别,聘用日期,转正日期,rtrim(所在部门) as 所在部门,rtrim(部门编码) as 部门编码,rtrim(职称职务) as 职称职务,rtrim(身份证号) as 身份证号,出生日期,
         rtrim(人员性质) as 人员性质,rtrim(人员类别) as 人员类别,班次类型,工资表类别,薪酬核算分组,rtrim(在职状态) as 在职状态,rtrim(U8在职) as U8在职,U8离职日期,rtrim(sys_id) as sys_id,sys_rq,mod_rq';
         $list = Db::name('人事_基本资料')->where($where)->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select();
         $total = Db::name('人事_基本资料')->where($where)->count();

+ 1 - 1
application/api/controller/WorkOrder.php

@@ -180,6 +180,7 @@ class WorkOrder extends Api
         if ($this->request->isGet() === false){
             $this->error('请求错误');
         }
+
         $Gd_gdbh = input('Gd_gdbh');
         if (empty($Gd_gdbh)){
             $this->error('参数错误');
@@ -697,7 +698,6 @@ class WorkOrder extends Api
         }
     }
 
-    //
 
     /**
      * 修正工单核算参数->数据获取

+ 76 - 14
application/api/controller/WorkOrderVerification.php

@@ -746,18 +746,80 @@ class WorkOrderVerification extends Api
         }
 
     }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+    /**
+     * 工单质检废品统计
+     * @ApiMethod GET
+     * @params string order
+    */
+    public function getOrderWasteTotal(){
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])) {
+            $this->error('参数错误');
+        }
+        $field = '
+        rtrim(a.fp_lb1) as fp_lb1,rtrim(a.fp_lb2) as fp_lb2,rtrim(a.fp_lb3) as fp_lb3,rtrim(a.fp_lb4) as fp_lb4,rtrim(a.fp_lb5) as fp_lb5,rtrim(a.fp_lb6) as fp_lb6,rtrim(a.fp_lb7) as fp_lb7,
+        rtrim(a.fp_lb8) as fp_lb8,rtrim(a.fp_lb9) as fp_lb9,rtrim(a.fp_lb10) as fp_lb10,rtrim(a.fp_lb11) as fp_lb11,rtrim(a.fp_lb12) as fp_lb12,rtrim(a.fp_lb13) as fp_lb13,
+        a.fp_sl1,a.fp_sl2,a.fp_sl3,a.fp_sl4,a.fp_sl5,a.fp_sl6,a.fp_sl7,a.fp_sl8,a.fp_sl9,a.fp_sl10,a.fp_sl11,a.fp_sl12,a.fp_sl13,
+        a.fp_bh1,a.fp_bh2,a.fp_bh3,a.fp_bh4,a.fp_bh5,a.fp_bh6,a.fp_bh7,a.fp_bh8,a.fp_bh9,a.fp_bh10,a.fp_bh11,a.fp_bh12,a.fp_bh13,
+        rtrim(a.fp_gxmc1) as fp_gxmc1, rtrim(a.fp_gxmc2) as fp_gxmc2, rtrim(a.fp_gxmc3) as fp_gxmc3, rtrim(a.fp_gxmc4) as fp_gxmc4, rtrim(a.fp_gxmc5) as fp_gxmc5, rtrim(a.fp_gxmc6) as fp_gxmc6, 
+        rtrim(a.fp_gxmc7) as fp_gxmc7,rtrim(a.fp_gxmc8) as fp_gxmc8, rtrim(a.fp_gxmc9) as fp_gxmc9, rtrim(a.fp_gxmc10) as fp_gxmc10, rtrim(a.fp_gxmc11) as fp_gxmc11, rtrim(a.fp_gxmc12) as fp_gxmc12, 
+        rtrim(a.fp_gxmc13) as fp_gxmc13,a.qczl_num,a.qczl_yjno,rtrim(b.成品代号) as product_code,rtrim(b.成品名称) as product_name,b.订单数量,rtrim(b.计量单位) as 计量单位,b.实际投料,b.交货日期,
+        c.yj_ls,d.jjcp_sl,d.jjcp_sj
+        ';
+        $where['a.qczl_gdbh'] = $params['order'];
+        $where['b.行号'] = 1;
+        $data = Db::name('db_qczl')->alias('a')
+            ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh','left')
+            ->join('工单_印件资料 c','a.qczl_gdbh = c.Yj_Gdbh','left')
+            ->join('成品入仓 d','a.qczl_gdbh = d.jjcp_gdbh','left')
+            ->where($where)
+            ->field($field)->select();
+        $list = [];
+        $j = 0;
+        foreach ($data as $entry) {
+            for ($i = 1; $i <= 13; $i++) {
+                $labelKey = "fp_lb" . $i;
+                $slKey = "fp_sl" . $i;
+                $bhKey = "fp_bh" . $i;
+                $gxhKey = "fp_gxmc". $i;
+                if (!empty($entry[$labelKey]) && $entry[$slKey] > 0) {
+                    $list[$j]['fp_lb'] = $entry[$labelKey];
+                    $list[$j]['fp_sl'] = $entry[$slKey];
+                    $list[$j]['fp_bh'] = $entry[$bhKey];
+                    $name = Db::name('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
+                    $list[$j]['fp_name'] =  $name;
+                    $list[$j]['fp_gxh'] = empty(substr($entry[$gxhKey],0,2)) ? "0" : substr($entry[$gxhKey],0,2);
+                    $list[$j]['qczl_num'] = $entry['qczl_num'];
+                    $list[$j]['qczl_yjno'] = $entry['qczl_yjno'];
+                    $list[$j]['product_code'] = $entry['product_code'];
+                    $list[$j]['product_name'] = $entry['product_name'];
+                    $list[$j]['订单数量'] = $entry['订单数量'];
+                    $list[$j]['计量单位'] = $entry['计量单位'];
+                    $list[$j]['交货日期'] = substr($entry['交货日期'],0,10);
+                    $list[$j]['yj_ls'] = $entry['yj_ls'];
+                    $list[$j]['jjcp_sl'] = $entry['jjcp_sl'];
+                    $list[$j]['jjcp_sj'] = substr($entry['jjcp_sj'],0,10);
+                    $j++;
+                }
+            }
+        }
+        $summedData = [];
+        foreach ($list as $item) {
+            $key = $item['qczl_num'] . $item['fp_lb'];
+            if (!isset($summedData[$key])) {
+                $summedData[$key] = $item;
+            } else {
+                $summedData[$key]['fp_sl'] += $item['fp_sl'];
+            }
+        }
+        $fpGxhColumn = array_column($summedData, 'fp_gxh');
+        $qczlNumColumn = array_column($summedData, 'qczl_num');
+        $fpLbColumn = array_column($summedData, 'fp_lb');
+        array_multisort($fpGxhColumn, SORT_ASC, $qczlNumColumn, SORT_ASC, $fpLbColumn, SORT_ASC, $summedData);
+        $summedData = array_values($summedData);
+        $this->success('请求成功',$summedData);
+    }
 }