| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- /**
- * 翌星工单资料管理
- */
- class YxworkOrder extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 工单资料菜单列表
- *
- * @ApiMethod (GET)
- * @return false|string
- * @throws \think\Exception
- */
- public function DataList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $where['工单分类'] = ['in',[1,3]];
- $where['行号'] = '1';
- //获取总计划中数量和总生产中数量
- $productingAll = \db('工单_基本资料')
- ->where($where)
- ->where('成品代号','<>','')
- ->where('gd_statu','2-生产中')
- ->count();
- $progressAll = \db('工单_基本资料')
- ->where($where)
- ->where('成品代号','<>','')
- ->where('gd_statu','3-计划中')
- ->count();
- $data = [
- 'productingAll' => $productingAll,
- 'progressAll' => $progressAll,
- ];
- $list = \db('产品_基本资料')
- ->where('客户编号','<>','')
- ->field('客户编号,客户名称')
- ->group('客户编号,客户名称')
- ->order('客户编号')
- ->select();
- if (empty($list)){
- $this->success('',[]);
- }
- $data['翌星工单']=[];
- foreach ($list as $key=>$value){
- $value['客户编号'] = rtrim($value['客户编号']);
- //这条sql查出来的数据可能不对,试一下以下sql
- $productIng = \db('工单_基本资料')
- ->where($where)
- ->where('Gd_cpdh|成品代号','LIKE',rtrim($value['客户编号']).'%')
- ->where('gd_statu','2-生产中')
- ->count();
- $proGress = \db('工单_基本资料')
- ->where($where)
- ->where('Gd_cpdh|成品代号','LIKE',rtrim($value['客户编号']).'%')
- ->where('gd_statu','3-计划中')
- ->count();
- $string = '';
- if ($productIng != 0){
- $string = $string."生产中:".$productIng;
- }
- if ($proGress != 0){
- $string = $string."计划中:".$proGress;
- }
- if ($string !== ''){
- $name = $value['客户编号'].'【'.$string.'】'.rtrim($value['客户名称']);
- if (strpos($value['客户编号'],'J') !== false || strpos($value['客户编号'],'Y') !== false){
- array_push($data['翌星工单'],$name);
- }
- }
- }
- $this->success('成功',$data);
- }
- /**
- * 工单基本资料列表
- * @ApiMethod (GET)
- * @param string $limit 查询长度
- * @param string $Gd_khdh 客户代号
- * @param string $startTime 接单日期开始时间
- * @param string $endTime 接单日期结束时间
- * @return \think\response\Json
- * @throws \think\exception\DbException
- */
- public function WorkList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $search = input('search');
- $clientNumber = input('Gd_khdh');
- $startTime = input('start');
- $endTime = input('end');
- $page = input('page');
- $limit = input('limit');
- $param = $this->request->param();
- if (isset($param['sort'])){
- $sort = 2;
- }else{
- $sort = 1;
- }
- $where = [];
- if (!empty($clientNumber)){
- if (substr($clientNumber,0,1) !== 'Y' && substr($clientNumber,0,1) !== 'J')
- {
- $clientNumber = substr($clientNumber,0,4);
- }
- if ($clientNumber === 'Y1401'){
- $where['Gd_cpdh'] = ['like',$clientNumber.'%'];
- }else{
- $where['成品代号'] = ['like',$clientNumber.'%'];
- }
- }
- if (!empty($workOrder)){
- $where['Gd_gdbh'] = $workOrder;
- }
- if (!empty($productCode)){
- $where['Gd_cpdh'] = $productCode;
- }
- if (!empty($search)){
- $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$search.'%'];
- }
- if (!empty($startTime) && !empty($endTime)){
- $where['接单日期'] = ['between',[$startTime,$endTime]];
- }
- $total = \db('工单_基本资料')->where($where)->distinct(true)->field('Gd_gdbh')->count();
- $list = \db('工单_基本资料')
- ->where($where)
- ->order('Gd_statu desc')
- ->limit(($page-1)*$limit,$limit)
- ->group('Gd_gdbh')
- ->select();
- //工单基本资料数据整理
- $data = [];
- foreach ($list as $key=>$value){
- $data[$key] = [
- '工单编号' => rtrim($value['Gd_gdbh']),
- '生产分类' => rtrim($value['Gd_生产分类']),
- '销售订单号' => rtrim($value['销售订单号']),
- '产品代号' => rtrim($value['成品代号']),
- '产品名称' => rtrim($value['成品名称']),
- '订单数量' => floatval($value['订单数量']),
- '单位' => rtrim($value['计量单位']),
- '折合大箱' => rtrim((int)$value['投料大箱']),
- '投料率' => rtrim($value['投料率']),
- '平均合格率' => '',
- '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
- '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
- '工单类型' => rtrim($value['Gd_lx']),
- '工单状态' => rtrim($value['gd_statu']),
- '当前生产工序' => '',
- '产量提交时间' => '',
- '建档用户' => rtrim($value['Sys_id']),
- '建档时间' => rtrim($value['Sys_rq']),
- '更新时间' => rtrim($value['Mod_rq']),
- 'Uniqid' => rtrim($value['Uniqid'])
- ];
- $number = \db('工单_工艺资料')->where('Gy0_gdbh',$data[$key]['工单编号'])->count();
- if ($number === 0){
- $data[$key]['status'] = '*';
- }else{
- $data[$key]['status'] = '';
- }
- }
- $this->success('成功',['data'=>$data,'total'=>$total]);
- }
- /**
- * 工单详情
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function workOrderListDetail()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $Gd_gdbh = input('Gd_gdbh');
- $param = $this->request->param();
- if (empty($Gd_gdbh)){
- $this->error('参数错误');
- }
- if (isset($param['sort'])){
- $where['yj_Yjno'] = ['>=','10'];
- }else{
- $where['yj_Yjno'] = ['<','10'];
- }
- $data = [];
- //印件资料
- $printList = \db('工单_印件资料')
- ->where('Yj_Gdbh',$Gd_gdbh)
- ->where($where)
- ->select();
- if (!empty($printList)){
- foreach ($printList as $key=>$value){
- $data['printList'][$key] = [
- '印件号' => rtrim($value['yj_Yjno']),
- '印件代号' => rtrim($value['yj_Yjdh']),
- '印件名称' => rtrim($value['yj_yjmc']),
- '纸张代号' => rtrim($value['yj_zzdh']),
- '纸张名称' => rtrim($value['yj_zzmc']),
- '投料规格' => rtrim($value['yj_tlgg']),
- '平张投料' => rtrim($value['yj_平张投料']),
- '开料规格' => rtrim($value['yj_klgg']),
- '开数*联数' => rtrim($value['yj_ks']).'*'.rtrim($value['yj_ls']),
- '建档用户' => rtrim($value['Sys_id']),
- '建档时间' => rtrim($value['Sys_rq']),
- '更新时间' => rtrim($value['Mod_rq']),
- 'zzdh1' => rtrim($value['yj_zzdh1']),
- 'zzdh2' => rtrim($value['yj_zzdh2']),
- 'zzdh3' => rtrim($value['yj_zzdh3']),
- 'zzdh4' => rtrim($value['yj_zzdh4']),
- 'zzmc1' => rtrim($value['yj_zzmc1']),
- 'zzmc2' => rtrim($value['yj_zzmc2']),
- 'zzmc3' => rtrim($value['yj_zzmc3']),
- 'zzmc4' => rtrim($value['yj_zzmc4']),
- '订单数量' => rtrim($value['yj_成品数量']),
- '万小张' => rtrim($value['yj_实际投料']),
- '开数' => rtrim($value['yj_ks']),
- '联数' => rtrim($value['yj_ls']),
- '核算规格' => rtrim($value['Yj_核算规格']),
- '备注' => rtrim($value['yj_desc']),
- 'Uniqid' => rtrim($value['Uniqid'])
- ];
- }
- }else{
- $data['printList'] = [];
- }
- //工艺资料
- if (isset($param['sort'])){
- $Prowhere['Gy0_yjno'] = ['>=','10'];
- }else{
- $Prowhere['Gy0_yjno'] = ['<','10'];
- }
- $processList = \db('工单_工艺资料')
- ->where('Gy0_gdbh',$Gd_gdbh)
- ->where($Prowhere)
- ->order('Gy0_yjno,Gy0_gxh')
- ->select();
- if (!empty($processList)){
- foreach ($processList as $key=>$value){
- if ($value['Gy0_yjno']<10){
- $value['Gy0_yjno'] = '0'.$value['Gy0_yjno'];
- }
- if ($value['Gy0_gxh']<10){
- $value['Gy0_gxh'] = '0'.$value['Gy0_gxh'];
- }
- if (rtrim($value['Gy0_shdh']) == '' || $value['Gy0_计划接货数'] == 0){
- $number = 0;
- }else{
- $number = round(((int)$value['Gy0_计划损耗']/(int)($value['Gy0_计划接货数']))*100,2).'%';
- }
- if ($value['PD_WG'] !== '1900-01-01 00:00:00'){
- $status = '已完工';
- }else{
- $status = '未完工';
- }
- $data['processList'][$key] = [
- '重点工序' => rtrim($value['重点工序']),
- '印件-工序' => rtrim($value['Gy0_yjno']).'-'.rtrim($value['Gy0_gxh']),
- '备选工序' => rtrim($value['备选工序']),
- '工序名称' => rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】',
- '印件号' => rtrim($value['Gy0_yjno']),
- '工序号' => rtrim($value['Gy0_gxh']),
- '工艺名称' => rtrim($value['Gy0_gxmc']),
- 'gxmc' => rtrim($value['Add_gxmc']),
- '计划产量' => $value['Gy0_计划接货数'],
- '基础损耗' => rtrim($value['Gy0_Rate0']),
- '损耗率' => rtrim($value['Gy0_Rate1']),
- '机台编号' => rtrim($value['Gy0_sbbh']),
- '报废定额' => rtrim($value['Gy0_计划损耗']),
- '计损色数' => rtrim($value['Gy0_ms']),
- '允损比例' => $number,
- '难度系数' => isset($value['工价系数'])?rtrim($value['工价系数']):'',
- '损耗系数' => isset($value['损耗系数'])?rtrim($value['损耗系数']):'',
- '人工检_次品板' => (int)$value['人工检_次品板']=0?'':$value['人工检_次品板'],
- '人工检_废检' => (int)$value['人工检_废检']=0?'':$value['人工检_废检'],
- '机检_正品板' => (int)$value['机检_正品板']=0?'':$value['机检_正品板'],
- '机检_次品板' => (int)$value['机检_次品板']=0?'':$value['机检_次品板'],
- '机检_废检' => (int)$value['机检_废检']=0?'':$value['机检_废检'],
- '开数*联数' => rtrim($value['Gy0_ks']).'*'.rtrim($value['Gy0_ls']),
- '备注' => isset($value['工序备注'])?rtrim($value['工序备注']):'',
- '印刷方式' => isset($value['印刷方式'])?rtrim($value['印刷方式']):'',
- '版距' => isset($value['版距'])?rtrim($value['版距']):'',
- '建档用户' => rtrim($value['Sys_id']),
- '建档日期' => isset($value['Sys_rq'])?rtrim($value['Sys_rq']):'',
- '更新时间' => isset($value['Mod_rq'])?rtrim($value['Mod_rq']):'',
- '车间名称' => rtrim($value['Gy0_SITE']),
- '质量要求' => rtrim($value['质量要求']),
- '质量隐患' => rtrim($value['质量隐患']),
- '开数' => rtrim($value['Gy0_ks']),
- '联数' => rtrim($value['Gy0_ls']),
- 'UniqId' => rtrim($value['UniqId']),
- 'shdh' => rtrim($value['Gy0_shdh']),
- '辅助工时' => rtrim($value['Gy0_辅助工时']),
- '小时产能' => rtrim($value['Gy0_小时产能']),
- 'status' => $status
- ];
- }
- }else{
- $data['processList'] = [];
- }
- //BOM资料
- $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
- BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
- $bomList = \db('工单_bom资料')
- ->where('BOM_工单编号',$Gd_gdbh)
- ->field($field)
- ->select();
- if (!empty($bomList)){
- foreach ($bomList as $key=>$value){
- $bomList[$key]['消耗定量'] = rtrim($value['BOM_投入数']).rtrim($value['BOM_投料单位']).'/'.rtrim($value['BOM_产出数']).rtrim($value['BOM_产出单位']);
- unset($bomList[$key]['BOM_投料单位'],$bomList[$key]['BOM_投入数'],$bomList[$key]['BOM_产出数'],$bomList[$key]['BOM_产出单位']);
- $bomList[$key]['计划用量'] = rtrim((float)$value['计划用量']);
- }
- $data['BOM'] = $bomList;
- }else{
- $data['BOM'] = [];
- }
- //工单附件资料
- $jsRes = db('工单_相关附件')
- ->where('关联编号','like','%'.$Gd_gdbh.'%')
- ->select();
- if (!empty($jsRes)){
- foreach ($jsRes as $key=>&$value){
- if(mb_detect_encoding($value['附件内容'])!='ASCII'){
- $value['附件内容'] = '';
- }
- }
- $data['jsData'] = $jsRes;
- }else{
- $data['jsData'] = [];
- }
- $this->success('成功',$data);
- }
- /**
- * 获取产品附件列表
- */
- public function getAnnexTable(){
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (isset($req['cpdh']) && !empty($req['cpdh'])){
- $where['关联产品'] = ['LIKE','%'.$req['cpdh'].'%'];
- }else{
- $this->error('参数错误');
- }
- $rows = db('产品_技术附件')
- ->where($where)
- ->select();
- foreach ($rows as $key=>&$value){
- if(mb_detect_encoding($value['附件内容'])!='ASCII'){
- $value['附件内容'] = '';
- }
- }
- $this->success('成功',$rows);
- }
- /**
- * 获取产品附件列表
- */
- public function getGdAnnexTable(){
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (isset($req['gdbh']) && !empty($req['gdbh'])){
- $where['关联编号'] = ['LIKE','%'.$req['gdbh'].'%'];
- }else{
- $this->error('参数错误');
- }
- $rows = db('工单_相关附件')
- ->where($where)
- ->select();
- foreach ($rows as $key=>&$value){
- if(mb_detect_encoding($value['附件内容'])!='ASCII'){
- $value['附件内容'] = '';
- }
- }
- $this->success('成功',$rows);
- }
- }
|