| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use Monolog\Handler\IFTTTHandler;
- use Overtrue\Socialite\Providers\WeWorkProvider;
- use think\Db;
- use think\Request;
- use function fast\e;
- /**
- *
- * 生产排单管理
- */
- class Manufacture extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 计划中工单
- * @ApiMethod (GET)
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function Project()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- if ($param['status'] === '计划中'){
- $status = '3-计划中';
- }else{
- $status = '1-已完工';
- }
- $page = 0;
- $limit = 15;
- if (isset($param['page'])){
- $page = $param['page'];
- }
- if (isset($param['limit'])){
- $limit = $param['limit'];
- }
- $where = [
- 'gd_statu' => $status,
- '行号' => '1',
- ];
- if (isset($param['search'])){
- $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$param['search'].'%'];
- }
- $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(计量单位) 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('工单_基本资料')->where($where)->field($field)->limit(($page-1)*$limit,$limit)->order('Uniqid desc')->select();
- $total = \db('工单_基本资料')->where($where)->count();
- if (empty($list)){
- $this->success('',[]);
- }
- foreach ($list as $key=>$value){
- $list[$key]['订单数量'] = rtrim((float)$value['订单数量']);
- $list[$key]['产品名称'] = $value['产品名称'] != '' ? $value['产品名称']:$value['成品名称'];
- $number = \db('工单_工艺资料')->where('Gy0_gdbh',$value['工单编号'])->count();
- if ($number === 0){
- $list[$key]['status'] = 0;
- }else{
- $list[$key]['status'] = 1;
- }
- unset($list[$key]['成品名称']);
- }
- $this->success('成功',['data'=>$list,'total'=>$total]);
- }
- /**
- * 计划中工单->工艺资料
- * @ApiMethod (GET)
- * @param string $Gd_gdbh 工单编号
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function projectCraft()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $Gd_gdbh = input('Gd_gdbh');
- if (empty($Gd_gdbh)){
- $this->error('参数错误');
- }
- $where = [
- 'Gy0_gdbh' => $Gd_gdbh
- ];
- $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(重点工序) as 重点工序,Gy0_yjno,Gy0_gxh,Gy0_gxmc,Add_gxmc,rtrim(工序备注) as 工序备注,
- rtrim(Gy0_sbbh) as 机组,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,
- rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(UniqId) as UNIQID';
- $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
- if (empty($list)){
- $this->success('',[]);
- }
- foreach ($list as $key=>$value){
- if ((int)$value['Gy0_yjno'] <10){
- $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
- }
- if ((int)$value['Gy0_gxh'] <10){
- $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
- }
- if (rtrim($value['Add_gxmc']) == ''){
- $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
- }else{
- $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
- }
- unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
- }
- $this->success('成功',$list);
- }
- /**
- * 计划中工单->印件资料
- * @ApiMethod (GET)
- * @param string $Gd_gdbh 工单编号
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function projectPrint()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $Gd_gdbh = input('Gd_gdbh');
- if (empty($Gd_gdbh)){
- $this->error('参数错误');
- }
- $where = [
- 'Yj_Gdbh' => $Gd_gdbh,
- ];
- $field = 'rtrim(Yj_Gdbh) as 工单编号,rtrim(yj_Yjno) as 印件号,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_yjmc) as 印件名称,
- rtrim(yj_zzmc) as 纸张名称,rtrim(yj_tlgg) as 投料规格,rtrim(yj_成品数量) as 成品数量,rtrim(yj_实际投料) as 实际投料,
- rtrim(yj_Dw) as 投料单位,rtrim(yj_平张投料) as 平张投料,rtrim(yj_ls) as 联数,rtrim(yj_ks) as 开数,rtrim(Sys_id) as 创建用户,
- rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID';
- $list = \db('工单_印件资料')->where($where)->field($field)->select();
- if (empty($list)){
- $this->success('');
- }
- foreach ($list as $key=>$value){
- $list[$key]['成品数量'] = rtrim((float)$value['成品数量']);
- $list[$key]['实际投料'] = rtrim((float)$value['实际投料']);
- }
- $this->success('成功',$list);
- }
- /**
- * 排程中/制程中工单
- */
- public function Schedule(){
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $where = '';
- if (!empty($param['search'])){
- $where = "
- a.Gd_gdbh LIKE '%{$param['search']}%'
- OR a.`成品名称` LIKE '%{$param['search']}%'
- ";
- }
- if ($param['status'] === '排程中'){
- $list = db('工单_基本资料')->alias('a')
- ->field([
- 'rtrim(a.Gd_gdbh)' => '工单编号',
- 'rtrim(a.Gd_cpdh)' => '产品代号',
- 'rtrim(a.Gd_cpmc)' => '产品名称',
- 'rtrim(a.接单日期)' => '接单日期',
- 'rtrim(a.交货日期)' => '交货日期',
- 'rtrim(a.订单数量)' => '订单数量',
- 'rtrim(a.计量单位)' => '计量单位',
- 'rtrim(a.销售订单号)' => '销售订单号',
- 'rtrim(a.Gd_客户代号)' => '客户编号',
- 'rtrim(a.Gd_客户名称)' => '客户名称',
- 'rtrim(a.客户料号)' => '客户料号',
- 'rtrim(a.Uniqid)' => 'GDUID',
- ])
- ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
- ->where([
- 'a.gd_statu' => '2-生产中',
- 'a.行号' => '1',
- 'b.PD_WG' => '1900-01-01 00:00:00',
- ])
- ->where($where)
- // ->whereNotExists(function ($query) {
- // $query->table('工单_工艺资料')->alias('b2')
- // ->where('b2.Gy0_gdbh = a.Gd_gdbh')
- // ->where('b2.Gy0_sj1 <> "1900-01-01 00:00:00"');
- // })
- ->group('a.Gd_gdbh')
- ->select();
- }else{
- $list = db('工单_基本资料')->alias('a')
- ->field([
- 'rtrim(a.Gd_gdbh)' => '工单编号',
- 'rtrim(a.Gd_cpdh)' => '产品代号',
- 'rtrim(a.Gd_cpmc)' => '产品名称',
- 'rtrim(a.接单日期)' => '接单日期',
- 'rtrim(a.交货日期)' => '交货日期',
- 'rtrim(a.订单数量)' => '订单数量',
- 'rtrim(a.计量单位)' => '计量单位',
- 'rtrim(a.销售订单号)' => '销售订单号',
- 'rtrim(a.Gd_客户代号)' => '客户编号',
- 'rtrim(a.Gd_客户名称)' => '客户名称',
- 'rtrim(a.客户料号)' => '客户料号',
- 'rtrim(a.Uniqid)' => 'GDUID',
- ])
- ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
- ->where([
- 'a.gd_statu' => '2-生产中',
- 'a.行号' => '1',
- 'b.PD_WG' => '1900-01-01 00:00:00',
- 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
- ])
- ->where($where)
- ->group('a.Gd_gdbh')
- ->select();
- }
- if (empty($list)){
- $this->success('未找到工单信息');
- }
- $this->success('成功',$list);
- }
- /**
- * 排程中/制程中工单->工序列表
- * @ApiMethod (GET)
- * @param string $Gd_gdbh 工单编号
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function ScheduleProcess()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $Gd_gdbh = input('Gd_gdbh');
- if (empty($Gd_gdbh)){
- $this->error('参数错误');
- }
- $sql = "SELECT rtrim(a.Gy0_gdbh) as 工单编号,a.Gy0_yjno,a.Gy0_gxh,a.Gy0_gxmc,a.Add_gxmc,rtrim(a.Gy0_sbbh) as 设备编号,rtrim(a.Gy0_小时产能) as 小时产能,
- rtrim(a.工价系数) as 产能系数,rtrim(a.Gy0_生产工时) as 生产工时,rtrim(a.Gy0_辅助工时) as 辅助工时,rtrim(a.Gy0_最早开工时间) as 最早开工时间,
- rtrim(a.Gy0_sj1) as 计划开工时间,rtrim(a.Gy0_sj2) as 计划完工时间,rtrim(a.Gy0_班次安排) as 班次安排,rtrim(a.工序备注) as 排单备注,
- rtrim(a.PD_WG) as 工序完工,rtrim(a.UniqId) as UniqId,COALESCE(b.cl, 0) AS 产量, c.设备名称,rtrim(d.计划投料) as 工序产量
- FROM `工单_工艺资料` AS a
- JOIN `设备_基本资料` AS c ON a.Gy0_sbbh = c.设备编号
- JOIN `工单_基本资料` As d ON a.Gy0_gdbh = d.Gd_Gdbh
- LEFT JOIN (
- SELECT sczl_gdbh, sczl_gxh, SUM(sczl_cl) AS cl
- FROM `设备_产量计酬`
- GROUP BY sczl_gdbh, sczl_gxh
- ) AS b ON a.Gy0_gdbh = b.sczl_gdbh AND (a.Gy0_gxh = b.sczl_gxh OR b.sczl_gxh IS NULL)
- WHERE a.Gy0_gdbh = '{$Gd_gdbh}' AND a.Gy0_sbbh != ''
- GROUP BY a.Gy0_yjno,a.Gy0_gxh";
- $list = Db::query($sql);
- if (empty($list)){
- $this->success('未找到工序');
- }
- foreach ($list as $key=>$value){
- if ((int)$value['Gy0_yjno'] <10){
- $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
- }
- if ((int)$value['Gy0_gxh'] <10){
- $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
- }
- if (rtrim($value['Add_gxmc']) == ''){
- $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
- }else{
- $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
- }
- unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
- $list[$key]['机组'] = $value['设备编号'];
- $list[$key]['剩余产量'] = (int)$list[$key]['工序产量']-(int)$list[$key]['产量'];
- }
- $this->success('成功',$list);
- }
- /**
- * 排单页面左侧车间和机台菜单
- * @ApiMethod (GET)
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function workbench()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (isset($param['sort'])){
- $where['使用部门'] = '智能车间';
- }else{
- $where['使用部门'] = ['in',['印刷车间','印后车间']];
- }
- $data = [];
- $department = \db('设备_基本资料')
- ->distinct(true)
- ->where('使用部门','<>','研发中心')
- ->where('设备编组','<>','')
- ->where($where)
- ->order('设备编组')
- ->column('使用部门');
- if (empty($department)){
- $this->success('为获取到机台数据');
- }
- foreach ($department as $value){
- $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->order('设备编组')->column('设备编组');
- foreach ($benchClass as $v){
- if (rtrim($v) !== ''){
- $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
- foreach ($machine as $kk=>$vv){
- $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
- }
- }
- }
- }
- $this->success('成功',$data);
- }
- /**
- * 工单状态设置
- * @ApiMethod (GET)
- * @param string $workOrder 工单编号
- * @param string $status 工单状态
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function StatusEdit()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $workOrder = input('workOrder');
- $status = input('status');
- if (empty($workOrder) || empty($status)){
- $this->error('参数错误');
- }
- $sql = \db('工单_基本资料')->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('工单_工艺资料')->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 (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $data = Request::instance()->post();
- if (empty($data)){
- $this->error('参数错误');
- }
- $where = [
- 'Gy0_gdbh' => $data['workOrder'],
- 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
- 'Gy0_yjno' => $data['printCode'],
- 'Gy0_gxh' => $data['processCode']
- ];
- $result = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj1) as sj1')->find();
- if ($result['sj1'] != '1900-01-01 00:00:00'){
- $this->error('该工单已经是制程中');
- }
- $lastTime = \db('工单_工艺资料')
- ->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();
- $date = date('Y-m-d H:i:s',time());
- if ($lastTime['sj2'] < $date){
- $newTime = $date;
- }else{
- $newTime = $lastTime['sj2'];
- }
- $row = \db('工单_工艺资料')
- ->where($where)
- ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
- ->find();
- if (empty($row)){
- $this->success('未找到该工单工艺资料');
- }
- $endTime = date('Y-m-d H:i:s',strtotime($newTime) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
- $sql = \db('工单_工艺资料')
- ->where($where)
- ->fetchSql(true)
- ->update(['Gy0_sj1'=>$newTime,'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 (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $data = Request::instance()->post();
- if (empty($data)){
- $this->error('参数错误');
- }
- $where = [
- 'Gy0_gdbh' => $data['workOrder'],
- 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
- 'Gy0_yjno' => $data['printCode'],
- 'Gy0_gxh' => $data['processCode']
- ];
- $machine = $data['machine'];
- $endTime = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2,rtrim(PD_WG) as wg')->find();
- if (empty($endTime)){
- $this->success('未找到该工序');
- }
- $time = $endTime['sj2'];
- if ($endTime['sj2'] == '1900-01-01 00:00:00' || $endTime['wg'] != '1900-01-01 00:00:00'){
- $this->error('该工单不是制程中工单');
- }
- $sql = \db('工单_工艺资料')
- ->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('工单_工艺资料')
- ->where($where)
- ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
- ->find();
- if (empty($row)){
- $this->success('未找到该工序');
- }
- $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'];
- $rechSql = "UPDATE `工单_工艺资料` SET Gy0_sj1 = DATE_ADD(Gy0_sj1, INTERVAL {$number} HOUR),Gy0_sj2 = DATE_ADD(Gy0_sj2, INTERVAL {$number} HOUR) WHERE Gy0_sbbh LIKE '%{$machine}%' AND Gy0_sj1 >= '{$time}' AND Gy0_sj1 < '2099-01-01 00:00:00'";
- $rechres = Db::query($rechSql);
- $res = Db::query($sql);
- 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'],
- ];
- $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 完工时间,rtrim(UniqId) as UniqId';
- $list = \db('工单_工艺资料')->where($where)->field($field)->order('Gy0_yjno,Gy0_gxh')->select();
- if (empty($list)){
- $this->success('未找到该工单工艺资料');
- }
- $yieldSql = "SELECT
- a.Gy0_yjno AS yjno,
- a.Gy0_gxh AS gxh,
- SUM( b.sczl_cl ) AS cl
- FROM
- `工单_工艺资料` AS a
- JOIN `设备_产量计酬` AS b ON a.Gy0_gxh = b.sczl_gxh AND a.Gy0_yjno = b.sczl_yjno
- WHERE
- a.Gy0_gdbh = '{$workOrder}'
- GROUP BY
- a.Gy0_yjno,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['yjno'] === $list[$key]['yjno']) {
- if ($v['gxh'] === $list[$key]['gxh']){
- $list[$key]['计划产量/已完成'] = (int)$value['计划接货数'] . '/' . $v['cl'];
- if ($value['计划接货数'] !== 0 && $value['计划接货数'] !== '' && !empty($value['计划接货数'])) {
- $num = (float)number_format(intval($v['cl']) / intval($value['计划接货数']), 4);
- $list[$key]['完成率'] = $num * 100 . '%';
- } else {
- $list[$key]['完成率'] = '';
- }
- }else{
- $list[$key]['计划产量/已完成'] = $value['计划接货数'].'/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 (POST)
- * @param void
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function ProcessStatusCorrectionEdit()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $i = 0;
- foreach ($param as $key=>$value){
- if ($value['PD_WG'] === null || $value['PD_WG'] === ''){
- $endTime = '1900-01-01 00:00:00';
- }else{
- $endTime = $value['PD_WG'];
- }
- $sql = \db('工单_工艺资料')
- ->where('UniqId',$value['UniqId'])
- ->fetchSql(true)
- ->update(['PD_WG'=>$endTime]);
- $res = Db::query($sql);
- if ($res !== false){
- $i++;
- }
- }
- if ($i !== 0){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 班次选择
- * @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('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
- if (empty($list)){
- $this->success('未找到班次数据');
- }
- 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('参数错误');
- }
- $machine = $param['machine'];
- $list = \db('工单_基本资料')
- ->alias('a')
- ->field([
- 'rtrim(b.Gy0_gdbh)' => '工单编号',
- 'rtrim(b.Gy0_计划接货数)' => '计划接货数',
- 'rtrim(b.Gy0_小时产能)' => '小时产能',
- 'rtrim(b.Gy0_生产工时)' => '生产工时',
- 'rtrim(b.Gy0_辅助工时)' => '辅助工时',
- 'rtrim(b.Gy0_班次安排)' => '班次安排',
- 'rtrim(b.工序备注)' => '排单备注',
- 'rtrim(b.Gy0_最早开工时间)' => '最早开工时间',
- 'rtrim(b.Gy0_sj1)' => '计划开工时间',
- 'rtrim(b.Gy0_sj2)' => '计划完工时间',
- 'rtrim(b.Gy0_yjno)' => 'yjno',
- 'rtrim(b.Gy0_gxh)' => 'gxh',
- 'rtrim(b.Gy0_gxmc)' => 'gxmc',
- 'rtrim(b.Gy0_ls)' => 'ls',
- 'rtrim(b.UniqId)' => 'UniqId',
- 'SUM(c.sczl_cl)' => '已完成'
- ])
- ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
- ->join('设备_产量计酬 c','a.Gd_gdbh = c.sczl_gdbh AND b.Gy0_yjno = c.sczl_yjno AND b.Gy0_gxh = c.sczl_gxh','LEFT')
- ->where([
- 'b.Gy0_sbbh' => $machine,
- 'b.Gy0_sj1' => ['>','1900-01-01 00:00:00'],
- 'b.PD_WG' => '1900-01-01 00:00:00',
- 'a.gd_statu' => '2-生产中'
- ])
- ->where('b.Gy0_sj1','<','2099-01-01 00:00:00')
- ->group('a.Gd_gdbh')
- ->select();
- 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']);
- }
- $this->success('成功',$list);
- }
- /**
- * 车间设备排程编辑
- * @ApiMethod (POST)
- * @param void $param
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function EquipmentSchedulingEdit()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $i = 0;
- foreach ($param as $key=>$value){
- $data = [
- 'Gy0_小时产能' => $value['capacity'],
- 'Gy0_生产工时' => $value['ProductionHours'],
- 'Gy0_辅助工时' => $value['AuxiliaryHours'],
- 'Gy0_班次安排' => $value['shift'],
- '工序备注' => $value['remark'],
- 'Gy0_最早开工时间' => $value['start'] === ''?'1900-01-01 00:00:00':date('Y-m-d H:i:s',strtotime($value['start'])),
- 'Gy0_sj1' => date('Y-m-d H:i:s',strtotime($value['projectTime'])),
- // 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($value['projectTime'])+(ceil($value['ProductionHours'])+ceil($value['AuxiliaryHours']))*3600),
- 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($value['endTime'])),
- ];
- $sql = \db('工单_工艺资料')
- ->where('UniqId',$value['UniqId'])
- ->fetchSql(true)
- ->update($data);
- $res = Db::query($sql);
- if ($res !== false){
- $i++;
- }
- }
- if ($i !== 0){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 机台工单展示
- * @ApiMethod ()
- * @return void
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function MachineWorkOrderList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求失败');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $where = '';
- if (isset($param['search'])){
- $where = "
- b.Gd_gdbh LIKE '%{$param['search']}%'
- OR b.`成品名称` LIKE '%{$param['search']}%'
- ";
- }
- $list = \db('工单_工艺资料')
- ->alias('a')
- ->field([
- 'RTRIM( a.Gy0_yjno )' =>'yjno',
- 'RTRIM( a.Gy0_gxh )' => 'gxh',
- 'RTRIM( a.Gy0_gxmc )' => 'gxmc',
- 'RTRIM( a.Add_gxmc )' => 'Add_gxmc',
- 'RTRIM( c.yj_yjmc )' => '印件名称',
- 'RTRIM( a.`Gy0_计划接货数` )' => '计划接货数',
- 'RTRIM( a.`Gy0_小时产能` )' => '小时产能',
- 'RTRIM( a.`工价系数` )' => '产能系数',
- 'RTRIM( a.`Gy0_生产工时` )' => '生产工时',
- 'RTRIM( a.Gy0_ls )' => 'ls',
- 'RTRIM( a.`Gy0_辅助工时` )' => '辅助工时',
- 'RTRIM( a.`Gy0_最早开工时间` )' => '最早开工时间',
- 'RTRIM( a.Gy0_sj1 )' => '计划开工时间',
- 'RTRIM( a.Gy0_sj2 )' => '计划完工时间',
- 'RTRIM( a.`Gy0_班次安排` )' => '班次安排',
- 'RTRIM( a.`工序备注` )' => '排单备注',
- 'RTRIM( b.Gd_cpmc )' => '产品名称',
- 'RTRIM( b.`成品名称` )' => '成品名称',
- 'RTRIM( b.`订单数量` )' => '订单数量',
- 'RTRIM( b.`计量单位` )' => '计量单位',
- 'RTRIM( b.`交货日期` )' => '交货日期',
- 'RTRIM( b.Gd_cpdh )' => '产品代号',
- 'RTRIM( b.`成品代号` )' => '成品代号',
- 'RTRIM( a.Gy0_sbbh )' => '设备编号',
- 'RTRIM( a.Gy0_SITE )' => '车间名称',
- 'RTRIM( a.UniqId )' => 'GYUID',
- 'RTRIM( b.Uniqid )' => 'UNIQID',
- 'SUM( d.sczl_cl )' => '已完成产量',
- 'RTRIM( b.Gd_gdbh )' => '工单编号',
- 'RTRIM( b.`销售订单号` )' => '销售订单号',
- ])
- ->join('工单_印件资料 c','c.Yj_Gdbh = a.Gy0_gdbh AND c.yj_Yjno = a.Gy0_yjno')
- ->join('工单_基本资料 b','b.Gd_gdbh = a.Gy0_gdbh')
- ->join('设备_产量计酬 d','a.Gy0_gdbh = d.sczl_gdbh AND a.Gy0_yjno = d.sczl_yjno AND a.Gy0_gxh = d.sczl_gxh AND a.Gy0_sbbh = d.sczl_jtbh','LEFT')
- ->where([
- 'b.gd_statu' => '2-生产中',
- 'a.Gy0_sbbh' => ['LIKE','%'.$param['machine'].'%'],
- 'a.PD_WG' => '1900-01-01 00:00:00',
- ])
- ->where($where)
- ->group('a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh')
- ->order('Gy0_sj1')
- ->select();
- if (empty($list)){
- $this->success('',[]);
- }
- $data['制程'] = $data['排程'] = [];
- foreach ($list as $key=>$value){
- $list[$key]['设备编号'] = $param['machine'];
- if ((int)$value['yjno'] <10){
- $value['yjno'] = '0'.rtrim($value['yjno']);
- }
- if ((int)$value['gxh'] <10){
- $value['gxh'] = '0'.rtrim($value['gxh']);
- }
- if (rtrim($value['Add_gxmc']) == ''){
- $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']);
- }else{
- $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
- }
- unset($list[$key]['Add_gxmc']);
- if ($value['产品名称'] == ''){
- $list[$key]['产品名称'] = $value['成品名称'];
- }
- if ($value['产品代号'] == ''){
- $list[$key]['产品代号'] = $value['成品代号'];
- }
- unset($list[$key]['成品代号'],$list[$key]['成品名称']);
- if ($list[$key]['计划开工时间'] !== '1900-01-01 00:00:00'){
- array_push($data['制程'],$list[$key]);
- }else{
- array_push($data['排程'],$list[$key]);
- }
- }
- $this->success('成功',$data);
- }
- /**
- * 机组调整
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function MachineTeamEdit()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param) || isset($param['UniqId']) === false){
- $this->error('参数错误');
- }
- $sql = \db('工单_工艺资料')
- ->where('UniqId',$param['UniqId'])
- ->fetchSql(true)
- ->update(['Gy0_sbbh'=>$param['machine']]);
- $res = \db()->query($sql);
- if ($res !== false){
- $this->success('修改成功');
- }else{
- $this->error('修改失败');
- }
- }
- /**
- * 子订单领料派单
- * @return void
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function processAdd()
- {
- if (Request::instance()->post() === false){
- $this->error('参数错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $data['班组编号'] = $param['班组'];
- $data['订单编号'] = $param['订单编号'];
- $data['子订单编号'] = $param['子订单编号'];
- $data['sys_id'] = $param['Sys_id'];
- $data['sys_rq'] = date('Y-m-d H:i:s',time());
- $sql = \db('工单_排程班次')->fetchSql(true)->insert($data);
- $res = \db()->query($sql);
- if ($res !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 月度车间报工汇总-菜单显示
- */
- public function MachineList() {
- // 检查请求是否为 GET
- if (!$this->request->isGet()) {
- $this->error('请求错误');
- }
- // 定义要查询的生产工序及排序顺序
- $processList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装'];
- // 查询所有数据
- $results = \db('设备_产量计酬')
- ->alias('a')
- ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
- ->field([
- 'DATE_FORMAT(a.sczl_rq, "%Y-%m-%d")' => '时间', // 转化为 "YYYY-MM-DD" 格式
- 'DATE_FORMAT(a.sczl_rq, "%Y-%m")' => '年月', // 转化为 "YYYY-MM" 格式
- 'RTRIM(a.sczl_jtbh)' => '机台编号',
- 'b.设备编号',
- 'b.设备编组',
- 'b.生产工序'
- ])
- ->whereNull('a.mod_rq') // 筛选无修改日期的数据
- ->whereIn('b.生产工序', $processList) // 筛选指定的生产工序
- ->order('a.sczl_rq ASC') // 按时间升序排序
- ->select();
- // 初始化按年月分组的结果
- $formattedData = [];
- // 遍历查询结果并分组
- foreach ($results as $row) {
- $yearMonth = $row['年月']; // 获取年月 "YYYY-MM"
- $monthDay = substr($row['时间'], 5, 5); // 获取月份和日期 "MM-DD"
- $process = $row['生产工序'];
- $machineKey = $row['设备编号'] . '--' . $row['设备编组'];
- // 初始化年份和工序结构
- if (!isset($formattedData[$yearMonth])) {
- $formattedData[$yearMonth] = array_fill_keys($processList, []); // 初始化月份,所有工序为空数组
- }
- if (!isset($formattedData[$yearMonth][$process][$machineKey])) {
- $formattedData[$yearMonth][$process][$machineKey] = [];
- }
- // 添加日期,避免重复
- if (!in_array($monthDay, $formattedData[$yearMonth][$process][$machineKey])) {
- $formattedData[$yearMonth][$process][$machineKey][] = $monthDay;
- }
- }
- // 对年份和月份进行排序(按年月降序排序)
- krsort($formattedData);
- // 按生产工序排序
- foreach ($formattedData as $yearMonth => &$processData) {
- // 确保每个月的工序顺序符合 $processList(即使为空也保留顺序)
- $sortedProcessData = array_fill_keys($processList, []);
- // 合并原有数据
- foreach ($processData as $process => $machines) {
- $sortedProcessData[$process] = $machines;
- }
- // 更新排序后的数据
- $processData = $sortedProcessData;
- // 对每组内的设备日期倒序排列
- foreach ($processData as $process => &$machines) {
- foreach ($machines as $machineKey => &$dates) {
- rsort($dates); // 每台设备的日期倒序排序
- }
- }
- }
- // 返回成功结果
- $this->success('成功', $formattedData);
- }
- /**
- * 月度车间报工汇总-列表数据
- */
- public function MachineDetail()
- {
- if ($this->request->isGet() === false) {$this->error('请求错误');}
- $param = $this->request->param();
- if (empty($param)) {$this->error('参数错误');}
- $where = [];
- // 获取当前年份
- $currentYear = date('Y');
- // 处理日期参数(可选)
- if (!empty($param['date'])) {
- // 检查 `date` 的格式是否为 "YYYY-MM"、"MM-DD" 或仅为月份 "MM"
- if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
- // 如果格式为 "YYYY-MM",查询当月数据
- $where['a.sys_rq'] = ['like', "{$param['date']}%"];
- } elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
- // 如果格式为 "MM-DD",查询指定的月份和日期
- $monthDay = $param['date'];
- $where['a.sys_rq'] = ['like', "%-$monthDay%"];
- } elseif (preg_match('/^\d{2}$/', $param['date'])) {
- // 如果格式为 "MM"(仅月份),自动补全为 "YYYY-MM"
- $where['a.sys_rq'] = ['like', "{$currentYear}-{$param['date']}%"];
- }
- }
- // 判断是否传入订单编号参数(可选)
- if (!empty($param['order'])) {
- $where['b.订单编号|b.款号'] = ['like', '%' . $param['order'] . '%'];
- }
- // 处理机台号参数(可选)
- if (!empty($param['machine'])) {
- $where['a.sczl_jtbh'] = $param['machine'];
- }
- // 查询数据
- $list = \db('设备_产量计酬')->alias('a')
- ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
- ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
- ->field('
- b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
- a.数量, MIN(a.sys_rq) as 上报时间, a.UniqId,
- j.客户编号, j.生产款号, j.款式
- ')
- ->where($where)
- ->where('a.mod_rq', null)
- ->order('a.sys_rq desc, a.UniqId desc')
- ->group('a.UniqId')
- ->select();
- // 提取所有的尺码,并去重
- $sizeList = array_values(array_unique(array_column($list, '尺码')));
- // **自定义排序规则**
- $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL']; // 定义字母尺码的顺序
- usort($sizeList, function ($a, $b) use ($sizeOrder) {
- // 如果是数字,直接比较大小
- if (is_numeric($a) && is_numeric($b)) {
- return $a - $b;
- }
- // 如果是字母,按 $sizeOrder 的索引排序
- if (in_array($a, $sizeOrder) && in_array($b, $sizeOrder)) {
- return array_search($a, $sizeOrder) - array_search($b, $sizeOrder);
- }
- // 如果一个是数字,一个是字母,数字排在前面
- if (is_numeric($a)) return -1;
- if (is_numeric($b)) return 1;
- // 如果都不符合,按字典顺序(备用)
- return strcmp($a, $b);
- });
- // 动态将尺码的数量添加到每个订单中,并替换已完成字段
- foreach ($list as &$item) {
- $size = $item['尺码'];
- $item[$size] = $item['数量'];
- // unset($item['数量']); // 如果不需要保留原字段,可以取消注释
- }
- // 返回结果
- $this->success('请求成功', [
- 'table' => $list,
- 'length' => count($list),
- 'headers' => $sizeList // 返回所有的尺码作为表头
- ]);
- }
- /**
- * 工单审核
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function Approval()
- {
- if ($this->request->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $data['审核'] = $param['sys_id'];
- $data['审核日期'] = date('Y-m-d H:i:s');
- $sql = \db('工单_基本资料')
- ->where('Uniqid',$param['Uniqid'])
- ->fetchSql(true)
- ->update($data);
- $res = \db()->query($sql);
- if ($res === false){
- $this->error('审核失败');
- }else{
- $this->success('审核成功');
- }
- }
- /**
- * 订单未审核列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function UnapprovalList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (isset($param)){
- $where['订单编号|生产款号'] = ['like','%'.$param['search'].'%'];
- }
- // $where['审核'] = null;
- // $where['审核日期'] = null;
- $where['Mod_rq'] = null;
- $list = \db('工单_基本资料')
- ->where($where)
- ->orderRaw("FIELD(gd_statu, '1-计划中', '2-生产中')")
- ->order('订单编号 desc')
- ->select();
- // 提取所有订单编号
- $orderIds = array_column($list, '订单编号');
- // 查询相关附件中是否存在这些订单编号
- $relatedOrders = \db('工单_相关附件')
- ->whereIn('关联编号', $orderIds)
- ->whereIn('附件备注', '技术附件')
- ->column('关联编号');
- // // 遍历数据,为每个订单设置 status
- // foreach ($list as &$value) {
- // if (in_array($value['订单编号'], $relatedOrders)) {
- // $value['status'] = '';
- // } else {
- // $value['status'] = '*';
- // }
- // }
- // $data['total'] = count($list);
- // $data['table'] = $list;
- // 遍历数据,为每个订单设置 status,并替换字段名
- foreach ($list as &$value) {
- // 设置订单状态
- if (in_array($value['订单编号'], $relatedOrders)) {
- $value['status'] = '';
- } else {
- $value['status'] = '*';
- }
- // 将「工单入仓数量」字段替换为「工单完工数量」
- if (isset($value['工单入仓数量'])) {
- $value['工单完工数量'] = $value['工单入仓数量'];
- unset($value['工单入仓数量']);
- }
- }
- $data['total'] = count($list);
- $data['table'] = $list;
- $this->success('成功',$data);
- }
- /**
- * 月度客户订单汇总
- */
- public function OrderYieldList(){
- // 获取前端传来的参数
- $param = $this->request->param();
- // 初始化查询条件
- $where = [];
- // 处理搜索条件
- if (isset($param['search']) && !empty($param['search'])) {
- $where['j.订单编号|j.生产款号'] = ['like', '%' . $param['search'] . '%'];
- }
- if (isset($param['client']) && !empty($param['client'])) {
- $where['j.客户编号'] = $param['client'];
- }
- if (isset($param['date']) && !empty($param['date'])) {
- $year = substr($param['date'], 0, 4);
- $month = substr($param['date'], 4, 2);
- $where['j.Sys_rq'] = ['like', "$year-$month%"];
- }
- // 只查询生产中的工单
- $where['j.gd_statu'] = '2-生产中';
- $where['j.Mod_rq'] = null;
- // 执行查询
- $orderList = \db('工单_基本资料')->alias('j')
- ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号')
- ->field('j.Sys_rq, y.订单编号, j.落货日期, j.生产款号, j.款式, SUM(y.sctotal) as 裁剪总数, SUM(y.zdtotal) as 制单总数')
- ->group('y.订单编号')
- ->where($where)
- ->select();
- $orderIds = array_column($orderList, '订单编号');
- // 通过订单编号关联设备_产量计酬表,获取工序名称和数量,并进行分组和汇总
- $processList = \db('设备_产量计酬')
- ->alias('a')
- ->join('工单_基本资料 j', 'a.订单编号 = j.订单编号')
- ->whereIn('a.订单编号', $orderIds) // 只查询符合条件的订单编号
- ->field('a.订单编号, a.工序名称, SUM(a.数量) as 总数量')
- ->group('a.订单编号, a.工序名称') // 按订单编号和工序名称分组
- ->select();
- //echo "<pre>";
- //print_r($processList);
- //echo "<pre>";
- // 合并两个结果
- $data = [];
- foreach ($orderList as $key => $order) {
- // 去掉落货日期的时间部分,只保留日期
- $orderDate = substr($order['落货日期'], 0, 10); // 提取前10位
- //放入结果
- $data[$key] = [
- '订单编号' => $order['订单编号'],
- '落货日期' => $order['落货日期'],
- '生产款号' => $order['生产款号'],
- '款式' => $order['款式'],
- '裁剪总数' => $order['裁剪总数'],
- '制单总数' => $order['制单总数'],
- ];
- // 找到该订单编号对应的工序名称和数量
- foreach ($processList as $process) {
- if ($process['订单编号'] === $order['订单编号']) {
- // 将工序名称和数量加入到结果中
- $data[$key][$process['工序名称']] = $process['总数量'];
- }
- }
- }
- // 返回最终结果
- $this->success('成功', $data);
- }
- /**
- * 订单状态及样衣批核-左侧菜单
- */
- public function dateList()
- {
- }
- /**
- * 车缝派单菜单
- * @return void
- */
- public function CfmachineList()
- {
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- // 查询所有生产工序为"车缝"的设备编号和设备编组
- $machineList = \db('设备_基本资料')
- ->where('生产工序', '车缝')
- ->field('设备编号, 设备编组')
- ->order('设备编号') // 按设备编号排序
- ->select();
- $result = [];
- foreach ($machineList as $machine) {
- $machineCode = $machine['设备编号'];
- $machineGroup = $machine['设备编组'];
- // 查询该设备编号在 设备_产量计酬 表中的订单编号及日期
- $orders = \db('设备_产量计酬')
- ->where('sczl_jtbh', $machineCode)
- ->where('mod_rq', null)
- ->order('sys_rq asc') // 按生产日期升序排序
- ->select();
- // 根据月份分组统计订单数量
- $monthlyOrders = [];
- foreach ($orders as $order) {
- $yearMonth = date('Ym', strtotime($order['sys_rq']));
- if (!isset($monthlyOrders[$yearMonth])) {
- $monthlyOrders[$yearMonth] = [];
- }
- $monthlyOrders[$yearMonth][] = $order['订单编号'];
- }
- // 构建返回数据,格式为:设备编号【设备编组 生产中:工单数量】
- foreach ($monthlyOrders as $yearMonth => $orderList) {
- $workOrderCount = count(array_unique($orderList));
- if (!isset($result[$yearMonth])) {
- $result[$yearMonth] = [];
- }
- // 使用集合来去重设备编号
- $deviceKey = $machineCode . '【' . $machineGroup . ' 生产中:' . $workOrderCount . '】';
- if (!in_array($deviceKey, $result[$yearMonth])) {
- $result[$yearMonth][] = $deviceKey;
- }
- }
- }
- // 按月份排序,确保最新的月份在前面
- krsort($result);
- $this->success('成功', $result);
- }
- /**
- * 车缝派单列表
- */
- public function CfdataList()
- {
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param['machine']) || empty($param['date'])) {
- $this->error('参数错误');
- }
- // 将传入的 YYYYMM 格式日期转换为 YYYY-MM-01
- $year = substr($param['date'], 0, 4);
- $month = substr($param['date'], 4, 2);
- $startDate = "$year-$month-01 00:00:00";
- $endDate = date("Y-m-t 23:59:59", strtotime($startDate)); // 获取该月的最后一天
- // 查询设备产量计酬与工单基本资料的关联数据
- $list = \db('设备_产量计酬')->alias('c')
- ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
- ->where('c.sczl_jtbh', $param['machine'])
- ->where('c.mod_rq', null)
- ->where('c.sczl_rq', '>=', $startDate)
- ->where('c.sczl_rq', '<=', $endDate)
- ->field('
- c.订单编号, c.款号 as 生产款号, j.款式, j.客户编号, j.订单数量,
- LEFT(j.落货日期, 10) as 落货日期,j.工单入仓数量 as 工单完工数量,j.订单数量,
- c.sczl_rq as 创建时间, j.gd_statu as 工单状态
- ')
- ->group('c.订单编号')
- ->select();
- // 返回数组结果
- $this->success('请求成功', ['table' => $list, 'length' => count($list)]);
- }
- //
- // /**车缝派单菜单
- // * @return void
- // */
- // public function CfmachineList()
- // {
- // if ($this->request->isGet() === false) {
- // $this->error('请求错误');
- // }
- //
- // // 查询所有生产工序为"车缝"的设备编号和设备编组
- // $machineList = \db('设备_基本资料')
- // ->where('生产工序', '车缝')
- // ->field('设备编号, 设备编组')
- // ->order('设备编号') // 按设备编号排序
- // ->select();
- //
- // $result = [];
- // $addedMachineCodes = []; // 用于跟踪已经添加的设备编号
- //
- // foreach ($machineList as $machine) {
- // $machineCode = $machine['设备编号'];
- // $machineGroup = $machine['设备编组'];
- //
- // // 检查是否已经添加过该设备编号
- // if (in_array($machineCode, $addedMachineCodes)) {
- // continue; // 跳过已添加的设备
- // }
- //
- // // 查询该设备编号在 设备_产量计酬 表中的订单编号
- // $orders = \db('设备_产量计酬')
- // ->where('sczl_jtbh', $machineCode)
- // ->order('sys_rq desc')
- // ->where('mod_rq', null)
- // ->column('订单编号');
- //
- // // 去重统计订单编号数量
- // $workOrderCount = count(array_unique($orders));
- //
- // // 构建返回数据,格式为:设备编号【设备编组 生产中:工单数量】
- // $result[] = $machineCode . '【' . $machineGroup . ' 生产中:' . $workOrderCount . '】';
- //
- // // 将设备编号添加到跟踪数组中
- // $addedMachineCodes[] = $machineCode;
- // }
- //
- // $yearMonth = date('Ym');
- // $finalResult = [
- // $yearMonth => $result
- // ];
- //
- // $this->success('成功', $finalResult);
- // }
- //
- //
- // /**
- // * 车缝派单列表
- // */
- // public function CfdataList()
- // {
- // if ($this->request->isGet() === false) {
- // $this->error('请求错误');
- // }
- //
- // $param = $this->request->param();
- // if (empty($param)) {
- // $this->error('参数错误');
- // }
- //
- // // 查询设备产量计酬与工单基本资料的关联数据
- // $list = \db('设备_产量计酬')->alias('c')
- // ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
- // ->where('c.sczl_jtbh', $param['machine'])
- // ->where('c.mod_rq', null)
- // ->field('
- // c.订单编号, c.款号, j.款式, j.客户编号, j.订单数量,
- // LEFT(j.落货日期, 10) as 落货日期,
- // j.Sys_rq as 创建时间, j.gd_statu as 工单状态
- // ')
- // ->group('c.订单编号')
- // ->select();
- //
- //
- // // 返回数组结果
- // $this->success('请求成功', ['table' => $list, 'length' => count($list)]);
- // }
- //车缝派单删除
- public function CfdataDel()
- {
- if ($this->request->isGet() === false)
- {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $sql = \db('工单_排程班次')
- ->where('UniqId',$param['UniqId'])
- ->fetchSql(true)
- ->update(['mod_rq'=>date('Y-m-d H:i:s',time())]);
- $res = \db()->query($sql);
- if ($res !== false){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- //车缝派单数据
- public function CfdataAllList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $list = \db('工单_排程班次')
- ->where('mod_rq',null)
- ->order('sys_rq desc')
- ->field('订单编号,子订单编号,班组编号,sys_rq as 创建时间,sys_id as 创建人员,UniqId')
- ->group('子订单编号')
- ->select();
- $this->success('成功',$list);
- }
- }
|