| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561 |
- <?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_客户供应商')
- // ->order('编号 asc')
- // ->column('rtrim(编号) as 编号');
- // $this->success('成功', $data);
- $where['j.Mod_rq'] = null;
- $allCustomers = \db('erp_客户供应商')->alias('e')
- ->field('e.编号 as 客户编号')
- ->select();
- $customerData = [];
- foreach ($allCustomers as $customer) {
- $customerID = $customer['客户编号'];
- $customerData[$customerID] = ['计划中' => 0, '生产中' => 0];
- }
- $data = \db('erp_客户供应商')->alias('e')
- ->join('工单_基本资料 j', 'e.编号 = j.客户编号', 'LEFT')
- ->field('e.编号 as 客户编号, j.订单编号, j.gd_statu')
- ->where($where)
- ->select();
- foreach ($data as $row) {
- $customerID = $row['客户编号'];
- $status = $row['gd_statu'];
- if ($status == '1-计划中') {
- $customerData[$customerID]['计划中']++;
- } elseif ($status == '2-生产中') {
- $customerData[$customerID]['生产中']++;
- }
- }
- ksort($customerData);
- $output = [];
- foreach ($customerData as $customerID => $statusCounts) {
- $statusString = [];
- if ($statusCounts['计划中'] > 0) {
- $statusString[] = "计划中:{$statusCounts['计划中']}";
- }
- if ($statusCounts['生产中'] > 0) {
- $statusString[] = "生产中:{$statusCounts['生产中']}";
- }
- $output[] = "{$customerID}【" . implode(' ', $statusString) . "】";
- }
- $this->success('成功', $output);
- }
- /**
- * 工单基本资料列表
- * @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 . '%'];
- }
- $where['Mod_rq'] = null;
- $list = \db('工单_基本资料')
- ->where($where)
- ->order('订单编号 desc, Gd_statu desc, Sys_rq desc')
- ->limit(($page - 1) * $limit, $limit)
- ->select();
- // 提取所有订单编号
- $orderIds = array_column($list, '订单编号');
- // 查询所有在“工单_相关附件”表中存在的订单编号
- $relatedOrders = \db('工单_相关附件')
- ->whereIn('关联编号', $orderIds)
- ->whereIn('附件备注', '技术附件')
- ->column('关联编号');
- // 遍历数据,判断每个订单编号是否在相关附件表中
- foreach ($list as &$value) {
- if (in_array($value['订单编号'], $relatedOrders)) {
- $value['status'] = ''; // 有相关附件,status为空
- } else {
- $value['status'] = '*'; // 没有相关附件,标记为新订单
- }
- }
- $this->success('成功', ['data' => $list, 'total' => count($list)]);
- }
- /**
- * 编辑页面展示
- * @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);
- // }
- /**
- * 月度客户订单汇总
- */
- public function ProductInformation(){
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $where['j.gd_statu'] = '2-生产中';
- $where['j.Mod_rq'] = null;
- $data = \db('工单_基本资料')->alias('j')
- ->field('j.客户编号, REPLACE(DATE_FORMAT(j.Sys_rq, "%Y-%m"), "-", "") as 年月, GROUP_CONCAT(DISTINCT j.订单编号) as 订单编号')
- ->where($where)
- ->order('j.客户编号 asc')
- ->group('j.客户编号, 年月')
- ->select();
- $result = [];
- foreach ($data as $item) {
- $orderlist = count(explode(',', $item['订单编号']));
- $result[$item['年月']][] = [$item['客户编号'] . '【生产中:' . $orderlist . '】',
- ];
- }
- $this->success('请求成功', ['data' => $result]);
- }
- /**
- * 引用产品资料->复制产品工艺资料
- * @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)
- */
- 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
- */
- 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['颜色'],
- '颜色备注' => $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 = [];
- // 收集cm1到cm10的非空非null值
- 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,updatatime as 更新时间,颜色备注,color_id,cm7,cm8,cm9,cm10,cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
- ->select();
- // 遍历列表并处理cm和cmsl字段
- foreach ($list as $key => $value) {
- for ($i = 1; $i <= 10; $i++) {
- if ($value['cm' . $i] !== '') {
- // 如果 cmsl 的值为 0,则设置为空字符串
- $list[$key][$value['cm' . $i]] = ($value['cmsl' . $i] === 0) ? '' : $value['cmsl' . $i];
- }
- // 删除原有的 cm 和 cmsl 字段
- unset($list[$key]['cm' . $i], $list[$key]['cmsl' . $i]);
- }
- }
- // 自定义型号排序
- $customOrder = array('XS','S', 'M', 'L', 'XL','XXL', '2XL', '3XL', '4XL');
- usort($arr, function ($a, $b) use ($customOrder) {
- $posA = array_search($a, $customOrder);
- $posB = array_search($b, $customOrder);
- return $posA - $posB;
- });
- // 返回结果
- $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('删除失败');
- }
- }
- /**
- * 月度车间报工汇总->报工删除记录
- */
- public function ProcessDetailDel()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- // $where['mod_rq'] = ['neq', ''];
- // $list = \db('设备_产量计酬')->alias('c')
- // ->field('c.订单编号,j.客户编号,c.mod_rq,c.delsys_id,c.款号,j.款式,,,,,,,,')
- // ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
- // ->where($where)
- // ->order('c.mod_rq desc')
- // ->select();
- // echo "<pre>";
- // print_r($list);
- // echo "<pre>";
- $where['a.mod_rq'] = ['neq', ''];
- $list = \db('设备_产量计酬')->alias('a')
- ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
- ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
- ->field('
- b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数,b.颜色备注,
- a.数量, a.sys_rq as 上报时间,a.UniqId,a.mod_rq,a.delsys_id,a.sczl_bh,
- j.客户编号,j.生产款号,j.款式
- ')
- ->where($where)
- ->order('a.mod_rq desc')
- ->group('a.UniqId')
- ->select();
- // 提取所有的尺码,并去重
- $sizeList = array_values(array_unique(array_column($list, '尺码')));
- // 动态将尺码的数量添加到每个订单中,并替换已完成字段
- foreach ($list as &$item) {
- $size = $item['尺码'];
- $item[$size] = $item['数量']; // 动态添加尺码字段,值为数量
- // unset($item['数量']); // 移除原来的已完成字段
- }
- $data['total'] = count($list);
- $data['table'] = $list;
- $this->success('成功',$data);
- }
- /**
- * 工艺资料添加->工序损耗代码
- */
- // 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();
- // 检查附件备注是否为 '技术附件'
- if (isset($req['附件备注']) && $req['附件备注'] === '技术附件') {
- // 查询工单状态
- $order = \db('工单_基本资料')->where('订单编号', $req['关联编号'])->find();
- if ($order) {
- // 如果工单状态不是 '2-生产中',则更新工单状态
- if ($order['gd_statu'] !== '2-生产中') {
- // 更新工单状态为 '2-生产中'
- \db('工单_基本资料')->where('订单编号', $req['关联编号'])->update(['gd_statu' => '2-生产中']);
- }
- } else {
- // 工单不存在时返回错误信息
- return $this->error('订单不存在');
- }
- }
- $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('参数错误');}
- //订单信息
- $list = \db('工单_基本资料')
- ->where('订单编号',$param['order'])
- ->where('Mod_rq',null)
- ->field('订单编号,img,生产款号,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,要求')
- ->find();
- //表格表头
- $xhdata = \db('工单_印件资料')
- ->where('订单编号',$param['order'])
- ->where('Mod_rq',null)
- ->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);
- $where['Mod_rq'] = null;
- $porlis = \db('工单_印件资料')
- ->where('订单编号',$param['order'])
- ->where('船样',0)
- ->where($where)
- ->field('子订单编号')
- ->select();
- $subOrder = $porlis[0]['子订单编号'];
- // 找到子订单编号中的 '-' 位置
- $dashPos = strpos($subOrder, '-');
- if ($dashPos !== false) {
- // 提取 '-' 后面的部分
- $afterDash = substr($subOrder, $dashPos + 1);
- // 判断长度是否等于2或等于4
- if (strlen($afterDash) == 2) {
- // // 查询船样为0的数据
- // $processlist = \db('工单_印件资料')
- // ->where('订单编号', $param['order'])
- // ->where($where)
- // ->where('船样', 0)
- // ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
- // 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) {
- // // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
- // for ($i = 1; $i <= 10; $i++) {
- // if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
- // $processlist[$key][$value['cm' . $i]] = $value['cmsl' . $i];
- // }
- // // 移除���始的 cm 和 cmsl 字段
- // unset($processlist[$key]['cm' . $i], $processlist[$key]['cmsl' . $i]);
- // }
- // // 添加条码字段,值为子订单编号
- // $processlist[$key]['条码'] = $value['子订单编号'];
- // }
- //
- //// 用于存储合并后的数据
- // $mergedData = [];
- //
- //// 按颜色备注进行合并
- // foreach ($processlist as $item) {
- // $key = $item['颜色备注'];
- //
- // if (!isset($mergedData[$key])) {
- // $mergedData[$key] = $item;
- // } else {
- // // 合并尺码对应的数量
- // foreach ($item as $size => $quantity) {
- // if (is_numeric($size)) {
- // if (!isset($mergedData[$key][$size])) {
- // $mergedData[$key][$size] = 0;
- // }
- // $mergedData[$key][$size] += $quantity;
- // }
- // }
- // // 合并 zdtotal
- // $mergedData[$key]['zdtotal'] += $item['zdtotal'];
- // }
- // }
- //
- //// 将合并后的数据转换为索引数组
- // $processlist = array_values($mergedData);
- //
- //// 如果有 0 的值,清空为 ''
- // foreach ($processlist as &$row) {
- // foreach ($row as $key => $value) {
- // if ($value === 0) {
- // $row[$key] = '';
- // }
- // }
- // }
- //
- //// 对数组进行排序
- // sort($processlist);
- //
- //// 自定义排序顺序
- // $customOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL'];
- // usort($processlist, function($a, $b) use ($customOrder) {
- // $posA = array_search($a, $customOrder);
- // $posB = array_search($b, $customOrder);
- // return $posA - $posB;
- // });
- //
- //// 查询船样为1的数据
- // $chuanyang = \db('工单_印件资料')
- // ->where('订单编号', $param['order'])
- // ->where($where)
- // ->where('船样', 1)
- // ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
- // cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
- // cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
- // ->select();
- //
- // foreach ($chuanyang as $key => $value) {
- // // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
- // for ($i = 1; $i <= 10; $i++) {
- // if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
- // $chuanyang[$key][$value['cm' . $i]] = $value['cmsl' . $i];
- // }
- // // 移除原始的 cm 和 cmsl 字段
- // unset($chuanyang[$key]['cm' . $i], $chuanyang[$key]['cmsl' . $i]);
- // }
- // // 添加条码字段,值为子订单编号
- // $chuanyang[$key]['条码'] = $value['子订单编号'];
- // }
- //
- //// 将船样为1的数据添加到船样为0的数据后面
- // $finalList = array_merge($processlist, $chuanyang);
- //
- // $data['process'] = $finalList;
- // 查询船样为0的数据
- $processlist = \db('工单_印件资料')
- ->where('订单编号', $param['order'])
- ->where($where)
- ->where('船样', 0)
- ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
- 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) {
- // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
- for ($i = 1; $i <= 10; $i++) {
- if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
- $processlist[$key][$value['cm' . $i]] = $value['cmsl' . $i];
- }
- // 移除原始的 cm 和 cmsl 字段
- unset($processlist[$key]['cm' . $i], $processlist[$key]['cmsl' . $i]);
- }
- }
- // 用于存储合并后的数据
- $mergedData = [];
- // 按颜色备注进行合并
- foreach ($processlist as $item) {
- $key = $item['颜色备注'];
- if (!isset($mergedData[$key])) {
- $mergedData[$key] = $item;
- // 添加条码字段,值为子订单编号
- $mergedData[$key]['条码'] = $item['子订单编号'];
- } else {
- // 合并尺码对应的数量
- foreach ($item as $size => $quantity) {
- if (is_numeric($size)) {
- if (!isset($mergedData[$key][$size])) {
- $mergedData[$key][$size] = 0;
- }
- $mergedData[$key][$size] += $quantity;
- }
- }
- // 合并 zdtotal
- $mergedData[$key]['zdtotal'] += $item['zdtotal'];
- }
- }
- // 查询船样为1的数据
- $chuanyang = \db('工单_印件资料')
- ->where('订单编号', $param['order'])
- ->where($where)
- ->where('船样', 1)
- ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
- cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
- cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
- ->select();
- foreach ($chuanyang as $key => $value) {
- // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
- for ($i = 1; $i <= 10; $i++) {
- if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
- $chuanyang[$key][$value['cm' . $i]] = $value['cmsl' . $i];
- }
- // 移除原始的 cm 和 cmsl 字段
- unset($chuanyang[$key]['cm' . $i], $chuanyang[$key]['cmsl' . $i]);
- }
- // 添加条码字段,值为子订单编号
- $chuanyang[$key]['条码'] = $value['子订单编号'];
- }
- // 将合并后的数据插入到相应颜色备注的原始数据尾部
- $finalList = [];
- $groupedData = [];
- // 将原始数据按颜色备注分组
- foreach ($processlist as $item) {
- $key = $item['颜色备注'];
- if (!isset($groupedData[$key])) {
- $groupedData[$key] = [];
- }
- $groupedData[$key][] = $item;
- }
- // 将合并后的数据插入到对应的颜色备注组的尾部
- foreach ($groupedData as $key => $items) {
- $finalList = array_merge($finalList, $items); // 先添加原始数据
- if (isset($mergedData[$key])) {
- $finalList[] = $mergedData[$key]; // 在组的尾部添加合并数据
- }
- }
- // 将船样为1的数据添加到最终列表中
- $finalList = array_merge($finalList, $chuanyang);
- // 最终数据结构
- $data['process'] = $finalList;
- $data['order'] = $list;
- $data['xhdata'] = $arr;
- $this->success('成功',$data);
- } elseif (strlen($afterDash) == 4) {
- // 获取印件资料
- $processlist = \db('工单_印件资料')
- ->where('订单编号', $param['order'])
- ->where($where)
- ->where('船样', 0)
- ->field('子订单编号, 颜色, 款号, zdtotal, 颜色备注, color_id, 船样,
- cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
- cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
- ->select();
- // 保存格式化后的数据
- $formattedData = [];
- // 遍历数据进行尺码转换并添加到输出数组
- foreach ($processlist as $item) {
- for ($i = 1; $i <= 10; $i++) {
- if (!empty($item['cm' . $i])) {
- $item[$item['cm' . $i]] = $item['cmsl' . $i];
- }
- unset($item['cm' . $i], $item['cmsl' . $i]);
- }
- $formattedData[] = $item;
- }
- // 用于存储每个 color_id 和颜色备注的合并数据
- $mergedData = [];
- // 进行合并
- foreach ($formattedData as $item) {
- $key = $item['color_id'] . '|' . $item['颜色备注'];
- if (!isset($mergedData[$key])) {
- $mergedData[$key] = $item;
- $mergedData[$key]['条码'] = $item['子订单编号']; // 初始化条码
- } else {
- // 合并 zdtotal 和尺码数量
- $mergedData[$key]['zdtotal'] += $item['zdtotal'];
- foreach (['36', '38', '40', '42', '44', '46', '48'] as $size) {
- if (isset($item[$size])) {
- $mergedData[$key][$size] = ($mergedData[$key][$size] ?? 0) + $item[$size];
- }
- }
- // 优先选择以 "00" 结尾的条码
- if (substr($item['子订单编号'], -2) == '00') {
- $mergedData[$key]['条码'] = $item['子订单编号'];
- }
- }
- }
- // 将合并后的数据添加到原始数据的末尾,并排序
- $finalOutput = $formattedData;
- // 按 color_id 和 颜色备注 分组,并在每组末尾添加合并后的条码数据
- foreach ($mergedData as $key => $mergeItem) {
- $mergeItem['合并标记'] = true; // 用于标记这是合并后的数据
- $finalOutput[] = $mergeItem;
- }
- // 对最终数组进行排序
- usort($finalOutput, function($a, $b) {
- // 先按 color_id 排序
- $compare = strcmp($a['color_id'], $b['color_id']);
- if ($compare === 0) {
- // 在 color_id 相同的情况下,再按 颜色备注 排序
- $compare = strcmp($a['颜色备注'], $b['颜色备注']);
- if ($compare === 0) {
- // 在 颜色备注相同的情况下,按 子订单编号 排序
- // 如果一项是合并标记的条码数据,另一项不是,则合并标记的条码数据排在后面
- if (isset($a['合并标记']) && !isset($b['合并标记'])) {
- return 1;
- } elseif (!isset($a['合并标记']) && isset($b['合并标记'])) {
- return -1;
- }
- return strcmp($a['子订单编号'], $b['子订单编号']);
- }
- return $compare;
- }
- return $compare;
- });
- // 查询仅获取船样为 1 的数据
- $chuanyang = \db('工单_印件资料')
- ->where('订单编号', $param['order'])
- ->where($where)
- ->where('船样', 1)
- ->field('子订单编号, 颜色, 款号, zdtotal, 颜色备注, color_id, 船样,
- cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
- cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
- ->select();
- $chuanyangvval = [];
- // 遍历船样为 1 的数据,进行尺码转换
- foreach ($chuanyang as $item) {
- for ($i = 1; $i <= 10; $i++) {
- if (!empty($item['cm' . $i])) {
- $item[$item['cm' . $i]] = $item['cmsl' . $i];
- }
- unset($item['cm' . $i], $item['cmsl' . $i]);
- }
- $item['条码'] = $item['子订单编号'];
- $chuanyangvval[] = $item;
- }
- // 合并船样和非船样的数据并去重
- $final = array_map("unserialize", array_unique(array_map("serialize", array_merge($finalOutput, $chuanyangvval))));
- // 最后清除带有条码的数据中的子订单编号和颜色信息
- foreach ($final as &$item) {
- if (isset($item['条码']) && $item['船样'] == 0) {
- $item['子订单编号'] = '';
- $item['颜色'] = '';
- $item['款号'] = '';
- unset($item['子订单编号'], $item['颜色']);
- }
- }
- $data['process'] = $final;
- $data['order'] = $list;
- $data['xhdata'] = $arr;
- $this->success('成功', $data);
- } else {
- echo "子订单编号 - 后不是2位也不是4位:$afterDash";
- }
- } else {
- echo "子订单编号中没有找到'-'";
- }
- // $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, 颜色备注, color_id,
- // cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
- // cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
- // ->select();
- // $mergedList = [];
- // $summaryList = []; // 用于存储汇总数据
- // foreach ($processlist as $item) {
- // $colorId = $item['color_id'];
- // $subOrderSuffix = substr($item['子订单编号'], -2);
- //
- // // 判断是否为汇总项(子订单编号后两位为 "00")
- // if ($subOrderSuffix === '00') {
- // // 初始化汇总数据
- // $summaryList[$colorId] = [
- // '子订单编号' => $item['子订单编号'],
- // '条码' => $item['子订单编号'],
- // '颜色' => $item['颜色'],
- // '款号' => $item['款号'],
- // 'zdtotal' => 0, // 累计总量
- // '颜色备注' => $item['颜色备注'],
- // 'color_id' => $colorId,
- // 'cm1' => $item['cm1'],
- // 'cm2' => $item['cm2'],
- // 'cm3' => $item['cm3'],
- // 'cm4' => $item['cm4'],
- // 'cm5' => $item['cm5'],
- // 'cm6' => $item['cm6'],
- // 'cm7' => $item['cm7'],
- // 'cm8' => $item['cm8'],
- // 'cm9' => $item['cm9'],
- // 'cm10' => $item['cm10'],
- // 'cmsl1' => 0,
- // 'cmsl2' => 0,
- // 'cmsl3' => 0,
- // 'cmsl4' => 0,
- // 'cmsl5' => 0,
- // 'cmsl6' => 0,
- // 'cmsl7' => 0,
- // 'cmsl8' => 0,
- // 'cmsl9' => 0,
- // 'cmsl10' => 0,
- // ];
- // }
- //
- // // 如果该 color_id 已经存在于汇总数组中,累加数量
- // if (isset($summaryList[$colorId])) {
- // $summaryList[$colorId]['cmsl1'] += $item['cmsl1'];
- // $summaryList[$colorId]['cmsl2'] += $item['cmsl2'];
- // $summaryList[$colorId]['cmsl3'] += $item['cmsl3'];
- // $summaryList[$colorId]['cmsl4'] += $item['cmsl4'];
- // $summaryList[$colorId]['cmsl5'] += $item['cmsl5'];
- // $summaryList[$colorId]['cmsl6'] += $item['cmsl6'];
- // $summaryList[$colorId]['cmsl7'] += $item['cmsl7'];
- // $summaryList[$colorId]['cmsl8'] += $item['cmsl8'];
- // $summaryList[$colorId]['cmsl9'] += $item['cmsl9'];
- // $summaryList[$colorId]['cmsl10'] += $item['cmsl10'];
- // $summaryList[$colorId]['zdtotal'] += $item['zdtotal'];
- // }
- //
- // // 将原数据保留到结果数组中
- // $mergedList[] = $item;
- // }
- //
- //// 将汇总数据追加到结果数组中
- // foreach ($summaryList as $summary) {
- // $mergedList[] = $summary;
- // }
- // foreach ($mergedList as $key=>$value){
- // for($i=1;$i<=10;$i++){
- // if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
- // $mergedList[$key][$value['cm'.$i]] = $value['cmsl'.$i];
- // }
- // unset($mergedList[$key]['cm'.$i],$mergedList[$key]['cmsl'.$i]);
- // }
- // }
- // // 如果有0清空为 ''
- // foreach ($mergedList as &$row) {
- // foreach ($row as $key => $value) {
- // if ($value === 0) {
- // $row[$key] = '';
- // }
- // }
- // }
- //
- // $data['order'] = $list;
- // sort($arr);
- // $data['xhdata'] = $arr;
- // $data['process'] = $mergedList;
- //
- // $this->success('成功', $data);
- }
- // public function orderPrint()
- // {
- // if ($this->request->isGet() === false){
- // $this->error('请求错误');
- // }
- // $param = $this->request->param();
- // if (empty($param['order'])){
- // $this->error('参数错误');
- // }
- //
- // $wheres['Mod_rq'] = null;
- //
- // $porlis = \db('工单_印件资料')
- // ->where('订单编号',$param['order'])
- // ->where('船样',0)
- // ->where($wheres)
- // ->field('子订单编号')
- // ->select();
- //
- // $subOrder = $porlis[0]['子订单编号'];
- // // 找到子订单编号中的 '-' 位置
- // $dashPos = strpos($subOrder, '-');
- // if ($dashPos !== false) {
- // // 提取 '-' 后面的部分
- // $afterDash = substr($subOrder, $dashPos + 1);
- // // 判断长度是否等于2或等于4
- // if (strlen($afterDash) == 2) {
- // $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)
- // // ->where('子订单编号','like','%00')
- // ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
- // cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
- // cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
- // ->select();
- //
- // if(!$processlist){
- // $processlist = \db('工单_印件资料')
- // ->where('订单编号',$param['order'])
- // ->where('船样',0)
- // ->where($where)
- // ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
- // 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]);
- // }
- // }
- // // 如果有0清空为 ''
- // foreach ($processlist as &$row) {
- // foreach ($row as $key => $value) {
- // if ($value === 0) {
- // $row[$key] = '';
- // }
- // }
- // }
- // echo "<pre>";
- // print_r($processlist);
- // echo "<pre>";
- // $data['order'] = $list;
- // sort($arr);
- // $data['xhdata'] = $arr;
- // $data['process'] = $processlist;
- // $this->success('成功',$data);
- // } elseif (strlen($afterDash) == 4) {
- // $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, 颜色备注, color_id,
- // cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
- // cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
- // ->select();
- // $mergedList = [];
- // $summaryList = []; // 用于存储汇总数据
- // foreach ($processlist as $item) {
- // $colorId = $item['color_id'];
- // $subOrderSuffix = substr($item['子订单编号'], -2);
- //
- // // 判断是否为汇总项(子订单编号后两位为 "00")
- // if ($subOrderSuffix === '00') {
- // // 初始化汇总数据
- // $summaryList[$colorId] = [
- // '子订单编号' => $item['子订单编号'],
- // '条码' => $item['子订单编号'],
- // '颜色' => $item['颜色'],
- // '款号' => $item['款号'],
- // 'zdtotal' => 0, // 累计总量
- // '颜色备注' => $item['颜色备注'],
- // 'color_id' => $colorId,
- // 'cm1' => $item['cm1'],
- // 'cm2' => $item['cm2'],
- // 'cm3' => $item['cm3'],
- // 'cm4' => $item['cm4'],
- // 'cm5' => $item['cm5'],
- // 'cm6' => $item['cm6'],
- // 'cm7' => $item['cm7'],
- // 'cm8' => $item['cm8'],
- // 'cm9' => $item['cm9'],
- // 'cm10' => $item['cm10'],
- // 'cmsl1' => 0,
- // 'cmsl2' => 0,
- // 'cmsl3' => 0,
- // 'cmsl4' => 0,
- // 'cmsl5' => 0,
- // 'cmsl6' => 0,
- // 'cmsl7' => 0,
- // 'cmsl8' => 0,
- // 'cmsl9' => 0,
- // 'cmsl10' => 0,
- // ];
- // }
- //
- // // 如果该 color_id 已经存在于汇总数组中,累加数量
- // if (isset($summaryList[$colorId])) {
- // $summaryList[$colorId]['cmsl1'] += $item['cmsl1'];
- // $summaryList[$colorId]['cmsl2'] += $item['cmsl2'];
- // $summaryList[$colorId]['cmsl3'] += $item['cmsl3'];
- // $summaryList[$colorId]['cmsl4'] += $item['cmsl4'];
- // $summaryList[$colorId]['cmsl5'] += $item['cmsl5'];
- // $summaryList[$colorId]['cmsl6'] += $item['cmsl6'];
- // $summaryList[$colorId]['cmsl7'] += $item['cmsl7'];
- // $summaryList[$colorId]['cmsl8'] += $item['cmsl8'];
- // $summaryList[$colorId]['cmsl9'] += $item['cmsl9'];
- // $summaryList[$colorId]['cmsl10'] += $item['cmsl10'];
- // $summaryList[$colorId]['zdtotal'] += $item['zdtotal'];
- // }
- //
- // // 将原数据保留到结果数组中
- // $mergedList[] = $item;
- // }
- //
- //// 将汇总数据追加到结果数组中
- // foreach ($summaryList as $summary) {
- // $mergedList[] = $summary;
- // }
- // foreach ($mergedList as $key=>$value){
- // for($i=1;$i<=10;$i++){
- // if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
- // $mergedList[$key][$value['cm'.$i]] = $value['cmsl'.$i];
- // }
- // unset($mergedList[$key]['cm'.$i],$mergedList[$key]['cmsl'.$i]);
- // }
- // }
- // // 如果有0清空为 ''
- // foreach ($mergedList as &$row) {
- // foreach ($row as $key => $value) {
- // if ($value === 0) {
- // $row[$key] = '';
- // }
- // }
- // }
- //
- // $data['order'] = $list;
- // sort($arr);
- // $data['xhdata'] = $arr;
- // $data['process'] = $mergedList;
- //
- // $this->success('成功', $data);
- // } else {
- // echo "子订单编号 - 后不是2位也不是4位:$afterDash";
- // }
- // } else {
- // echo "子订单编号中没有找到'-'";
- // }
- //
- //
- //// $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, 颜色备注, color_id,
- //// cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
- //// cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
- //// ->select();
- //// $mergedList = [];
- //// $summaryList = []; // 用于存储汇总数据
- //// foreach ($processlist as $item) {
- //// $colorId = $item['color_id'];
- //// $subOrderSuffix = substr($item['子订单编号'], -2);
- ////
- //// // 判断是否为汇总项(子订单编号后两位为 "00")
- //// if ($subOrderSuffix === '00') {
- //// // 初始化汇总数据
- //// $summaryList[$colorId] = [
- //// '子订单编号' => $item['子订单编号'],
- //// '条码' => $item['子订单编号'],
- //// '颜色' => $item['颜色'],
- //// '款号' => $item['款号'],
- //// 'zdtotal' => 0, // 累计总量
- //// '颜色备注' => $item['颜色备注'],
- //// 'color_id' => $colorId,
- //// 'cm1' => $item['cm1'],
- //// 'cm2' => $item['cm2'],
- //// 'cm3' => $item['cm3'],
- //// 'cm4' => $item['cm4'],
- //// 'cm5' => $item['cm5'],
- //// 'cm6' => $item['cm6'],
- //// 'cm7' => $item['cm7'],
- //// 'cm8' => $item['cm8'],
- //// 'cm9' => $item['cm9'],
- //// 'cm10' => $item['cm10'],
- //// 'cmsl1' => 0,
- //// 'cmsl2' => 0,
- //// 'cmsl3' => 0,
- //// 'cmsl4' => 0,
- //// 'cmsl5' => 0,
- //// 'cmsl6' => 0,
- //// 'cmsl7' => 0,
- //// 'cmsl8' => 0,
- //// 'cmsl9' => 0,
- //// 'cmsl10' => 0,
- //// ];
- //// }
- ////
- //// // 如果该 color_id 已经存在于汇总数组中,累加数量
- //// if (isset($summaryList[$colorId])) {
- //// $summaryList[$colorId]['cmsl1'] += $item['cmsl1'];
- //// $summaryList[$colorId]['cmsl2'] += $item['cmsl2'];
- //// $summaryList[$colorId]['cmsl3'] += $item['cmsl3'];
- //// $summaryList[$colorId]['cmsl4'] += $item['cmsl4'];
- //// $summaryList[$colorId]['cmsl5'] += $item['cmsl5'];
- //// $summaryList[$colorId]['cmsl6'] += $item['cmsl6'];
- //// $summaryList[$colorId]['cmsl7'] += $item['cmsl7'];
- //// $summaryList[$colorId]['cmsl8'] += $item['cmsl8'];
- //// $summaryList[$colorId]['cmsl9'] += $item['cmsl9'];
- //// $summaryList[$colorId]['cmsl10'] += $item['cmsl10'];
- //// $summaryList[$colorId]['zdtotal'] += $item['zdtotal'];
- //// }
- ////
- //// // 将原数据保留到结果数组中
- //// $mergedList[] = $item;
- //// }
- ////
- ////// 将汇总数据追加到结果数组中
- //// foreach ($summaryList as $summary) {
- //// $mergedList[] = $summary;
- //// }
- //// foreach ($mergedList as $key=>$value){
- //// for($i=1;$i<=10;$i++){
- //// if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
- //// $mergedList[$key][$value['cm'.$i]] = $value['cmsl'.$i];
- //// }
- //// unset($mergedList[$key]['cm'.$i],$mergedList[$key]['cmsl'.$i]);
- //// }
- //// }
- //// // 如果有0清空为 ''
- //// foreach ($mergedList as &$row) {
- //// foreach ($row as $key => $value) {
- //// if ($value === 0) {
- //// $row[$key] = '';
- //// }
- //// }
- //// }
- ////
- //// $data['order'] = $list;
- //// sort($arr);
- //// $data['xhdata'] = $arr;
- //// $data['process'] = $mergedList;
- ////
- //// $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(){
- // 确保是GET请求
- if ($this->request->isGet() === false) {
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param) || !isset($param['cy']) || !isset($param['order'])) {
- $this->error('参数错误');
- }
- // 判断是否“船样”获取对应的子订单编号
- if ($param['cy'] == '否') {
- //1.通过色系名称查询对应的编号
- $colorlist = \db('工单_颜色编号')
- ->field('colorcode, colorname')
- ->where('colorname', $param['colorname'] ?? '')
- ->find();
- if (empty($colorlist)) {
- $this->error('未找到对应的颜色编号');
- }
- $num = $param['order'] . '-' . $colorlist['colorcode'];
- // 查询子订单编号
- $data = \db('工单_印件资料')
- ->field('子订单编号,cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
- ->where('子订单编号', 'like', '%' . $num . '%')
- ->where('船样', '=', 0)
- ->order('子订单编号', 'desc')
- ->find();
- if (empty($data)) {
- // 如果没有找到数据,生成默认的订单编号,后两位从00开始
- $order = $param['order'] . '-' . $colorlist['colorcode'] . '00';
- } else {
- if (strlen($data['子订单编号']) == 12) {
- $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;
- }
- }
- }else{
- // 如果找到数据,提取子订单编号并递增
- $order = $data['子订单编号'];
- if (preg_match('/(.*-' . $colorlist['colorcode'] . ')(\d{2})$/', $order, $matches)) {
- $prefix = $matches[1]; // 前缀部分(包括订单编号和颜色代码)
- $number = $matches[2]; // 数字部分(后两位)
- // 循环生成子订单编号并检查数据库中是否存在相同编号
- do {
- $incrementedNumber = (int)$number + 1;
- // 将数字部分补充为两位数,例如 1 -> 01,2 -> 02
- $order = $prefix . str_pad($incrementedNumber, 2, '0', STR_PAD_LEFT);
- $exists = \db('工单_印件资料')->where('子订单编号', '=', $order)->find();
- $number = $incrementedNumber; // 更新 number 用于下一次循环
- } while ($exists); // 如果存在相同编号则继续循环递增
- } else {
- $this->error('订单编号格式错误');
- }
- }
- }
- //2.获取色系名称信息
- $colorlist = \db('工单_颜色编号')->select();
- //3.获取历史尺码数据
- $cm_list = \db('工单_印件资料')
- ->where('订单编号', $param['order'])
- ->group('订单编号')
- ->find();
- $cm_data = [];
- if ($cm_list) {
- // 精准筛选字段名以 "cm" 开头并跟1到2位数字的字段
- foreach ($cm_list as $key => $value) {
- if (preg_match('/^cm\d{1,2}$/', $key)) {
- $cm_data[$key] = $value ?? ''; // 如果值为 null,设为空字符串
- }
- }
- } else {
- // 如果查询结果为空,将 cm1 到 cm10 都设置为空
- for ($i = 1; $i <= 10; $i++) {
- $cm_data["cm$i"] = '';
- }
- }
- $result = ['order' => $order,'colorlist' => $colorlist,'cm' => $cm_data];
- $this->success('成功', $result);
- } else if ($param['cy'] == '是') {
- //1.获取船样子订单编号
- $data = \db('工单_印件资料')
- ->where('订单编号', $param['order'])
- ->where('船样', '=', 1)
- ->order('子订单编号 asc')
- ->find();
- if (empty($data)) {
- // 如果没有数据,初始子订单编号为 '99'
- $order = $param['order'] . '-99';
- } else {
- // 提取子订单编号中的数字部分
- $subOrder = $data['子订单编号']; // 例如 "DC2410006-99"
- if (preg_match('/-(\d+)$/', $subOrder, $matches)) {
- $numberPart = (int)$matches[1]; // 提取到的数字部分
- $newNumber = $numberPart - 1; // 减 1
- // 将新的数字拼接回订单编号
- $order = preg_replace('/-\d+$/', '-' . $newNumber, $subOrder);
- } else {
- $this->error('订单编号格式错误');
- }
- }
- $this->success('成功', $order);
- }
- }
- /**
- * 获取PO号 【代码展示未用到】
- */
- public function getPonumber() {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- // $num = substr($param['child_order'], 0, 12); // 如果需要,可以用这个方式截取子订单编号
- // $sql = "SELECT * FROM `工单_印件资料` WHERE `子订单编号` LIKE '{$num}%' ORDER BY `子订单编号` DESC LIMIT 1";
- // $data = \db()->query($sql);
- $colorlist = \db('工单_颜色编号')
- ->field('colorcode,colorname')
- ->where('colorname',$param['child_order'])
- ->find();
- $num = $param['order'] . '-' . $colorlist['colorcode']; // 生成 num,用于模糊查询
- $data = \db('工单_印件资料')
- ->where('子订单编号', 'like', '%' . $num . '%')
- ->order('子订单编号', 'desc')
- ->find();
- if(count($data) === 1){
- $order = $num.'01';
- }else{
- $number = (int)substr($data['子订单编号'],12,14) + 1;
- if ($num<10){
- $order = $num.'0'.$number;
- }else{
- $order = $num.$number;
- }
- }
- $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']);
- // $findlist = \db('工单_印件资料')
- // ->where('Uniqid', $param['id'])
- // ->find();
- $updata = [
- '订单编号' => $param['订单编号'],
- '子订单编号' => $param['子订单编号'],
- '款号' => $param['款号'],
- '船样' => $param['船样'],
- '颜色' => $param['颜色'],
- 'color_id' => $param['color_id'],
- '颜色备注' => $param['颜色备注'],
- 'zdtotal' => $param['zdtotal']
- ];
- for ($i = 1; $i <= 10; $i++) {
- $updata["cmsl{$i}"] = isset($param["cmsl{$i}"]) ? $param["cmsl{$i}"] : '';
- }
- $sql = \db('工单_印件资料')
- ->where('Uniqid', $param['id'])
- ->fetchSql(true)
- ->update($updata);
- $res = \db()->query($sql);
- if ($res !== false) {
- $this->success('修改成功');
- } else {
- $this->error('修改失败');
- }
- // $child_order = substr($param['子订单编号'],0,12);
- // $list = \db('工单_印件资料')
- // ->field('sum(cmsl1) as cmsl1,sum(cmsl2) as cmsl2,sum(cmsl3) as cmsl3,sum(cmsl4) as cmsl4
- // ,sum(cmsl5) as cmsl5,sum(cmsl6) as cmsl6,sum(cmsl7) as cmsl7,sum(cmsl8) as cmsl8
- // ,sum(cmsl9) as cmsl9,sum(cmsl10) as cmsl10')
- // ->where('子订单编号','like',$child_order.'%')
- // ->where('子订单编号','<>',$child_order.'00')
- // ->where('Mod_rq',null)
- // ->find();
- // $num_sql = \db('工单_印件资料')->where('子订单编号',$child_order.'00')->fetchSql(true)->update($list);
- // $result = \db()->query($num_sql);
- // if ($res === false || $result === false){
- // $this->error('修改失败');
- // }else{
- // $this->success('修改成功');
- // }
- // if(Request::instance()->post() === 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);
- // $child_order = substr($param['子订单编号'],0,12);
- // $list = \db('工单_印件资料')
- // ->field('sum(cmsl1) as cmsl1,sum(cmsl2) as cmsl2,sum(cmsl3) as cmsl3,sum(cmsl4) as cmsl4
- // ,sum(cmsl5) as cmsl5,sum(cmsl6) as cmsl6,sum(cmsl7) as cmsl7,sum(cmsl8) as cmsl8
- // ,sum(cmsl9) as cmsl9,sum(cmsl10) as cmsl10')
- // ->where('子订单编号','like',$child_order.'%')
- // ->where('子订单编号','<>',$child_order.'00')
- // ->where('Mod_rq',null)
- // ->find();
- // $num_sql = \db('工单_印件资料')->where('子订单编号',$child_order.'00')->fetchSql(true)->update($list);
- // $result = \db()->query($num_sql);
- // if ($res === false || $result === 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')
- ->order('sys_rq desc')
- ->limit(1)
- ->select();
- $this->success('成功',$list);
- }
- }
|