| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\library\Upload;
- use Monolog\Handler\IFTTTHandler;
- use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
- use think\Config;
- use think\Db;
- use think\Request;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- /**
- * 工单资料管理
- */
- class WorkOrder extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- public function _initialize()
- {
- if (isset($_SERVER['HTTP_ORIGIN'])) {
- header('Access-Control-Expose-Headers: __token__');//跨域让客户端获取到
- }
- //跨域检测
- check_cors_request();
- if (!isset($_COOKIE['PHPSESSID'])) {
- Config::set('session.id', $this->request->server("HTTP_SID"));
- }
- parent::_initialize();
- }
- /**
- * 工单资料菜单列表
- *
- * @ApiMethod (GET)
- * @return false|string
- * @throws \think\Exception
- */
- public function DataList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $data = \db('erp_客户供应商')
- ->column('rtrim(编号) as 编号');
- $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 WorkOrderList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $search = input('search');
- $page = input('page');
- $limit = input('limit');
- $param = $this->request->param();
- $where = [];
- if (!empty($search)){
- $where['订单编号|生产款号|客户编号|款式|审核|Sys_id'] = ['like','%'.$search.'%'];
- }
- $total = \db('工单_基本资料')->where($where)->distinct(true)->count();
- $list = \db('工单_基本资料')
- ->where($where)
- ->order('订单编号 desc,Gd_statu desc,Sys_rq desc')
- ->limit(($page-1)*$limit,$limit)
- ->select();
- foreach ($list as $key=>$value){
- $number = \db('工单_工艺资料')->where('订单编号',$value['订单编号'])->count();
- if ($number === 0){
- $list[$key]['status'] = '*';
- }else{
- $list[$key]['status'] = '';
- }
- }
- $this->success('成功',['data'=>$list,'total'=>$total]);
- }
- /**
- * 编辑页面展示
- * @ApiMethod (GET)
- * @param string $workOrder 工单编号
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function DataCorrection()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $workOrder = input('Gd_gdbh');
- // if (empty($workOrder)){
- // $this->error('参数错误');
- // }
- // $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
- // rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称,rtrim(接单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
- // rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
- // rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid,rtrim(计划投料) as 平张投料';
- // $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
- // if (empty($list)){
- // $this->error('未找到该工单信息');
- // }
- // $printData = \db('工单_印件资料')
- // ->where('Yj_Gdbh',$workOrder)
- // ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(Uniqid) as id')
- // ->cache(true,84600)
- // ->find();
- // if (empty($printData)){
- // $list['印件名称'] = '';
- // $list['印件代号'] = '';
- // $list['印件ID'] = '';
- // }else{
- // $list['印件名称'] = $printData['印件名称'];
- // $list['印件代号'] = $printData['印件代号'];
- // $list['印件ID'] = $printData['id'];
- // }
- // $this->success('成功',$list);
- // }
- /**
- * 工单资料修改
- * @ApiMethod (POST)
- * @param void
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- // public function WorkOrderEdit()
- // {
- // if (Request::instance()->isPost() === false){
- // $this->error('请求错误');
- // }
- // $param = Request::instance()->post();
- // if (empty($param) || isset($param['Uniqid']) === false){
- // $this->error('参数错误');
- // }
- // $row = [
- // 'Gd_lx' => isset($param['lx'])?$param['lx']:'',
- // '开单日期' => isset($param['kdrq'])?$param['kdrq']:'',
- // 'Gd_gdbh' => isset($param['gdbh'])?$param['gdbh']:'',
- // 'Gd_生产分类' => isset($param['scfl'])?$param['scfl']:'',
- // 'Gd_客户代号' => isset($param['khdh'])?$param['khdh']:'',
- // 'Gd_客户名称' => isset($param['khmc'])?$param['khmc']:'',
- // '成品代号' => isset($param['cpdh'])?$param['cpdh']:'',
- // '成品名称' => isset($param['cpmc'])?$param['cpmc']:'',
- // '订单数量' => isset($param['ddsl'])?$param['ddsl']:'',
- // '交货日期' => isset($param['jhrq'])?$param['jhrq']:'',
- // '投料率' => isset($param['tll'])?$param['tll']:'',
- // '计划投料' => isset($param['jhtl'])?$param['jhtl']:'',
- // '实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
- // '计量单位' => isset($param['jldw'])?$param['jldw']:'',
- // '投料大箱' => isset($param['tldx'])?$param['tldx']:'',
- // '销售订单号' => isset($param['xsddh'])?$param['xsddh']:'',
- // '警语版面' => isset($param['jymb'])?$param['jymb']:'',
- // '产品版本号' => isset($param['bbh'])?$param['bbh']:'',
- // '客户ERP编码' => isset($param['erp'])?$param['erp']:'',
- // '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
- // '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
- // 'Gd_desc' => isset($param['desc'])?$param['desc']:'',
- // '排产时库存' => isset($param['kc'])?$param['kc']:'',
- // '平均合格率' => isset($param['avg'])?$param['avg']:'',
- // ];
- // //获取印件资料
- // $printCode = \db('工单_印件资料')
- // ->where('Uniqid',$param['printID'])
- // ->value('yj_Yjno');
- // if (!empty($printCode)){
- // if ((int)$param['jhtl'] >0){
- // //修改工单工艺计划产量
- // $result = $this->PlannedProcessYield($param['gdbh'],$printCode,0,$param['jhtl']);
- // if ($result === false){
- // $this->success('分配工序计划产量失败');
- // }
- // }
- //
- // //修改印件信息
- // $printSql = \db('工单_印件资料')
- // ->where('Uniqid',$param['printID'])
- // ->fetchSql(true)
- // ->update(['Yj_Gdbh'=>$param['gdbh'],'yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
- // $printRes = Db::query($printSql);
- // }
- // //修改工单信息
- // $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
- // $res = Db::query($sql);
- // //修改订单数量该工单下的订单数量
- // //1. 查询该id下的工单编号, 防止其手动修改工单编号导致条件错误
- // $gdbh = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->value('Gd_gdbh');
- // //2. 根据查出的工单编号修改订单数量
- // $sql = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->fetchSql(true)->update(['订单数量'=>$row['订单数量']]);
- // $res1 = Db::query($sql);
- // if ($res !== false && $res1 !== false){
- // $this->success('成功');
- // }else{
- // $this->error('失败');
- // }
- // }
- /**
- * U8投料试算
- * @ApiMethod (GET)
- * @param string $processCode 产品编号
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function U8Trial()
- // {
- // if ($this->request->isGet() === false)
- // {
- // $this->error('请求错误');
- // }
- // $productCode = input('productCode');
- // if (empty($productCode)){
- // $this->error('参数错误');
- // }
- // $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
- // rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
- // $list = \db('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
- // if (empty($list)){
- // $this->success('未找到该产品工序');
- // }
- // foreach ($list as $key=>$value){
- // $data = \db('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
- // $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
- // $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
- // if ($value['add_gxmc'] !== ''){
- // $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
- // }else{
- // $list[$key]['工序名称'] = $value['gxmc'];
- // }
- // unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
- // }
- // $this->success('成功',$list);
- // }
- /**
- * 引用产品资料->获取产品资料
- * @ApiMethod (GET)
- * @param string $workOrder 工单编号
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function ProductInformation()
- // {
- // if ($this->request->isGet() === false)
- // {
- // $this->error('请求错误');
- // }
- // $workOrder = input('workOrder');
- // if (empty($workOrder)){
- // $this->error('参数错误');
- // }
- // $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_客户名称) as 客户名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称';
- // $Detail = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
- // if (empty($Detail)){
- // $this->success('未找到工单信息');
- // }
- // $Detail['客户代号'] = substr($Detail['产品代号'],0,4);
- // $this->success('成功',$Detail);
- // }
- /**
- * 引用产品资料->复制产品工艺资料
- * @ApiMethod (POST)
- * @param string $oldWorkOrder 被复制工单编号
- * @param string $newWorkOrder 复制工单编号
- * @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 ProductInformationEdit()
- // {
- // if (Request::instance()->isPost() === false)
- // {
- // $this->error('请求错误');
- // }
- // $oldWorkOrder = input('oldWorkOrder');
- // $newWorkOrder = input('newWorkOrder');
- // if (empty($oldWorkOrder) || empty($newWorkOrder))
- // {
- // $this->error('参数错误');
- // }
- // $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
- // if ($lastId<10000000){
- // $lastId = 10000000;
- // }else{
- // $lastId = $lastId + 1;
- // }
- // //获取原工单工艺资料
- // $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->select();
- // $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
- // foreach ($oldProcessData as $k=>$v){
- // $oldProcessData[$k]['Gy0_gdbh'] = $oldWorkOrder;
- // $oldProcessData[$k]['Sys_id'] = '';
- // $oldProcessData[$k]['Gy0_sj1'] = '1900-01-01 00:00:00';
- // $oldProcessData[$k]['Gy0_sj2'] = '1900-01-01 00:00:00';
- // $oldProcessData[$k]['UniqId'] = $lastId + $k;
- // $oldProcessData[$k]['PD_WG'] = '1900-01-01 00:00:00';
- // }
- // if (\db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->find()){
- // \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->delete();
- // }
- // //获取原工单印件资料
- // $lastUniqId = \db('工单_印件资料')->order('UniqId desc')->value('UniqId');
- // if ($lastUniqId<1000000){
- // $lastUniqId = 1000000;
- // }else{
- // $lastUniqId = $lastUniqId + 1;
- // }
- // $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->select();
- // $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
- // foreach ($oldPrintData as $k=>$v){
- // $oldPrintData[$k]['Yj_Gdbh'] = $oldWorkOrder;
- // $oldPrintData[$k]['Sys_id'] = '';
- // $oldPrintData[$k]['Uniqid'] = $lastUniqId +$k +1;
- // }
- // if (\db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->find()){
- // \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->delete();
- // }
- // //复制印件、工艺资料
- // $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
- // $ProcessRes = Db::query($ProcessSQL);
- // $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
- // $PrintRes = Db::query($PrintSQL);
- // if ($ProcessRes !== false && $PrintRes !== false){
- // $this->success('成功');
- // }else{
- // $this->error('失败');
- // }
- // }
- /**
- * 工艺流程调成->获取当前工单工艺资料
- * @ApiMethod (GET)
- * @param string $workorder 当前工单编号
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function ProcessFlow()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $workOrder = input('workOrder');
- // if (empty($workOrder)){
- // $this->error('参数错误');
- // }
- // $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
- // if (empty($list)){
- // $this->success('未找到工单信息');
- // }
- // $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
- // rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
- // rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间,rtrim(UniqId) as UniqId';
- // $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->cache(true,84600)->field($filed)->select();
- // if (empty($process)){
- // $this->error('未找到该工单工艺资料');
- // }
- // foreach ($process as $key=>$value){
- // if (isset($value['add_gxmc'])){
- // $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
- // }else{
- // $process[$key]['工序名称'] = $value['gxmc'];
- // }
- // $process[$key]['工价系数'] = (float)$value['工价系数'];
- // $process[$key]['损耗系数'] = (float)$value['损耗系数'];
- // $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
- // }
- // $list['process'] = $process;
- // $this->success('成功',$list);
- // }
- /**
- * 参照工单列表获取
- * @ApiMethod (GET)
- * @param string $workOrder 工单编号
- * @param string $productCode 产品代号
- * @return void
- */
- // public function ReferenceWorkOrder()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $productCode = input('productCode');
- // $workOrder = input('workOrder');
- // if (empty($productCode) || empty($workOrder)){
- // $this->error('参数错误');
- // }
- // $list = \db('工单_基本资料')->where('成品代号',$productCode)->distinct(true)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
- // if (empty($list)){
- // $this->success('未获取该产品其他工单信息');
- // }
- // $this->success('成功',$list);
- // }
- /**
- * 工艺资料复制
- * @ApiMethod (POST)
- * @param string $oldWorkOrder 被复制工单编号
- * @param string $newWorkOrder 复制工单编号
- * @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 ProcessCopy()
- // {
- // if (Request::instance()->isPost() === false){
- // $this->error('请求错误');
- // }
- // $param = Request::instance()->post();
- // if (empty($param)){
- // $this->error('参数错误');
- // }
- // $UniqId = [];
- // $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
- // if ($lastId['id']>10000000){
- // $lastUniqId = $lastId['id'];
- // }else{
- // $lastUniqId = 10000000;
- // }
- // foreach ($param as $key=>$value){
- // $UniqId[$key] = $value['UniqId'];
- // }
- // $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
- // if (empty($processList)){
- // $this->success('未找到工艺资料');
- // }
- // $data = [];
- // foreach ($param as $key=>$value){
- // foreach ($processList as $k=>$v){
- // if ($value['UniqId'] = $v['UniqId']){
- // $data[$key] = $v;
- // $data[$key]['Gy0_gxh'] = $value['gxh'];
- // $data[$key]['Gy0_gdbh'] = $value['workOrder'];
- // $data[$key]['UniqId'] = $lastUniqId + $key + 1;
- // }
- // }
- // }
- // $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
- // if ($res !== false){
- // $result = \db('工单_工艺资料')->insertAll($data);
- // if ($result !== false){
- // $this->success('成功');
- // }else{
- // $this->error('失败');
- // }
- // }else{
- // $this->error('失败');
- // }
- // }
- /**
- * U8工单列表
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function U8workOrder()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param)){
- // $this->error('参数错误');
- // }
- // $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
- // rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
- // $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
- // if (empty($list)){
- // $this->success('未找到工单');
- // }
- // $this->success('成功',$list);
- // }
- /**
- * U8工单资料删除
- * @param string $workOrder 工单编号
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function orderDataDel()
- {
- if($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $workOrder = input('Uniqid');
- if (empty($workOrder)){
- $this->error('参数错误');
- }
- $order = \db('工单_基本资料')->where('Uniqid',$workOrder)->find();
- \db()->startTrans();
- try {
- \db('工单_印件资料')->where('订单编号',$order['订单编号'])->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
- \db('工单_工艺资料')->where('订单编号',$order['订单编号'])->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
- $res = \db('工单_基本资料')->where('Uniqid',$workOrder)->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
- \db()->commit();
- } catch (\Exception $e){
- \db()->rollback();
- }
- if ($res !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 产品废检系数调整->质检工艺数据获取
- * @ApiMethod (GET)
- * @param string $workOrder 工单编号
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function TestCoefficient()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $workOrder = input('workOrder');
- // if (empty($workOrder)){
- // $this->error('参数错误');
- // }
- // $where = [
- // 'Gy0_gdbh' => $workOrder,
- // 'Gy0_gxmc' => ['like','%检%']
- // ];
- // $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
- // rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
- // rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
- // $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
- // if (empty($list)){
- // $this->success('未找到该工单工艺');
- // }
- // $name = \db('工单_基本资料')
- // ->where('Gd_gdbh',$workOrder)
- // ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
- // ->find();
- // if (empty($name)){
- // $this->success('未找到该工单');
- // }
- // 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['gdbh'].'-'.$value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
- // unset($list[$key]['gdbh'],$list[$key]['yjno'],$list[$key]['gxmc']);
- // $list[$key]['产品编号'] = $name['产品代号'];
- // $list[$key]['产品名称'] = $name['产品名称'];
- // $list[$key]['客户名称'] = $name['客户名称'];
- // }
- // $this->success('成功',$list);
- // }
- /**
- * 产品质检系数调整->系数修改
- * @ApiMethod (GET)
- * @param string $workorder 工单编号
- * @param string $processCode 工序号
- * @param float $code1 人工正品板
- * @param float $code2 人工次品板
- * @param float $code3 人工废检
- * @param float $code4 机检正品板
- * @param float $code5 机检次品板
- * @param float $code6 机检废检
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- // public function TestCoefficientEdit()
- // {
- // if (Request::instance()->isPost() === false){
- // $this->error('请求错误');
- // }
- // $workOrder = input('workOrder');
- // $processCode = input('processCode');
- // $row = [
- // '人工检_正品板' => input('code1'),
- // '人工检_次品板' => input('code2'),
- // '人工检_废检' => input('code3'),
- // '机检_正品板' => input('code4'),
- // '机检_次品板' => input('code5'),
- // '机检_废检' => input('code6'),
- // ];
- // if (empty($workOrder) || empty($processCode)){
- // $this->error('参数错误');
- // }
- // $where = [
- // 'Gy0_gdbh' => $workOrder,
- // 'Gy0_gxh' => $processCode
- // ];
- // $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
- // $res = Db::query($sql);
- // if ($res !== false){
- // $this->success('成功');
- // }else{
- // $this->error('失败');
- // }
- // }
- /**
- * 修正工单核算参数->数据获取
- * @ApiMethod (GET)
- * @param string $workOrder 工单编号
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function AccountingParameter()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $workOrder = input('workOrder');
- // if (empty($workOrder)){
- // $this->error('参数错误');
- // }
- // $field = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
- // rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
- // rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
- // $list = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
- // if (empty($list)){
- // $this->success('未找到该工单工艺资料');
- // }
- // 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'].'('.$value['add_gxmc'].')';
- // unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
- // }
- // $this->success('成功',$list);
- // }
- /**
- * 修正工单核算参数->参数修改
- * @ApiMethod (POST)
- * @param void
- * @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 AccountingParameterEdit()
- // {
- // if (Request::instance()->isPost() === false){
- // $this->error('请求错误');
- // }
- // $param = Request::instance()->post();
- // if (empty($param) || isset($param[0]['Uniqid']) === false){
- // $this->error('参数错误');
- // }
- // $i = 0;
- // foreach ($param as $key=>$value){
- // $data['rate0'] = 0;
- // $data['rate1'] = 0;
- // $rate = \db('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
- // if (!empty($rate)){
- // $data['rate0'] = $rate['rate0'];
- // $data['rate1'] = $rate['rate1'];
- // }
- // $row = [
- // '工价系数' => $value['difficulty']?:'',
- // 'Gy0_shdh' => $value['loss']?:'',
- // '印刷方式' => $value['printMode']?:'',
- // '版距' => $value['plate']?:'',
- // 'Gy0_ms' => $value['chromatic']?:'',
- // '损耗系数' => $value['wastage']?:'',
- // 'Gy0_Rate0' => $data['rate0'],
- // 'Gy0_Rate1' => $data['rate1']
- // ];
- // $sql = \db('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
- // $res = Db::query($sql);
- // if ($res !== false){
- // $i++;
- // }
- // }
- // if ($i !== 0){
- // $this->success('成功');
- // }else{
- // $this->error('失败');
- // }
- // }
- /**
- * 印件资料修改
- * @ApiMethod (POST)
- * @param void
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function PrintedEdit()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param) || isset($param['Uniqid']) === false){
- $this->error('参数错误');
- }
- $param['Yj_Gdbh'] = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->value('Yj_Gdbh');
- $data = [
- 'Yj_Gdbh' =>$param['Yj_Gdbh'],
- 'yj_Yjno' =>$param['yjno'],
- 'yj_Yjdh' =>$param['yjdh'],
- 'yj_yjmc' =>$param['yjmc'],
- 'yj_zzdh' =>$param['zzdh'],
- 'yj_zzdh1' =>$param['zzdh1'],
- 'yj_zzdh2' =>$param['zzdh2'],
- 'yj_zzdh3' =>$param['zzdh3'],
- 'yj_zzdh4' =>$param['zzdh4'],
- 'yj_zzmc' =>$param['zzmc'],
- 'yj_zzmc1' =>$param['zzmc1'],
- 'yj_zzmc2' =>$param['zzmc2'],
- 'yj_zzmc3' =>$param['zzmc3'],
- 'yj_zzmc4' =>$param['zzmc4'],
- 'yj_tlgg' =>$param['tlgg'],
- 'yj_klgg' =>$param['klgg'],
- 'Yj_核算规格' =>$param['hsgg'],
- 'yj_成品数量' =>$param['cpsl'],
- 'yj_平张投料' =>$param['pztl'],
- 'yj_ks' =>$param['ks'],
- 'yj_ls' =>$param['ls'],
- 'yj_desc' =>$param['desc'],
- ];
- $UniqId = $param['Uniqid'];
- $sql = \db('工单_印件资料')->where('Uniqid',$UniqId)->fetchSql(true)->update($data);
- $res = Db::query($sql);
- $process = \db('工单_工艺资料')
- ->where('Gy0_gdbh',$data['Yj_Gdbh'])
- ->where('Gy0_yjno',$data['yj_Yjno'])
- ->select();
- if ((int)$data['yj_平张投料'] > 0 && !empty($process)){
- //重新分配工序计划产量
- $result = $this->PlannedProcessYield($data['Yj_Gdbh'],$data['yj_Yjno'],0,$data['yj_平张投料']);
- if ($result === false){
- $this->success('修改工序产量失败');
- }
- }
- if ($res !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 工艺资料修改
- * @ApiMethod (POST)
- * @param void
- * @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 ProcessDetailEdit()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param) || isset($param['UniqId']) === false){
- $this->error('参数错误');
- }
- if (empty($param['Gy0_shdh'])){
- $rate['rate0'] = 0;
- $rate['rate1'] = 0;
- }else{
- $rate = \db('dic_lzsh')->where('sys_bh',$param['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
- }
- $param['Gy0_Rate0']= isset($rate['rate0'])?$rate['rate0']:0;
- $param['Gy0_Rate1'] = isset($rate['rate1'])?$rate['rate1']:0;
- $param['Mod_rq'] = date('Y-m-d H:i:s',time());
- $UniqId = $param['UniqId'];
- unset($param['UniqId']);
- //修改工艺资料
- $sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
- $res = Db::query($sql);
- //获取工艺资料数据
- $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
- //修改工单状态
- $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
- if ($status['status'] !== '2-生产中'){
- $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
- Db::query($statusSql);
- }
- //重新分配工序计划产量
- if ((int)$list['计划接货数'] > 0){
- $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],$list['Gy0_gxh'],$list['计划接货数']);
- }
- if ($res !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 工艺资料编辑->机台列表获取
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function MachineList()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param)){
- // $this->error('参数错误');
- // }
- // $list = \db('设备_基本资料')
- // ->where('存放地点',$param['address'])
- // ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
- // ->select();
- // if (empty($list)){
- // $this->success('未找到该车间机台');
- // }
- // $data = [];
- // foreach ($list as $key=>$value){
- // $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
- // }
- // $this->success('成功',$data);
- // }
- /**
- * 打印作业通知单->工单印件和工序获取
- * @ApiMethod (GET)
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function PrintCodeList()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param)){
- // $this->error('参数错误');
- // }
- // $list = \db('工单_印件资料')
- // ->field([
- // 'rtrim(yj_Yjno)' => '印件号',
- // 'rtrim(yj_yjmc)' => '印件名称'
- // ])
- // ->where('Yj_Gdbh',$param['workOrder'])
- // ->select();
- // $this->success('成功',$list);
- // }
- /**
- * 打印作业通知单->工艺编号获取
- * @ApiMethod (GET)
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function ProcessCodeList()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param)){
- // $this->error('参数错误');
- // }
- // $list = \db('工单_工艺资料')
- // ->field('rtrim(Gy0_gxh) as 工序号')
- // ->where([
- // 'Gy0_gdbh' => $param['workOrder'],
- // 'Gy0_yjno' => $param['yjno']
- // ])
- // ->select();
- // $this->success('成功',$list);
- // }
- /**
- * 打印作业通知单
- * @ApiMethod (POST)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function PrintJobOrder()
- // {
- // if ($this->request->isGet() === false) {
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param)){
- // $this->error('参数错误');
- // }
- // $data = $this->workOrderDetailGet($param['workOrder'],$param['yjno']);
- // if (empty($data)){
- // $this->success('未找到工单信息');
- // }
- // $materiel = $this->MaterielDetailGet($param['workOrder']);
- // $printDetail = $this->PrintDetailGet($param['workOrder'],$param['yjno'],$param['gxh']);
- // if (empty($printDetail)){
- // $this->success('未找到工艺信息');
- // }
- // $number = 0;
- // foreach ($printDetail as $key=>$value){
- // $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
- // $number = $number+$value['允损比例'];
- // }
- // $data['制单'] = $param['PrepareDocument'];
- // $data['审核'] = $param['examine'];
- // $data['目标合格率'] = 100-$number.'%';
- // $data['materiel'] = $materiel;
- // $data['printDetail'] = $printDetail;
- // $this->success('成功',$data);
- // }
- /**
- * 打印作业通知单->工单及印件资料获取
- * @param $workOrder
- * @return mixed
- */
- // public function workOrderDetailGet($workOrder,$yjno)
- // {
- // $sql = "SELECT
- // RTRIM( a.Gd_lx) AS 工单类型,
- // RTRIM( a.Gd_gdbh ) AS 生产批次号,
- // RTRIM( a.销售订单号 ) AS 销售订单号,
- // RTRIM( a.Gd_客户代号 ) AS 客户代号,
- // RTRIM( a.Gd_客户名称 ) AS 客户名称,
- // RTRIM( a.成品代号 ) AS 产品代码,
- // RTRIM( a.成品名称 ) AS 产品名称,
- // RTRIM( a.产品版本号 ) AS 版本号,
- // RTRIM( a.警语版面 ) AS 警语版面,
- // RTRIM( a.码源数量 ) AS 码源数量,
- // RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
- // RTRIM( a.接单日期 ) AS 开单日期,
- // RTRIM( a.交货日期 ) AS 交货日期,
- // RTRIM( a.Gd_desc ) AS 工单说明,
- // RTRIM( a.投料率 ) AS 投料率,
- // RTRIM( a.订单数量 ) AS 订单数量,
- // RTRIM( a.平均合格率 ) AS 平均合格率,
- // RTRIM( a.投料大箱 ) AS 订货数量,
- // RTRIM( a.排产时库存 ) AS 排产时库存,
- // RTRIM( b.yj_Yjno ) AS 印件,
- // RTRIM( b.yj_Yjdh ) AS 印件代号,
- // RTRIM( b.yj_yjmc ) AS 印件名称,
- // RTRIM( b.yj_平张投料 ) AS 平张投料量,
- // RTRIM( b.yj_zzmc ) AS 纸张名称,
- // RTRIM( b.yj_tlgg ) AS 投料规格,
- // RTRIM( b.yj_ks ) AS 开数,
- // RTRIM( b.yj_ls ) AS 联数,
- // RTRIM( b.yj_desc ) AS 印件备注
- // FROM
- // `工单_基本资料` AS a
- // JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh
- // WHERE
- // a.Gd_gdbh = '{$workOrder}' AND a.行号 = 1 AND b.yj_Yjno = '{$yjno}'";
- // $list = Db::query($sql);
- // if (empty($list)){
- // $this->success('未找到订单数据');
- // }
- // $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
- // $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
- // if (strpos($list[0]['产品名称'],'条') !== false){
- // $list[0]['订货数量'] = (int)$list[0]['订单数量']*40;
- // $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/250);
- // }else{
- // $list[0]['订货数量'] = (int)$list[0]['订单数量']*4;
- // $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/2500);
- // }
- // $list[0]['联数'] = (int)$list[0]['联数'];
- // $list[0]['印件代号及名称'] = $list[0]['印件代号'].' '.$list[0]['印件名称'];
- //// $list[0]['投料数量'] = $list[0]['订货数量'];
- // unset($list[0]['印件代号'],$list[0]['印件名称']);
- // return($list[0]);
- // }
- /**打印作业流程单->物料资料获取
- * @param $workOrder
- * @return bool|\PDOStatement|string|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function MaterielDetailGet($workOrder)
- // {
- // $where = [
- // 'BOM_工单编号' => $workOrder,
- // ];
- // $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
- // $list = \db('工单_bom资料')->where($where)->field($filed)->select();
- // if (!empty($list)){
- // foreach ($list as $key=>$value){
- // $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
- // $list[$key]['计划用量'] = (float)$value['计划用量'];
- // unset($list[$key]['物料编码'],$list[$key]['物料名称']);
- // }
- // }
- // return $list;
- // }
- /**
- * 打印作业流程单->工艺资料获取
- * @param $workOrder
- * @return bool|\PDOStatement|string|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function PrintDetailGet($workOrder,$yjno,$gxh)
- // {
- // $where = [
- // 'Gy0_gdbh' => $workOrder,
- // 'Gy0_yjno' => $yjno,
- // 'Gy0_gxh' => ['<=',$gxh]
- // ];
- // $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
- // rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
- // rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
- // $list = \db('工单_工艺资料')
- // ->where($where)
- // ->field($filed)
- // ->select();
- // if (empty($list)){
- // $this->success('工单工艺为空');
- // }
- // foreach ($list as $key=>$value){
- // if ($value['yjno']<10){
- // $value['yjno'] = '0'.$value['yjno'];
- // }
- // if ($value['gxh']<10){
- // $value['gxh'] = '0'.$value['gxh'];
- // }
- // if ($value['add_gxmc'] !== null){
- //
- // $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
- // }else{
- // $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
- // }
- // $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
- // $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
- // if ((int)$value['计划接货数'] === 0){
- // $list[$key]['允损比例'] = 0;
- // }else{
- // $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
- // }
- // unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
- // }
- // return $list;
- // }
- /**
- * 获取小时产能
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function capacityList()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param)){
- // $this->error('参数错误');
- // }
- // $machine = explode(' ',$param['machine'])[0];
- // $number = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(排单小时定额) as 小时产能')->find();
- // if (empty($number)){
- // $this->error('未找到小时产能');
- // }
- // $this->success('成功',$number['小时产能']);
- // }
- /**
- * 新增工单->添加工单
- * @ApiMethod (POST)
- * @param
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function WorkOrderAdd()
- {
- // var_dump(1);exit;
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $param['Sys_rq'] = date('Y-m-d H:i:s');
- $param['gd_statu'] = '1-计划中';
- $prefix = substr($param['订单编号'], 0, 2); // e.g., "DC"
- $maxOrder = \db('工单_基本资料')
- ->where('订单编号', 'like', "{$prefix}%")
- ->order('订单编号', 'desc')
- ->limit(1)
- ->value('订单编号');
- if ($maxOrder) {
- $numericPart = substr($maxOrder, 2);
- $newNumericPart = str_pad((int)$numericPart + 1, strlen($numericPart), '0', STR_PAD_LEFT);
- $param['订单编号'] = $prefix . $newNumericPart;
- } else {
- $param['订单编号'] = $param['订单编号'];
- }
- $sql= \db('工单_基本资料')->fetchSql(true)->insert($param);
- $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 ClientList()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (isset($param['search'])){
- // $where = $param['search'].'%';
- // $sql = "SELECT DISTINCT
- // (客户编号),rtrim(客户名称 ) as 客户名称
- // FROM
- // `产品_基本资料`
- // WHERE
- // 客户编号 LIKE "."'".$where."'"."
- // OR
- // 客户名称 LIKE "."'".$where."'"."
- // GROUP BY
- // 客户编号
- // order by
- // 客户编号";
- // }else{
- // $sql = "SELECT DISTINCT
- // (客户编号),rtrim(客户名称 ) as 客户名称
- // FROM
- // `产品_基本资料`
- // GROUP BY
- // 客户编号
- // order by
- // 客户编号";
- // }
- // $list = \db()->query($sql);
- // if (empty($list)){
- // $this->success('未找到客户列表');
- // }
- // foreach ($list as $key=>$value){
- // if (empty($value['客户编号'])){
- // unset($list[$key]);
- // }else{
- // $list[$key]['客户编号'] = rtrim($value['客户编号']);
- // $list[$key]['name'] = rtrim($value['客户编号']).'【'.$value['客户名称'].'】';
- // if ($value['客户编号'] == '1098'){
- // $list[$key]['客户名称'] = '打样专用';
- // }
- // }
- // }
- // $list = array_values($list);
- // $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 ProductCodeList()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (isset($param['cilent']) === false){
- // $this->error('参数错误');
- // }
- // $where = ['产品编号'=>['like',$param['cilent'].'%']];
- // $list = \db('产品_基本资料')
- // ->where($where)
- // ->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
- // ->select();
- // if (empty($list)){
- // $this->success('未获取到产品数据');
- // }
- // foreach ($list as $key=>$value){
- // $list[$key]['name'] = $value['产品编号'].'【'.$value['产品名称'].'】';
- // }
- // $this->success('成功',$list);
- // }
- /**
- * 新增印件资料->印件资料添加
- * @return void
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function PrintDetailAdd()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $param['Sys_rq'] = date('Y-m-d H:i:s',time());
- $process = [
- ['1','仓库出库'],['2','裁切'],['3','车缝'],['4','后道收样'],['5','大烫'],['6','总检'],['7','包装']
- ];
- $processDetail = [];
- foreach ($process as $key=>$value){
- $total = null;
- if ($key !== 0){
- $total = $param['zdtotal'];
- }
- $processDetail[$key] = [
- '订单编号' => $param['订单编号'],
- '子订单编号' => $param['子订单编号'],
- '款号' => $param['款号'],
- '颜色' => $param['颜色'],
- '工序编号' => $value[0],
- '工序名称' => $value[1],
- '计划产量' => $total,
- 'Sys_id' => $param['Sys_id'],
- 'Sys_rq' => $param['Sys_rq']
- ];
- }
- //开启事务
- db()->startTrans();
- try{
- $priSql = \db('工单_印件资料')->fetchSql(true)->insert($param);
- $priRes = \db()->query($priSql);
- $proSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($processDetail);
- $proRes = \db()->query($proSql);
- // 提交事务
- db()->commit();
- } catch (\Exception $e) {
- // 回滚事务
- db()->rollback();
- $this->error($e->getMessage());
- }
- if ($priRes !== false && $proRes !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 新增工艺资料->工艺资料添加
- * @return void
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- // public function ProcessDetailAdd()
- // {
- // if (Request::instance()->isPost() === false){
- // $this->error('请求错误');
- // }
- // $param = Request::instance()->post();
- // if (empty($param)){
- // $this->error('参数错误');
- // }
- // $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
- // if (empty($lastId)){
- // $lastId = 0;
- // }else{
- // $lastId = $lastId + 1;
- // }
- // if (empty($param['Gy0_shdh'])){
- // $param['Gy0_Rate0'] = 0;
- // $param['Gy0_Rate1'] = 0;
- // }else{
- // $detail = \db('dic_lzsh')->field('sys_rate0,sys_rate1')->where('sys_bh',$param['Gy0_shdh'])->find();
- // $param['Gy0_Rate0'] = $detail['sys_rate0'];
- // $param['Gy0_Rate1'] = $detail['sys_rate1'];
- // }
- // $param['Sys_rq'] = date('Y-m-d H:i:s',time());
- // $param['Mod_rq'] = '1900-01-01 00:00:00';
- // $param['Gy0_sj1'] = '1900-01-01 00:00:00';
- // $param['Gy0_sj2'] = '1900-01-01 00:00:00';
- // $param['PD_WG'] = '1900-01-01 00:00:00';
- // $param['UniqId'] = $lastId;
- // $sql = \db('工单_工艺资料')
- // ->fetchSql(true)
- // ->insert($param);
- // $res = \db()->query($sql);
- // //获取平张投料
- // $number = \db('工单_印件资料')
- // ->where('Yj_Gdbh',$param['Gy0_gdbh'])
- // ->where('yj_Yjno',$param['Gy0_yjno'])
- // ->value('rtrim(yj_平张投料)');
- // //分配工艺计划产量
- // if ((int)$number >0){
- // $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],$param['Gy0_gxh'],$number);
- // }
- // if ($res !== false){
- // $this->success('成功');
- // }else{
- // $this->error('失败');
- // }
- //
- // }
- /**
- * 新增工艺资料->印件编号获取
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function PrintDetailList()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param)){
- // $this->error('参数错误');
- // }
- // $printList = \db('工单_印件资料')
- // ->where('Yj_Gdbh',$param['workOrder'])
- // ->order('yj_Yjno')
- // ->select();
- // if (empty($printList)){
- // $this->success('未找到该工单印件资料');
- // }
- // $list = [];
- // foreach ($printList as $key=>$value){
- // $list[$key]['name'] = rtrim($value['yj_Yjno']).'-->'.rtrim($value['yj_yjmc']);
- // $list[$key]['no'] = rtrim($value['yj_Yjno']);
- // }
- // $this->success('成功',$list);
- // }
- /**
- * 子订单列表
- * @return null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function PrintListData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (isset($param) === false){
- $this->error('参数错误');
- }
- $where['Mod_rq'] = null;
- $xhdata = \db('工单_印件资料')
- ->where('订单编号',$param['order'])
- ->where($where)
- ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
- ->select();
- $arr = [];
- foreach ($xhdata as $key => $value){
- for($i=1;$i<=10;$i++){
- if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
- array_push($arr,$value['cm'.$i]);
- }
- }
- }
- $arr = array_unique($arr);
- sort($arr);
- $list = \db('工单_印件资料')
- ->where('订单编号',$param['order'])
- ->where($where)
- ->field('订单编号,子订单编号,款号,颜色,船样,zdtotal,Sys_id,Sys_rq,ck_rq,sc_rq,cm1,cm2,cm3,cm4,cm5,cm6,
- cm7,cm8,cm9,cm10,cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
- ->select();
- foreach ($list as $key=>$value){
- for($i=1;$i<=10;$i++){
- if ($value['cm'.$i] !== ''){
- $list[$key][$value['cm'.$i]] = $value['cmsl'.$i];
- }
- unset($list[$key]['cm'.$i],$list[$key]['cmsl'.$i]);
- }
- }
- $data['型号'] = $arr;
- $data['列表'] = $list;
- $this->success('成功',$data);
- }
- /**
- * 工单资料管理->印件资料删除
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function PrintDetailDel()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (isset($param['UniqId']) === false){
- $this->error('参数错误');
- }
- $printId = explode(',',$param['UniqId']);
- $i = 0;
- foreach ($printId as $value){
- $res = \db('工单_印件资料')
- ->where('Uniqid',$value)
- ->update(['Mod_rq'=>date('Y-m-d H:i:s',time())]);
- if ($res === false){
- $i++;
- }
- }
- if ($i === 0){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- /**
- * 工单资料管理->工艺资料删除
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- // public function ProcessDetailDel()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (isset($param['UniqId']) === false){
- // $this->error('参数错误');
- // }
- // $printId = explode(',',$param['UniqId']);
- // $i = 0;
- // //获取工单编号、印件号
- // $codeList = \db('工单_工艺资料')
- // ->where('UniqId',$printId[0])
- // ->field('rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_yjno) as 印件号')
- // ->find();
- // //获取平张投料数量
- // $number = \db('工单_印件资料')
- // ->where([
- // 'Yj_Gdbh' => $codeList['工单编号'],
- // 'yj_Yjno' => $codeList['印件号']
- // ])
- // ->value('rtrim(yj_平张投料)');
- // //循环删除工艺资料
- // foreach ($printId as $value){
- // $res = \db('工单_工艺资料')
- // ->where('UniqId',$value)
- // ->delete();
- // if ($res === false){
- // $i++;
- // }
- // }
- // //重新分配工艺计划产量
- // if ((int)$number>0){
- // $this->PlannedProcessYield($codeList['工单编号'],$codeList['印件号'],0,$number);
- // }
- // if ($i === 0){
- // $this->success('删除成功');
- // }else{
- // $this->error('删除失败');
- // }
- // }
- /**
- * 工艺资料添加->工序损耗代码
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function WastageList()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param['process'])){
- // $this->error('参数错误');
- // }
- // $order = \db('dic_lzsh')
- // ->where('sys_mc','like',$param['process'].'%')
- // ->value('rtrim(sys_bh) as 编号');
- // $this->success('成功',$order);
- // }
- /**
- * 获取产品附件列表
- */
- // 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 annexAdd(){
- // if(!$this->request->isPost()){
- // $this->error('请求方式错误');
- // }
- // $req = $this->request->param();
- //
- // $arr = [
- // 'sys_id',
- // '序号',
- // '附件备注',
- // '附件内容',
- // '附件类型',
- // '适用工序',
- // '关联产品'
- // ];
- // $data = [];
- // foreach ($arr as $key => $value){
- // if (!isset($req[$value])){
- // $this->error('参数错误',$value,$key+1);
- // }
- // $data[$value] = $req[$value];
- // }
- // $data['sys_rq'] = date('Y-m-d H:i:s');
- //
- // //开启事务
- // db()->startTrans();
- // try{
- // $sql = db('产品_技术附件')->fetchSql(true)->insert($data);
- // $bool = db()->query($sql);
- // // 提交事务
- // db()->commit();
- // } catch (\Exception $e) {
- // // 回滚事务
- // db()->rollback();
- // $this->error($e->getMessage());
- // }
- //
- // if($bool===false) $this->error('失败');
- //
- // $this->success('成功');
- // }
- /**
- * 产品附件修改
- * @ApiMethod (GET)
- * @param string 'UniqId'
- */
- // public function annexDel()
- // {
- // if(!$this->request->isGet()){
- // $this->error('请求方式错误');
- // }
- // $req = $this->request->param();
- //
- // if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
- // $this->error('参数错误','UniqId',100);
- // }
- //
- // //开启事务
- // db()->startTrans();
- // try{
- // $bool = db('产品_技术附件')->where('UniqId',$req['UniqId'])->delete();
- // // 提交事务
- // db()->commit();
- // } catch (\Exception $e) {
- // // 回滚事务
- // db()->rollback();
- // $this->error($e->getMessage());
- // }
- //
- // if($bool===false) $this->error('失败');
- //
- // $this->success('成功');
- //
- // }
- /**
- * 获取产品附件列表
- */
- // 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);
- // }
- /**
- * 产品附件新增
- */
- public function gdAnnexAdd(){
- if(!$this->request->isPost()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- $arr = [
- 'sys_id',
- '附件备注',
- '附件内容',
- '附件类型',
- '关联编号'
- ];
- $data = [];
- foreach ($arr as $key => $value){
- if (!isset($req[$value])){
- $this->error('参数错误',$value,$key+1);
- }
- $data[$value] = $req[$value];
- }
- $data['sys_rq'] = date('Y-m-d H:i:s');
- //检测目录是否存在
- if(is_dir(ROOT_PATH.'public/uploads/'.$req['关联编号']) == null)
- {
- mkdir(ROOT_PATH.'public/uploads/'.$req['关联编号'],0777,true);
- }
- $base64Data = $req['附件内容'];
- if (strpos($base64Data, 'base64,') !== false) {
- $base64Data = explode('base64,', $base64Data)[1]; // 去掉前缀
- }
- // 解码 Base64 数据
- $tempFileContent = base64_decode($base64Data);
- // 创建一个临时文件
- $tempFile = tempnam(sys_get_temp_dir(), 'excel_') . '.xlsx';
- // 将解码后的内容写入临时文件
- file_put_contents($tempFile, $tempFileContent);
- // 加载 Excel 文件
- $spreadsheet =IOFactory::load($tempFile);
- //储存pdf地址
- $address = '';
- // 遍历每个工作表
- foreach ($spreadsheet->getAllSheets() as $index => $sheet) {
- // 创建新 Spreadsheet 对象,仅包含当前工作表
- $pdfSpreadsheet = new Spreadsheet();
- $pdfSpreadsheet->addExternalSheet($sheet);
- // 设置 PDF 写入器
- $pdfWriter = new Tcpdf($pdfSpreadsheet);
- // 生成 PDF 文件名
- $pdfFileName = 'output_sheet_' . ($index + 1) . '.pdf';
- //设置保存地址
- $pdfOutputPath = ROOT_PATH.'public/uploads/'.$req['关联编号'] . $pdfFileName;
- // 保存到服务器指定目录
- $pdfWriter->save($pdfOutputPath);
- // 编辑pdf地址
- $address = $pdfOutputPath.',' . $address;
- }
- // 清理临时文件
- unlink($tempFile);;
- //开启事务
- db()->startTrans();
- try{
- $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
- $bool = db()->query($sql);
- // 提交事务
- db()->commit();
- } catch (\Exception $e) {
- // 回滚事务
- db()->rollback();
- $this->error($e->getMessage());
- }
- if($bool===false) $this->error('失败');
- $this->success('成功');
- }
- /**
- * 产品附件修改
- * @ApiMethod (GET)
- * @param string 'UniqId'
- */
- // public function gdAnnexDel()
- // {
- // if(!$this->request->isGet()){
- // $this->error('请求方式错误');
- // }
- // $req = $this->request->param();
- //
- // if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
- // $this->error('参数错误','UniqId',100);
- // }
- //
- // //开启事务
- // db()->startTrans();
- // try{
- // $bool = db('工单_相关附件')->where('UniqId',$req['UniqId'])->delete();
- // // 提交事务
- // db()->commit();
- // } catch (\Exception $e) {
- // // 回滚事务
- // db()->rollback();
- // $this->error($e->getMessage());
- // }
- //
- // if($bool===false) $this->error('失败');
- //
- // $this->success('成功');
- //
- // }
- /**
- * 引用工单资料数据查询
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function WorkOrderDetailCope()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param['search'])){
- // $this->error('参数错误');
- // }
- // $list = \Db('工单_基本资料')
- // ->alias('a')
- // ->field([
- // 'rtrim(a.Gd_gdbh)' => '工单编号',
- // 'rtrim(b.客户编号)' => '客户编号',
- // 'rtrim(b.客户名称)' => '客户名称',
- // 'rtrim(b.产品编号)' => '产品编号',
- // 'rtrim(b.产品名称)' => '产品名称'
- // ])
- // ->join('产品_基本资料 b', 'a.成品代号 = b.产品编号')
- // ->join('产品_工艺资料 c', 'a.成品代号 = c.Gy0_cpdh')
- // ->join('产品_印件资料 d', 'a.成品代号 = d.yj_cpdh')
- // ->where(function($query) use ($param) {
- // $query->where('a.Gd_gdbh', 'like', '%'.$param['search'].'%')
- // ->whereOr('a.成品名称', 'like', '%'.$param['search'].'%');
- // })
- // ->where(function($query) {
- // $query->where('c.Gy0_cpdh', '<>', '')
- // ->where('d.yj_cpdh', '<>', '')
- // ->where('b.状态', 'not like', '%停用%')
- // ->where('b.产品名称', 'not like', '%停用%');
- // })
- // ->group('a.Gd_gdbh')
- // ->order('a.Uniqid desc')
- // ->select();
- // if (empty($list)){
- // $this->success('未找到工单资料');
- // }else{
- // $this->success('成功',$list);
- // }
- // }
- //
- /**
- * 引用产品印件、工艺资料
- * @return void
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- // public function WorkOrderDetailListCope()
- // {
- // if (Request::instance()->isPost() === false){
- // $this->error('请求错误');
- // }
- //
- // $param = Request::instance()->post();
- // if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
- // $this->error('参数错误');
- // }
- // if (isset($param['sort'])){
- // $priWhere['yj_yjno'] = ['>=',10];
- // $proWhere['Gy0_yjno'] = ['>=',10];
- // }else{
- // $priWhere['yj_yjno'] = ['<',10];
- // $proWhere['Gy0_yjno'] = ['<',10];
- // }
- // $list = \db('工单_基本资料')
- // ->where('Gd_gdbh',$param['workorder'])
- //// ->where('成品代号',$param['productCode'])
- // ->field('行号,Gd_cpdh')
- // ->select();
- // //引用印件资料
- // $PrintList = \db('产品_印件资料')
- // ->where('yj_cpdh',$param['productCode'])
- // ->where($priWhere)
- // ->select();
- // if (empty($PrintList)){
- // $this->error('未找到印件资料');
- // }
- // $PrintLastId = \db('工单_印件资料')->order('Uniqid desc')->value('rtrim(Uniqid)');
- // $number = \db('工单_基本资料')
- // ->where('Gd_gdbh',$param['workorder'])
- // ->where('成品代号',$param['productCode'])
- // ->value('rtrim(计划投料)');
- // $arr = [];
- // foreach ($PrintList as $key => $value){
- // foreach ($list as $k=>$v){
- // if ($value['yj_yjdh'] === $v['Gd_cpdh']){
- // $PrintList[$key]['Yj_Gdbh'] = $param['workorder'];
- // $PrintList[$key]['yj_Yjno'] = $value['yj_yjno'];
- // $PrintList[$key]['yj_Yjdh'] = $value['yj_yjdh'];
- // $PrintList[$key]['yj_ks'] = $value['yj_ks'];
- // $PrintList[$key]['yj_ls'] = $value['yj_ls'];
- // $PrintList[$key]['yj_平张投料'] = $number;
- // $PrintList[$key]['Sys_id'] = $value['sys_id'];
- // $PrintList[$key]['Uniqid'] = $PrintLastId + $key + 1;
- // $PrintList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
- // $PrintList[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
- // array_push($arr,[$value['yj_yjno'],$v['行号']]);
- // }
- // $sql = \db('工单_基本资料')
- // ->where('Gd_gdbh',$param['workorder'])
- // ->where('Gd_cpdh',$value['yj_yjdh'])
- // ->fetchSql(true)
- // ->update(['行号'=>$value['yj_yjno']]);
- // \db()->query($sql);
- // }
- // unset($PrintList[$key]['mod_rq'],$PrintList[$key]['sys_rq'],$PrintList[$key]['sys_id'],$PrintList[$key]['KgToPages'],$PrintList[$key]['yj_tll'],$PrintList[$key]['yj_yjdh'],$PrintList[$key]['yj_yjno'],$PrintList[$key]['UniqId']);
- // }
- // //引用工艺资料
- // $processWhere = [
- // 'Gy0_方案' => $param['option'],
- // 'Gy0_cpdh' => $param['productCode']
- // ];
- // $ProcessList = \db('产品_工艺资料')
- // ->where($processWhere)
- // ->where($proWhere)
- // ->order('Gy0_yjno,Gy0_gxh')
- // ->select();
- // if (empty($ProcessList)){
- // $this->error('未找到产品工艺资料');
- // }
- // $ProcesslastId = \db('工单_工艺资料')->order('UniqId desc')->value('rtrim(UniqId)');
- // foreach ($ProcessList as $key=>$value){
- // if (empty(trim($value['Gy0_shdh']))){
- // $rate['rate0'] = 0;
- // $rate['rate1'] = 0;
- // }else{
- // $rate = \db('dic_lzsh')->where('sys_bh',$value['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
- // if (empty($rate)){
- // $this->error('该产品印件号'.$value['Gy0_yjno'].'工序号为'.$value['gy0_gxmc'].'的损耗代号错误,请调整之后再引用');
- // }
- // }
- // //设置默认机台
- // $machineList = \db('设备_基本资料')
- // ->where('生产工序','like','%'.$value['gy0_gxmc'].'%')
- // ->order('设备编号')
- // ->value('设备编号');
- // $ProcessList[$key]['Gy0_sbbh'] = '';
- // if (!empty($machineList)){
- // $ProcessList[$key]['Gy0_sbbh'] = $machineList;
- // }
- // $ProcessList[$key]['Gy0_yjno'] = $value['Gy0_yjno'];
- // $ProcessList[$key]['Gy0_gdbh'] = $param['workorder'];
- // $ProcessList[$key]['Gy0_gxmc'] = $value['gy0_gxmc'];
- // $ProcessList[$key]['Gy0_SITE'] = $value['Gy0_site'];
- // $ProcessList[$key]['Gy0_shdh'] = $value['Gy0_shdh'];
- // $ProcessList[$key]['Gy0_Rate0'] = $rate['rate0'];
- // $ProcessList[$key]['Gy0_Rate1'] = $rate['rate1'];
- // $ProcessList[$key]['Gy0_ks'] = $value['Gy0_Ks'];
- // $ProcessList[$key]['Gy0_ms'] = $value['Gy0_Ms'];
- // $ProcessList[$key]['Gy0_oil'] = $value['Gy0_Oil'];
- // $ProcessList[$key]['Gy0_计划接货数'] = 0;
- // $ProcessList[$key]['Gy0_计划损耗'] = 0;
- // $ProcessList[$key]['无形损承担比例'] = 0;
- // $ProcessList[$key]['超节损承担比例'] = 1;
- // $ProcessList[$key]['超节损核算单价'] = 0;
- // $ProcessList[$key]['Gy0_sj1'] = '1900-01-01 00:00:00';
- // $ProcessList[$key]['Gy0_sj2'] = '1900-01-01 00:00:00';
- // $ProcessList[$key]['UniqId'] = $ProcesslastId + $key + 1;
- // $ProcessList[$key]['PD_WG'] = '1900-01-01 00:00:00';
- // $ProcessList[$key]['Sys_rq'] = date('Y-m-d H:i:s', time());
- // unset($ProcessList[$key]['Gy0_Oil'],$ProcessList[$key]['Gy0_Ms'],$ProcessList[$key]['Gy0_Ks'],$ProcessList[$key]['UniqID'],$ProcessList[$key]['Gy0_cpdh'],$ProcessList[$key]['gy0_gxmc'],$ProcessList[$key]['Gy0_site']);
- // }
- // //插入数据
- // \db()->startTrans();
- // try {
- // \db('工单_工艺资料')->where('Gy0_gdbh',$param['workorder'])->delete();
- // $processSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($ProcessList);
- // \db()->query($processSql);
- // \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->delete();
- // $printSql = \db('工单_印件资料')->fetchSql(true)->insertAll($PrintList);
- // \db()->query($printSql);
- // \db()->commit();
- // }catch (\Exception $e){
- // \db()->rollback();
- // }
- // //计算工序计划生产数量
- // if ($number !== null){
- // $list = \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->field('yj_Yjno,yj_平张投料')->select();
- // foreach ($list as $value){
- // if ((int)$value['yj_平张投料'] >0){
- // $this->PlannedProcessYield($param['workorder'],$value['yj_Yjno'],0,$value['yj_平张投料']);
- // }
- // }
- // }
- // $this->success('成功');
- // }
- /**
- * 引用产品印件、工艺资料->信息获取
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function ProductCopeDetail()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param['workorder'])){
- // $this->error('参数错误');
- // }
- // $list = \db('工单_基本资料')
- // ->alias('a')
- // ->field([
- // 'rtrim(a.Gd_gdbh)' => '工单编号',
- // 'rtrim(b.客户编号)' => '客户编号',
- // 'rtrim(b.客户名称)' => '客户名称',
- // 'rtrim(b.产品编号)' => '产品编号',
- // 'rtrim(b.产品名称)' => '产品名称'
- // ])
- // ->join('产品_基本资料 b','a.成品代号 = b.产品编号')
- // ->where('a.Gd_gdbh',$param['workorder'])
- // ->find();
- // if (empty($list)){
- // $this->error('未找到工单信息');
- // }
- // $option = \db('产品_工艺资料')
- // ->field('rtrim(Gy0_方案) as 方案')
- // ->where('Gy0_cpdh',$list['产品编号'])
- // ->group('Gy0_方案')
- // ->select();
- // $list['方案'] = $option;
- // $this->success('成功',$list);
- // }
- /**
- * 工艺资料计划产量重新分配
- * @param string $workOrder 工单
- * @param int $yjno 印件号
- * @param int $gxh 工序号
- * @param int $feed 平张投料
- * @return bool
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- // public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
- // {
- // if ($gxh === 0){
- // $where = [
- // 'Gy0_gdbh'=>$workOrder,
- // 'Gy0_yjno'=>$yjno,
- // ];
- // }else{
- // $where = [
- // 'Gy0_gdbh'=>$workOrder,
- // 'Gy0_yjno'=>$yjno,
- // 'Gy0_gxh'=>['>=',$gxh]
- // ];
- // }
- // //获取工艺资料
- // $processList = \db('工单_工艺资料')
- // ->where($where)
- // ->field('Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
- // ->order('Gy0_gxh')
- // ->select();
- // if (empty($processList)){
- // $this->success('未找到该工单工序资料');
- // }
- // //计算损耗定额和计划产量
- // $production = [];
- // $i = 0;
- // foreach ($processList as $key=>$value){
- // if ($key === 0){
- // array_push($production,$feed);
- // }
- // $wastage = 0;
- // if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
- // $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
- // }
- //
- // if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
- // $wastage = round($wastage * $value['Gy0_ms']);
- // }
- // if ((int)$value['Gy0_ls'] === 1 && $key>=1){
- // $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
- // }else{
- // $number = $production[$key];
- // }
- // if ($key>=1 && (int)$processList[$key-1]['Gy0_ls'] === 1 && (int)$value['Gy0_ls'] > 1){
- // $number = $number/(int)$value['Gy0_ls'];
- // }
- // array_push($production,ceil($number-$wastage));
- // $processSql = \db('工单_工艺资料')
- // ->where('UniqId',$value['UniqId'])
- // ->fetchSql(true)
- // ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
- // $res = \db()->query($processSql);
- // if ($res === false){
- // $i++;
- // }
- // }
- // if ($i===0){
- // return true;
- // }else{
- // return false;
- // }
- // }
- /**
- * 工单资料删除
- * @return void
- * @throws \think\exception\PDOException
- */
- // public function WorkOrderDel()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (isset($param['UniqId']) === false){
- // $this->error('参数错误');
- // }
- // $WorkOrderId = explode(',',$param['UniqId']);
- // $i = 0;
- // foreach ($WorkOrderId as $key=>$value){
- // //获取工单编号
- // $workorder = \db('工单_基本资料')
- // ->where('Uniqid',$value)
- // ->value('rtrim(Gd_gdbh)');
- // //删除工单资料、工艺资料、印件资料
- // \db()->startTrans();
- // try {
- // \db('工单_基本资料')->where('Gd_gdbh',$workorder)->delete();
- // if (!empty(\db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->find())){
- // \db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->delete();
- // }
- // if (!empty(\db('工单_印件资料')->where('Yj_Gdbh',$workorder)->find())){
- // \db('工单_印件资料')->where('Yj_Gdbh',$workorder)->delete();
- // }
- // if (!empty(\db('工单_bom资料')->where('BOM_工单编号',$workorder)->find())){
- // \db('工单_bom资料')->where('BOM_工单编号',$workorder)->delete();
- // }
- // \db()->commit();
- // }catch (\Exception $e){
- // \db()->rollback();
- // $i++;
- // }
- // }
- // if ($i === 0){
- // $this->success('删除成功');
- // }else{
- // $this->error('删除失败');
- // }
- // }
- /**
- * 修正核算参数-》工单产品信息获取
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function ProductNameData()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $workOrder = input('workOrder');
- // if (empty($workOrder)){
- // $this->error('参数错误');
- // }
- // $orderList = \db('工单_基本资料')
- // ->field('rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称')
- // ->where('Gd_gdbh',$workOrder)
- // ->find();
- // $this->success('成功',$orderList);
- // }
- /**
- * 获取联数
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- // public function getCouplet()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param['gdbh']) || empty($param['yjno'])){
- // $this->error('参数错误');
- // }
- // $list = \db('工单_印件资料')
- // ->where('Yj_gdbh',$param['gdbh'])
- // ->where('yj_Yjno',$param['yjno'])
- // ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
- // ->find();
- // $process = \db('工单_工艺资料')
- // ->where('Gy0_gdbh',$param['gdbh'])
- // ->where('Gy0_yjno',$param['yjno'])
- // ->order('Gy0_gxh desc')
- // ->value('Gy0_gxh');
- // $list['工序号'] = $process + 1;
- // $this->success('成功',$list);
- // }
- public function orderPrint()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param['order'])){
- $this->error('参数错误');
- }
- $where['Mod_rq'] = null;
- $list = \db('工单_基本资料')
- ->where('订单编号',$param['order'])
- ->where($where)
- ->field('订单编号,生产款号,要求,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,img')
- ->find();
- $xhdata = \db('工单_印件资料')
- ->where('订单编号',$param['order'])
- ->where('船样',0)
- ->where($where)
- ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,款号')
- ->select();
- $arr = [];
- foreach ($xhdata as $key => $value){
- for($i=1;$i<=10;$i++){
- if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
- array_push($arr,$value['cm'.$i]);
- }
- }
- }
- $arr = array_unique($arr);
- $processlist = \db('工单_印件资料')
- ->where('订单编号',$param['order'])
- ->where($where)
- // ->where('船样',0)
- ->field('子订单编号,颜色,款号,zdtotal,cm1,cm2,cm3,cm4,cm5,cm6,
- cm7,cm8,cm9,cm10,cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
- ->select();
- foreach ($processlist as $key=>$value){
- for($i=1;$i<=10;$i++){
- if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
- $processlist[$key][$value['cm'.$i]] = $value['cmsl'.$i];
- }
- unset($processlist[$key]['cm'.$i],$processlist[$key]['cmsl'.$i]);
- }
- }
- $data['order'] = $list;
- sort($arr);
- $data['xhdata'] = $arr;
- $data['process'] = $processlist;
- $this->success('成功',$data);
- }
- /**
- * 订单编号自动获取
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getWorkOrder()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $time =substr( date('Ym',time()),2);
- $lastOrder = \db('工单_基本资料')
- ->where('订单编号','like','%'.$time.'%')
- ->order('Uniqid desc')
- ->find();
- if (empty($lastOrder)){
- $newNumber = 1;
- }else{
- $lastNumber = substr($lastOrder['订单编号'],6);
- $newNumber = (int)$lastNumber + 1;
- }
- if ($newNumber<10){
- $newOrder = 'DC'.$time.'00'.$newNumber;
- }elseif ($newNumber>=10 && $newNumber<100){
- $newOrder = 'DC'.$time.'0'.$newNumber;
- }else{
- $newOrder = 'DC'.$time.$newNumber;
- }
- $this->success('成功',$newOrder);
- }
- /**
- * 获取子订单编号
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getSuborder()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- if($param['cy'] == '否'){
- $data = \db('工单_印件资料')
- ->where('订单编号', $param['order'])
- ->where('船样', '=', 0)
- ->order('子订单编号 desc')
- ->find();
- if (empty($data)) {
- $order = $param['order'] . '-01';
- } else {
- $num = (int)substr($data['子订单编号'], 10) + 1;
- if ($num < 10) {
- $order = $param['order'] . '-0' . $num;
- } else {
- $order = $param['order'] . '-' . $num;
- }
- }
- $cm_data = [
- 'cm1' => $data['cm1'] ?? '',
- 'cm2' => $data['cm2'] ?? '',
- 'cm3' => $data['cm3'] ?? '',
- 'cm4' => $data['cm4'] ?? '',
- 'cm5' => $data['cm5'] ?? '',
- 'cm6' => $data['cm6'] ?? '',
- 'cm7' => $data['cm7'] ?? '',
- 'cm8' => $data['cm8'] ?? '',
- 'cm9' => $data['cm9'] ?? '',
- 'cm10' => $data['cm10'] ?? ''
- ];
- $result = [
- 'order' => $order,
- 'cm' => $cm_data
- ];
- $this->success('成功', $result);
- }else if ($param['cy'] == '是') {
- // 获取工单信息
- $data = \db('工单_印件资料')
- ->where('订单编号', $param['order'])
- ->where('船样', '=', 1)
- ->order('子订单编号 asc')
- ->find();
- if(empty($data)){
- $order = $param['order'].'-99';
- }else{
- // 提取子订单编号中的数字部分
- $subOrder = $data['子订单编号']; // 例如 "DC2410006-99"
- // 使用正则匹配找到 "-数字" 的部分,并减去 1
- if (preg_match('/-(\d+)$/', $subOrder, $matches)) {
- $numberPart = (int)$matches[1]; // 提取到的数字部分,转换为整数
- $newNumber = $numberPart - 1; // 减 1
- // 将新的数字拼接回订单编号
- $order = preg_replace('/-\d+$/', '-' . $newNumber, $subOrder);
- } else {
- // 如果没有找到子订单中的数字部分,保持原订单编号不变
- $order = $subOrder;
- }
- }
- $this->success('成功', $order);
- }
- // $data = \db('工单_印件资料')
- // ->where('订单编号',$param['order'])
- // ->where('船样',0)
- // ->order('子订单编号 desc')
- // ->find();
- // if(empty($data)){
- // $order = $param['order'].'-01';
- // }else{
- // $num = (int)substr($data['子订单编号'],10) + 1;
- // if ($num<10){
- // $order = $param['order'].'-0'.$num;
- // }else{
- // $order = $param['order'].'-'.$num;
- // }
- // }
- // $this->success('成功',$order);
- }
- /**
- * 订单资料修改
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function WorkOrderEdit()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $id = $param['id'];
- unset($param['id']);
- $sql = \db('工单_基本资料')
- ->where('Uniqid',$id)
- ->fetchSql(true)
- ->update($param);
- $res = \db()->query($sql);
- if ($res === false){
- $this->error('失败');
- }else{
- $this->success('成功');
- }
- }
- /**
- * 颜色资料修改
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function PrintDataEdit()
- {
- if(Request::instance()->post() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $id = $param['id'];
- unset($param['id']);
- $param['updatatime'] = date('Y-m-d H:i:s');
- $sql = \db('工单_印件资料')
- ->where('Uniqid',$id)
- ->fetchSql(true)
- ->update($param);
- $res = \db()->query($sql);
- if ($res === false){
- $this->error('修改失败');
- }else{
- $this->success('修改成功');
- }
- }
- /**
- * 图片上传
- * @return void
- */
- // public function ImgUpload(){
- // $file = request()->file('image');
- // if($file){
- // $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
- // if($info){
- // $fileName = $info->getSaveName();
- // $this->success('成功','public' . DS . 'uploads'. DS . $fileName);
- // }else{
- // $res = $file->getError();
- // $this->error('失败',$res);
- // }
- // }
- // }
- public function ImgUpload(){
- $file = request()->file('image');
- if($file){
- $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
- if($info){
- $fileName = $info->getSaveName();
- $imageUrl = '/uploads/' . str_replace('\\', '/', $fileName);
- return json(['code' => 0, 'msg' => '成功', 'data' => ['url' => $imageUrl]]);
- }else{
- $res = $file->getError();
- return json(['code' => 1, 'msg' => '失败', 'data' => $res]);
- }
- }
- return json(['code' => 1, 'msg' => '没有文件上传', 'data' => null]);
- }
- /**
- * 工单技术附件
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function OrderAttachments()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = \db('工单_相关附件')
- ->where('关联编号',$param['order'])
- ->where('附件备注',$param['desc'])
- ->whereNull('Mod_rq')
- ->select();
- $this->success('成功',$list);
- }
- }
|