WorkOrder.php 141 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Upload;
  5. use Monolog\Handler\IFTTTHandler;
  6. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  7. use think\Config;
  8. use think\Db;
  9. use think\Request;
  10. use PhpOffice\PhpSpreadsheet\IOFactory;
  11. use PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf;
  12. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  13. /**
  14. * 工单资料管理
  15. */
  16. class WorkOrder extends Api
  17. {
  18. protected $noNeedLogin = ['*'];
  19. protected $noNeedRight = ['*'];
  20. public function _initialize()
  21. {
  22. if (isset($_SERVER['HTTP_ORIGIN'])) {
  23. header('Access-Control-Expose-Headers: __token__');//跨域让客户端获取到
  24. }
  25. //跨域检测
  26. check_cors_request();
  27. if (!isset($_COOKIE['PHPSESSID'])) {
  28. Config::set('session.id', $this->request->server("HTTP_SID"));
  29. }
  30. parent::_initialize();
  31. }
  32. /**
  33. * 工单资料菜单列表
  34. *
  35. * @ApiMethod (GET)
  36. * @return false|string
  37. * @throws \think\Exception
  38. */
  39. public function DataList()
  40. {
  41. // if ($this->request->isGet() === false){
  42. // $this->error('请求错误');
  43. // }
  44. // $data = \db('erp_客户供应商')
  45. // ->order('编号 asc')
  46. // ->column('rtrim(编号) as 编号');
  47. // $this->success('成功', $data);
  48. $where['j.Mod_rq'] = null;
  49. $allCustomers = \db('erp_客户供应商')->alias('e')
  50. ->field('e.编号 as 客户编号')
  51. ->select();
  52. $customerData = [];
  53. foreach ($allCustomers as $customer) {
  54. $customerID = $customer['客户编号'];
  55. $customerData[$customerID] = ['计划中' => 0, '生产中' => 0];
  56. }
  57. $data = \db('erp_客户供应商')->alias('e')
  58. ->join('工单_基本资料 j', 'e.编号 = j.客户编号', 'LEFT')
  59. ->field('e.编号 as 客户编号, j.订单编号, j.gd_statu')
  60. ->where($where)
  61. ->select();
  62. foreach ($data as $row) {
  63. $customerID = $row['客户编号'];
  64. $status = $row['gd_statu'];
  65. if ($status == '1-计划中') {
  66. $customerData[$customerID]['计划中']++;
  67. } elseif ($status == '2-生产中') {
  68. $customerData[$customerID]['生产中']++;
  69. }
  70. }
  71. ksort($customerData);
  72. $output = [];
  73. foreach ($customerData as $customerID => $statusCounts) {
  74. $statusString = [];
  75. if ($statusCounts['计划中'] > 0) {
  76. $statusString[] = "计划中:{$statusCounts['计划中']}";
  77. }
  78. if ($statusCounts['生产中'] > 0) {
  79. $statusString[] = "生产中:{$statusCounts['生产中']}";
  80. }
  81. $output[] = "{$customerID}【" . implode(' ', $statusString) . "】";
  82. }
  83. $this->success('成功', $output);
  84. }
  85. /**
  86. * 工单基本资料列表
  87. * @ApiMethod (GET)
  88. * @param string $limit 查询长度
  89. * @param string $Gd_khdh 客户代号
  90. * @param string $startTime 接单日期开始时间
  91. * @param string $endTime 接单日期结束时间
  92. * @return \think\response\Json
  93. * @throws \think\exception\DbException
  94. */
  95. public function WorkOrderList()
  96. {
  97. if ($this->request->isGet() === false) {
  98. $this->error('请求错误');
  99. }
  100. $search = input('search');
  101. $page = input('page');
  102. $limit = input('limit');
  103. $param = $this->request->param();
  104. $where = [];
  105. if (!empty($search)) {
  106. $where['订单编号|生产款号|客户编号|款式|审核|Sys_id'] = ['like', '%' . $search . '%'];
  107. }
  108. $where['Mod_rq'] = null;
  109. $list = \db('工单_基本资料')
  110. ->where($where)
  111. ->order('订单编号 desc, Gd_statu desc, Sys_rq desc')
  112. ->limit(($page - 1) * $limit, $limit)
  113. ->select();
  114. // 提取所有订单编号
  115. $orderIds = array_column($list, '订单编号');
  116. // 查询所有在“工单_相关附件”表中存在的订单编号
  117. $relatedOrders = \db('工单_相关附件')
  118. ->whereIn('关联编号', $orderIds)
  119. ->whereIn('附件备注', '技术附件')
  120. ->column('关联编号');
  121. // 遍历数据,判断每个订单编号是否在相关附件表中
  122. foreach ($list as &$value) {
  123. if (in_array($value['订单编号'], $relatedOrders)) {
  124. $value['status'] = ''; // 有相关附件,status为空
  125. } else {
  126. $value['status'] = '*'; // 没有相关附件,标记为新订单
  127. }
  128. }
  129. $this->success('成功', ['data' => $list, 'total' => count($list)]);
  130. }
  131. /**
  132. * 编辑页面展示
  133. * @ApiMethod (GET)
  134. * @param string $workOrder 工单编号
  135. * @return void
  136. * @throws \think\db\exception\DataNotFoundException
  137. * @throws \think\db\exception\ModelNotFoundException
  138. * @throws \think\exception\DbException
  139. */
  140. // public function DataCorrection()
  141. // {
  142. // if ($this->request->isGet() === false){
  143. // $this->error('请求错误');
  144. // }
  145. // $workOrder = input('Gd_gdbh');
  146. // if (empty($workOrder)){
  147. // $this->error('参数错误');
  148. // }
  149. // $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  150. // rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称,rtrim(接单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
  151. // rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
  152. // rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid,rtrim(计划投料) as 平张投料';
  153. // $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  154. // if (empty($list)){
  155. // $this->error('未找到该工单信息');
  156. // }
  157. // $printData = \db('工单_印件资料')
  158. // ->where('Yj_Gdbh',$workOrder)
  159. // ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(Uniqid) as id')
  160. // ->cache(true,84600)
  161. // ->find();
  162. // if (empty($printData)){
  163. // $list['印件名称'] = '';
  164. // $list['印件代号'] = '';
  165. // $list['印件ID'] = '';
  166. // }else{
  167. // $list['印件名称'] = $printData['印件名称'];
  168. // $list['印件代号'] = $printData['印件代号'];
  169. // $list['印件ID'] = $printData['id'];
  170. // }
  171. // $this->success('成功',$list);
  172. // }
  173. /**
  174. * 工单资料修改
  175. * @ApiMethod (POST)
  176. * @param void
  177. * @return void
  178. * @throws \think\Exception
  179. * @throws \think\exception\PDOException
  180. */
  181. // public function WorkOrderEdit()
  182. // {
  183. // if (Request::instance()->isPost() === false){
  184. // $this->error('请求错误');
  185. // }
  186. // $param = Request::instance()->post();
  187. // if (empty($param) || isset($param['Uniqid']) === false){
  188. // $this->error('参数错误');
  189. // }
  190. // $row = [
  191. // 'Gd_lx' => isset($param['lx'])?$param['lx']:'',
  192. // '开单日期' => isset($param['kdrq'])?$param['kdrq']:'',
  193. // 'Gd_gdbh' => isset($param['gdbh'])?$param['gdbh']:'',
  194. // 'Gd_生产分类' => isset($param['scfl'])?$param['scfl']:'',
  195. // 'Gd_客户代号' => isset($param['khdh'])?$param['khdh']:'',
  196. // 'Gd_客户名称' => isset($param['khmc'])?$param['khmc']:'',
  197. // '成品代号' => isset($param['cpdh'])?$param['cpdh']:'',
  198. // '成品名称' => isset($param['cpmc'])?$param['cpmc']:'',
  199. // '订单数量' => isset($param['ddsl'])?$param['ddsl']:'',
  200. // '交货日期' => isset($param['jhrq'])?$param['jhrq']:'',
  201. // '投料率' => isset($param['tll'])?$param['tll']:'',
  202. // '计划投料' => isset($param['jhtl'])?$param['jhtl']:'',
  203. // '实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  204. // '计量单位' => isset($param['jldw'])?$param['jldw']:'',
  205. // '投料大箱' => isset($param['tldx'])?$param['tldx']:'',
  206. // '销售订单号' => isset($param['xsddh'])?$param['xsddh']:'',
  207. // '警语版面' => isset($param['jymb'])?$param['jymb']:'',
  208. // '产品版本号' => isset($param['bbh'])?$param['bbh']:'',
  209. // '客户ERP编码' => isset($param['erp'])?$param['erp']:'',
  210. // '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
  211. // '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
  212. // 'Gd_desc' => isset($param['desc'])?$param['desc']:'',
  213. // '排产时库存' => isset($param['kc'])?$param['kc']:'',
  214. // '平均合格率' => isset($param['avg'])?$param['avg']:'',
  215. // ];
  216. // //获取印件资料
  217. // $printCode = \db('工单_印件资料')
  218. // ->where('Uniqid',$param['printID'])
  219. // ->value('yj_Yjno');
  220. // if (!empty($printCode)){
  221. // if ((int)$param['jhtl'] >0){
  222. // //修改工单工艺计划产量
  223. // $result = $this->PlannedProcessYield($param['gdbh'],$printCode,0,$param['jhtl']);
  224. // if ($result === false){
  225. // $this->success('分配工序计划产量失败');
  226. // }
  227. // }
  228. //
  229. // //修改印件信息
  230. // $printSql = \db('工单_印件资料')
  231. // ->where('Uniqid',$param['printID'])
  232. // ->fetchSql(true)
  233. // ->update(['Yj_Gdbh'=>$param['gdbh'],'yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
  234. // $printRes = Db::query($printSql);
  235. // }
  236. // //修改工单信息
  237. // $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
  238. // $res = Db::query($sql);
  239. // //修改订单数量该工单下的订单数量
  240. // //1. 查询该id下的工单编号, 防止其手动修改工单编号导致条件错误
  241. // $gdbh = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->value('Gd_gdbh');
  242. // //2. 根据查出的工单编号修改订单数量
  243. // $sql = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->fetchSql(true)->update(['订单数量'=>$row['订单数量']]);
  244. // $res1 = Db::query($sql);
  245. // if ($res !== false && $res1 !== false){
  246. // $this->success('成功');
  247. // }else{
  248. // $this->error('失败');
  249. // }
  250. // }
  251. /**
  252. * U8投料试算
  253. * @ApiMethod (GET)
  254. * @param string $processCode 产品编号
  255. * @return void
  256. * @throws \think\db\exception\DataNotFoundException
  257. * @throws \think\db\exception\ModelNotFoundException
  258. * @throws \think\exception\DbException
  259. */
  260. // public function U8Trial()
  261. // {
  262. // if ($this->request->isGet() === false)
  263. // {
  264. // $this->error('请求错误');
  265. // }
  266. // $productCode = input('productCode');
  267. // if (empty($productCode)){
  268. // $this->error('参数错误');
  269. // }
  270. // $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  271. // rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
  272. // $list = \db('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
  273. // if (empty($list)){
  274. // $this->success('未找到该产品工序');
  275. // }
  276. // foreach ($list as $key=>$value){
  277. // $data = \db('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
  278. // $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
  279. // $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
  280. // if ($value['add_gxmc'] !== ''){
  281. // $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
  282. // }else{
  283. // $list[$key]['工序名称'] = $value['gxmc'];
  284. // }
  285. // unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
  286. // }
  287. // $this->success('成功',$list);
  288. // }
  289. /**
  290. * 月度客户订单汇总
  291. */
  292. public function ProductInformation(){
  293. if ($this->request->isGet() === false) {
  294. $this->error('请求错误');
  295. }
  296. $where['j.gd_statu'] = '2-生产中';
  297. $where['j.Mod_rq'] = null;
  298. $data = \db('工单_基本资料')->alias('j')
  299. ->field('j.客户编号, REPLACE(DATE_FORMAT(j.Sys_rq, "%Y-%m"), "-", "") as 年月, GROUP_CONCAT(DISTINCT j.订单编号) as 订单编号')
  300. ->where($where)
  301. ->order('j.客户编号 asc')
  302. ->group('j.客户编号, 年月')
  303. ->select();
  304. $result = [];
  305. foreach ($data as $item) {
  306. $orderlist = count(explode(',', $item['订单编号']));
  307. $result[$item['年月']][] = [$item['客户编号'] . '【生产中:' . $orderlist . '】',
  308. ];
  309. }
  310. $this->success('请求成功', ['data' => $result]);
  311. }
  312. /**
  313. * 引用产品资料->复制产品工艺资料
  314. * @ApiMethod (POST)
  315. * @param string $oldWorkOrder 被复制工单编号
  316. * @param string $newWorkOrder 复制工单编号
  317. * @return void
  318. * @throws \think\Exception
  319. * @throws \think\db\exception\DataNotFoundException
  320. * @throws \think\db\exception\ModelNotFoundException
  321. * @throws \think\exception\DbException
  322. * @throws \think\exception\PDOException
  323. */
  324. // public function ProductInformationEdit()
  325. // {
  326. // if (Request::instance()->isPost() === false)
  327. // {
  328. // $this->error('请求错误');
  329. // }
  330. // $oldWorkOrder = input('oldWorkOrder');
  331. // $newWorkOrder = input('newWorkOrder');
  332. // if (empty($oldWorkOrder) || empty($newWorkOrder))
  333. // {
  334. // $this->error('参数错误');
  335. // }
  336. // $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  337. // if ($lastId<10000000){
  338. // $lastId = 10000000;
  339. // }else{
  340. // $lastId = $lastId + 1;
  341. // }
  342. // //获取原工单工艺资料
  343. // $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->select();
  344. // $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  345. // foreach ($oldProcessData as $k=>$v){
  346. // $oldProcessData[$k]['Gy0_gdbh'] = $oldWorkOrder;
  347. // $oldProcessData[$k]['Sys_id'] = '';
  348. // $oldProcessData[$k]['Gy0_sj1'] = '1900-01-01 00:00:00';
  349. // $oldProcessData[$k]['Gy0_sj2'] = '1900-01-01 00:00:00';
  350. // $oldProcessData[$k]['UniqId'] = $lastId + $k;
  351. // $oldProcessData[$k]['PD_WG'] = '1900-01-01 00:00:00';
  352. // }
  353. // if (\db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->find()){
  354. // \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->delete();
  355. // }
  356. // //获取原工单印件资料
  357. // $lastUniqId = \db('工单_印件资料')->order('UniqId desc')->value('UniqId');
  358. // if ($lastUniqId<1000000){
  359. // $lastUniqId = 1000000;
  360. // }else{
  361. // $lastUniqId = $lastUniqId + 1;
  362. // }
  363. // $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->select();
  364. // $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
  365. // foreach ($oldPrintData as $k=>$v){
  366. // $oldPrintData[$k]['Yj_Gdbh'] = $oldWorkOrder;
  367. // $oldPrintData[$k]['Sys_id'] = '';
  368. // $oldPrintData[$k]['Uniqid'] = $lastUniqId +$k +1;
  369. // }
  370. // if (\db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->find()){
  371. // \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->delete();
  372. // }
  373. // //复制印件、工艺资料
  374. // $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  375. // $ProcessRes = Db::query($ProcessSQL);
  376. // $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
  377. // $PrintRes = Db::query($PrintSQL);
  378. // if ($ProcessRes !== false && $PrintRes !== false){
  379. // $this->success('成功');
  380. // }else{
  381. // $this->error('失败');
  382. // }
  383. // }
  384. /**
  385. * 工艺流程调成->获取当前工单工艺资料
  386. * @ApiMethod (GET)
  387. * @param string $workorder 当前工单编号
  388. * @return void
  389. * @throws \think\db\exception\DataNotFoundException
  390. * @throws \think\db\exception\ModelNotFoundException
  391. * @throws \think\exception\DbException
  392. */
  393. // public function ProcessFlow()
  394. // {
  395. // if ($this->request->isGet() === false){
  396. // $this->error('请求错误');
  397. // }
  398. // $workOrder = input('workOrder');
  399. // if (empty($workOrder)){
  400. // $this->error('参数错误');
  401. // }
  402. // $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
  403. // if (empty($list)){
  404. // $this->success('未找到工单信息');
  405. // }
  406. // $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  407. // rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
  408. // rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间,rtrim(UniqId) as UniqId';
  409. // $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->cache(true,84600)->field($filed)->select();
  410. // if (empty($process)){
  411. // $this->error('未找到该工单工艺资料');
  412. // }
  413. // foreach ($process as $key=>$value){
  414. // if (isset($value['add_gxmc'])){
  415. // $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
  416. // }else{
  417. // $process[$key]['工序名称'] = $value['gxmc'];
  418. // }
  419. // $process[$key]['工价系数'] = (float)$value['工价系数'];
  420. // $process[$key]['损耗系数'] = (float)$value['损耗系数'];
  421. // $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
  422. // }
  423. // $list['process'] = $process;
  424. // $this->success('成功',$list);
  425. // }
  426. /**
  427. * 参照工单列表获取
  428. * @ApiMethod (GET)
  429. * @param string $workOrder 工单编号
  430. * @param string $productCode 产品代号
  431. * @return void
  432. */
  433. // public function ReferenceWorkOrder()
  434. // {
  435. // if ($this->request->isGet() === false){
  436. // $this->error('请求错误');
  437. // }
  438. // $productCode = input('productCode');
  439. // $workOrder = input('workOrder');
  440. // if (empty($productCode) || empty($workOrder)){
  441. // $this->error('参数错误');
  442. // }
  443. // $list = \db('工单_基本资料')->where('成品代号',$productCode)->distinct(true)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
  444. // if (empty($list)){
  445. // $this->success('未获取该产品其他工单信息');
  446. // }
  447. // $this->success('成功',$list);
  448. // }
  449. /**
  450. * 工艺资料复制
  451. * @ApiMethod (POST)
  452. * @param string $oldWorkOrder 被复制工单编号
  453. * @param string $newWorkOrder 复制工单编号
  454. * @return void
  455. * @throws \think\Exception
  456. * @throws \think\db\exception\DataNotFoundException
  457. * @throws \think\db\exception\ModelNotFoundException
  458. * @throws \think\exception\DbException
  459. * @throws \think\exception\PDOException
  460. *
  461. */
  462. // public function ProcessCopy()
  463. // {
  464. // if (Request::instance()->isPost() === false){
  465. // $this->error('请求错误');
  466. // }
  467. // $param = Request::instance()->post();
  468. // if (empty($param)){
  469. // $this->error('参数错误');
  470. // }
  471. // $UniqId = [];
  472. // $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
  473. // if ($lastId['id']>10000000){
  474. // $lastUniqId = $lastId['id'];
  475. // }else{
  476. // $lastUniqId = 10000000;
  477. // }
  478. // foreach ($param as $key=>$value){
  479. // $UniqId[$key] = $value['UniqId'];
  480. // }
  481. // $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
  482. // if (empty($processList)){
  483. // $this->success('未找到工艺资料');
  484. // }
  485. // $data = [];
  486. // foreach ($param as $key=>$value){
  487. // foreach ($processList as $k=>$v){
  488. // if ($value['UniqId'] = $v['UniqId']){
  489. // $data[$key] = $v;
  490. // $data[$key]['Gy0_gxh'] = $value['gxh'];
  491. // $data[$key]['Gy0_gdbh'] = $value['workOrder'];
  492. // $data[$key]['UniqId'] = $lastUniqId + $key + 1;
  493. // }
  494. // }
  495. // }
  496. // $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
  497. // if ($res !== false){
  498. // $result = \db('工单_工艺资料')->insertAll($data);
  499. // if ($result !== false){
  500. // $this->success('成功');
  501. // }else{
  502. // $this->error('失败');
  503. // }
  504. // }else{
  505. // $this->error('失败');
  506. // }
  507. // }
  508. /**
  509. * U8工单列表
  510. * @ApiMethod (GET)
  511. * @param void
  512. * @return void
  513. * @throws \think\db\exception\DataNotFoundException
  514. * @throws \think\db\exception\ModelNotFoundException
  515. * @throws \think\exception\DbException
  516. */
  517. // public function U8workOrder()
  518. // {
  519. // if ($this->request->isGet() === false){
  520. // $this->error('请求错误');
  521. // }
  522. // $param = $this->request->param();
  523. // if (empty($param)){
  524. // $this->error('参数错误');
  525. // }
  526. // $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  527. // rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
  528. // $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
  529. // if (empty($list)){
  530. // $this->success('未找到工单');
  531. // }
  532. // $this->success('成功',$list);
  533. // }
  534. /**
  535. * U8工单资料删除
  536. * @param string $workOrder 工单编号
  537. * @return void
  538. * @throws \think\Exception
  539. * @throws \think\exception\PDOException
  540. */
  541. public function orderDataDel()
  542. {
  543. if($this->request->isGet() === false){
  544. $this->error('请求错误');
  545. }
  546. $workOrder = input('Uniqid');
  547. if (empty($workOrder)){
  548. $this->error('参数错误');
  549. }
  550. $order = \db('工单_基本资料')->where('UniqId',$workOrder)->find();
  551. \db()->startTrans();
  552. try {
  553. \db('工单_印件资料')->where('订单编号',$order['订单编号'])->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  554. \db('工单_工艺资料')->where('订单编号',$order['订单编号'])->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  555. $res = \db('工单_基本资料')->where('UniqId',$workOrder)->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  556. \db()->commit();
  557. } catch (\Exception $e){
  558. \db()->rollback();
  559. }
  560. if ($res !== false){
  561. $this->success('成功');
  562. }else{
  563. $this->error('失败');
  564. }
  565. }
  566. /**
  567. * 产品废检系数调整->质检工艺数据获取
  568. * @ApiMethod (GET)
  569. * @param string $workOrder 工单编号
  570. * @return void
  571. * @throws \think\db\exception\DataNotFoundException
  572. * @throws \think\db\exception\ModelNotFoundException
  573. * @throws \think\exception\DbException
  574. */
  575. // public function TestCoefficient()
  576. // {
  577. // if ($this->request->isGet() === false){
  578. // $this->error('请求错误');
  579. // }
  580. // $workOrder = input('workOrder');
  581. // if (empty($workOrder)){
  582. // $this->error('参数错误');
  583. // }
  584. // $where = [
  585. // 'Gy0_gdbh' => $workOrder,
  586. // 'Gy0_gxmc' => ['like','%检%']
  587. // ];
  588. // $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
  589. // rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
  590. // rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
  591. // $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
  592. // if (empty($list)){
  593. // $this->success('未找到该工单工艺');
  594. // }
  595. // $name = \db('工单_基本资料')
  596. // ->where('Gd_gdbh',$workOrder)
  597. // ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
  598. // ->find();
  599. // if (empty($name)){
  600. // $this->success('未找到该工单');
  601. // }
  602. // foreach ($list as $key=>$value){
  603. // if ($value['yjno']<10){
  604. // $value['yjno'] = '0'.$value['yjno'];
  605. // }
  606. // if ($value['gxh']<10){
  607. // $value['gxh'] = '0'.$value['gxh'];
  608. // }
  609. // $list[$key]['印件工序及工艺'] = $value['gdbh'].'-'.$value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  610. // unset($list[$key]['gdbh'],$list[$key]['yjno'],$list[$key]['gxmc']);
  611. // $list[$key]['产品编号'] = $name['产品代号'];
  612. // $list[$key]['产品名称'] = $name['产品名称'];
  613. // $list[$key]['客户名称'] = $name['客户名称'];
  614. // }
  615. // $this->success('成功',$list);
  616. // }
  617. /**
  618. * 产品质检系数调整->系数修改
  619. * @ApiMethod (GET)
  620. * @param string $workorder 工单编号
  621. * @param string $processCode 工序号
  622. * @param float $code1 人工正品板
  623. * @param float $code2 人工次品板
  624. * @param float $code3 人工废检
  625. * @param float $code4 机检正品板
  626. * @param float $code5 机检次品板
  627. * @param float $code6 机检废检
  628. * @return void
  629. * @throws \think\Exception
  630. * @throws \think\exception\PDOException
  631. */
  632. // public function TestCoefficientEdit()
  633. // {
  634. // if (Request::instance()->isPost() === false){
  635. // $this->error('请求错误');
  636. // }
  637. // $workOrder = input('workOrder');
  638. // $processCode = input('processCode');
  639. // $row = [
  640. // '人工检_正品板' => input('code1'),
  641. // '人工检_次品板' => input('code2'),
  642. // '人工检_废检' => input('code3'),
  643. // '机检_正品板' => input('code4'),
  644. // '机检_次品板' => input('code5'),
  645. // '机检_废检' => input('code6'),
  646. // ];
  647. // if (empty($workOrder) || empty($processCode)){
  648. // $this->error('参数错误');
  649. // }
  650. // $where = [
  651. // 'Gy0_gdbh' => $workOrder,
  652. // 'Gy0_gxh' => $processCode
  653. // ];
  654. // $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
  655. // $res = Db::query($sql);
  656. // if ($res !== false){
  657. // $this->success('成功');
  658. // }else{
  659. // $this->error('失败');
  660. // }
  661. // }
  662. /**
  663. * 修正工单核算参数->数据获取
  664. * @ApiMethod (GET)
  665. * @param string $workOrder 工单编号
  666. * @return void
  667. * @throws \think\db\exception\DataNotFoundException
  668. * @throws \think\db\exception\ModelNotFoundException
  669. * @throws \think\exception\DbException
  670. */
  671. // public function AccountingParameter()
  672. // {
  673. // if ($this->request->isGet() === false){
  674. // $this->error('请求错误');
  675. // }
  676. // $workOrder = input('workOrder');
  677. // if (empty($workOrder)){
  678. // $this->error('参数错误');
  679. // }
  680. // $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,
  681. // rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
  682. // rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
  683. // $list = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
  684. // if (empty($list)){
  685. // $this->success('未找到该工单工艺资料');
  686. // }
  687. // foreach ($list as $key=>$value){
  688. // if ($value['yjno']<10){
  689. // $value['yjno'] = '0'.$value['yjno'];
  690. // }
  691. // if ($value['gxh']<10){
  692. // $value['gxh'] = '0'.$value['gxh'];
  693. // }
  694. // $list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
  695. // unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
  696. // }
  697. // $this->success('成功',$list);
  698. // }
  699. /**
  700. * 修正工单核算参数->参数修改
  701. * @ApiMethod (POST)
  702. * @param void
  703. * @return void
  704. * @throws \think\Exception
  705. * @throws \think\db\exception\DataNotFoundException
  706. * @throws \think\db\exception\ModelNotFoundException
  707. * @throws \think\exception\DbException
  708. * @throws \think\exception\PDOException
  709. */
  710. // public function AccountingParameterEdit()
  711. // {
  712. // if (Request::instance()->isPost() === false){
  713. // $this->error('请求错误');
  714. // }
  715. // $param = Request::instance()->post();
  716. // if (empty($param) || isset($param[0]['Uniqid']) === false){
  717. // $this->error('参数错误');
  718. // }
  719. // $i = 0;
  720. // foreach ($param as $key=>$value){
  721. // $data['rate0'] = 0;
  722. // $data['rate1'] = 0;
  723. // $rate = \db('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  724. // if (!empty($rate)){
  725. // $data['rate0'] = $rate['rate0'];
  726. // $data['rate1'] = $rate['rate1'];
  727. // }
  728. // $row = [
  729. // '工价系数' => $value['difficulty']?:'',
  730. // 'Gy0_shdh' => $value['loss']?:'',
  731. // '印刷方式' => $value['printMode']?:'',
  732. // '版距' => $value['plate']?:'',
  733. // 'Gy0_ms' => $value['chromatic']?:'',
  734. // '损耗系数' => $value['wastage']?:'',
  735. // 'Gy0_Rate0' => $data['rate0'],
  736. // 'Gy0_Rate1' => $data['rate1']
  737. // ];
  738. // $sql = \db('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
  739. // $res = Db::query($sql);
  740. // if ($res !== false){
  741. // $i++;
  742. // }
  743. // }
  744. // if ($i !== 0){
  745. // $this->success('成功');
  746. // }else{
  747. // $this->error('失败');
  748. // }
  749. // }
  750. /**
  751. * 印件资料修改
  752. * @ApiMethod (POST)
  753. * @param void
  754. * @return void
  755. * @throws \think\Exception
  756. * @throws \think\exception\PDOException
  757. */
  758. public function PrintedEdit()
  759. {
  760. if (Request::instance()->isPost() === false){
  761. $this->error('请求错误');
  762. }
  763. $param = Request::instance()->post();
  764. if (empty($param) || isset($param['Uniqid']) === false){
  765. $this->error('参数错误');
  766. }
  767. $param['Yj_Gdbh'] = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->value('Yj_Gdbh');
  768. $data = [
  769. 'Yj_Gdbh' =>$param['Yj_Gdbh'],
  770. 'yj_Yjno' =>$param['yjno'],
  771. 'yj_Yjdh' =>$param['yjdh'],
  772. 'yj_yjmc' =>$param['yjmc'],
  773. 'yj_zzdh' =>$param['zzdh'],
  774. 'yj_zzdh1' =>$param['zzdh1'],
  775. 'yj_zzdh2' =>$param['zzdh2'],
  776. 'yj_zzdh3' =>$param['zzdh3'],
  777. 'yj_zzdh4' =>$param['zzdh4'],
  778. 'yj_zzmc' =>$param['zzmc'],
  779. 'yj_zzmc1' =>$param['zzmc1'],
  780. 'yj_zzmc2' =>$param['zzmc2'],
  781. 'yj_zzmc3' =>$param['zzmc3'],
  782. 'yj_zzmc4' =>$param['zzmc4'],
  783. 'yj_tlgg' =>$param['tlgg'],
  784. 'yj_klgg' =>$param['klgg'],
  785. 'Yj_核算规格' =>$param['hsgg'],
  786. 'yj_成品数量' =>$param['cpsl'],
  787. 'yj_平张投料' =>$param['pztl'],
  788. 'yj_ks' =>$param['ks'],
  789. 'yj_ls' =>$param['ls'],
  790. 'yj_desc' =>$param['desc'],
  791. ];
  792. $UniqId = $param['Uniqid'];
  793. $sql = \db('工单_印件资料')->where('Uniqid',$UniqId)->fetchSql(true)->update($data);
  794. $res = Db::query($sql);
  795. $process = \db('工单_工艺资料')
  796. ->where('Gy0_gdbh',$data['Yj_Gdbh'])
  797. ->where('Gy0_yjno',$data['yj_Yjno'])
  798. ->select();
  799. if ((int)$data['yj_平张投料'] > 0 && !empty($process)){
  800. //重新分配工序计划产量
  801. $result = $this->PlannedProcessYield($data['Yj_Gdbh'],$data['yj_Yjno'],0,$data['yj_平张投料']);
  802. if ($result === false){
  803. $this->success('修改工序产量失败');
  804. }
  805. }
  806. if ($res !== false){
  807. $this->success('成功');
  808. }else{
  809. $this->error('失败');
  810. }
  811. }
  812. /**
  813. * 工艺资料修改
  814. * @ApiMethod (POST)
  815. */
  816. public function ProcessDetailEdit()
  817. {
  818. if (Request::instance()->isPost() === false){
  819. $this->error('请求错误');
  820. }
  821. $param = Request::instance()->post();
  822. if (empty($param) || isset($param['UniqId']) === false){
  823. $this->error('参数错误');
  824. }
  825. if (empty($param['Gy0_shdh'])){
  826. $rate['rate0'] = 0;
  827. $rate['rate1'] = 0;
  828. }else{
  829. $rate = \db('dic_lzsh')->where('sys_bh',$param['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  830. }
  831. $param['Gy0_Rate0']= isset($rate['rate0'])?$rate['rate0']:0;
  832. $param['Gy0_Rate1'] = isset($rate['rate1'])?$rate['rate1']:0;
  833. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  834. $UniqId = $param['UniqId'];
  835. unset($param['UniqId']);
  836. //修改工艺资料
  837. $sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
  838. $res = Db::query($sql);
  839. //获取工艺资料数据
  840. $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
  841. // //修改工单状态
  842. // $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
  843. // if ($status['status'] !== '2-生产中'){
  844. // $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  845. // Db::query($statusSql);
  846. // }
  847. //重新分配工序计划产量
  848. if ((int)$list['计划接货数'] > 0){
  849. $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],$list['Gy0_gxh'],$list['计划接货数']);
  850. }
  851. if ($res !== false){
  852. $this->success('成功');
  853. }else{
  854. $this->error('失败');
  855. }
  856. }
  857. /**
  858. * 工艺资料编辑->机台列表获取
  859. * @return void
  860. * @throws \think\db\exception\DataNotFoundException
  861. * @throws \think\db\exception\ModelNotFoundException
  862. * @throws \think\exception\DbException
  863. */
  864. // public function MachineList()
  865. // {
  866. // if ($this->request->isGet() === false){
  867. // $this->error('请求错误');
  868. // }
  869. // $param = $this->request->param();
  870. // if (empty($param)){
  871. // $this->error('参数错误');
  872. // }
  873. // $list = \db('设备_基本资料')
  874. // ->where('存放地点',$param['address'])
  875. // ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
  876. // ->select();
  877. // if (empty($list)){
  878. // $this->success('未找到该车间机台');
  879. // }
  880. // $data = [];
  881. // foreach ($list as $key=>$value){
  882. // $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
  883. // }
  884. // $this->success('成功',$data);
  885. // }
  886. /**
  887. * 打印作业通知单->工单印件和工序获取
  888. * @ApiMethod (GET)
  889. * @return void
  890. * @throws \think\db\exception\DataNotFoundException
  891. * @throws \think\db\exception\ModelNotFoundException
  892. * @throws \think\exception\DbException
  893. */
  894. // public function PrintCodeList()
  895. // {
  896. // if ($this->request->isGet() === false){
  897. // $this->error('请求错误');
  898. // }
  899. // $param = $this->request->param();
  900. // if (empty($param)){
  901. // $this->error('参数错误');
  902. // }
  903. // $list = \db('工单_印件资料')
  904. // ->field([
  905. // 'rtrim(yj_Yjno)' => '印件号',
  906. // 'rtrim(yj_yjmc)' => '印件名称'
  907. // ])
  908. // ->where('Yj_Gdbh',$param['workOrder'])
  909. // ->select();
  910. // $this->success('成功',$list);
  911. // }
  912. /**
  913. * 打印作业通知单->工艺编号获取
  914. * @ApiMethod (GET)
  915. * @return void
  916. * @throws \think\db\exception\DataNotFoundException
  917. * @throws \think\db\exception\ModelNotFoundException
  918. * @throws \think\exception\DbException
  919. */
  920. // public function ProcessCodeList()
  921. // {
  922. // if ($this->request->isGet() === false){
  923. // $this->error('请求错误');
  924. // }
  925. // $param = $this->request->param();
  926. // if (empty($param)){
  927. // $this->error('参数错误');
  928. // }
  929. // $list = \db('工单_工艺资料')
  930. // ->field('rtrim(Gy0_gxh) as 工序号')
  931. // ->where([
  932. // 'Gy0_gdbh' => $param['workOrder'],
  933. // 'Gy0_yjno' => $param['yjno']
  934. // ])
  935. // ->select();
  936. // $this->success('成功',$list);
  937. // }
  938. /**
  939. * 打印作业通知单
  940. * @ApiMethod (POST)
  941. * @param void
  942. * @return void
  943. * @throws \think\db\exception\DataNotFoundException
  944. * @throws \think\db\exception\ModelNotFoundException
  945. * @throws \think\exception\DbException
  946. */
  947. // public function PrintJobOrder()
  948. // {
  949. // if ($this->request->isGet() === false) {
  950. // $this->error('请求错误');
  951. // }
  952. // $param = $this->request->param();
  953. // if (empty($param)){
  954. // $this->error('参数错误');
  955. // }
  956. // $data = $this->workOrderDetailGet($param['workOrder'],$param['yjno']);
  957. // if (empty($data)){
  958. // $this->success('未找到工单信息');
  959. // }
  960. // $materiel = $this->MaterielDetailGet($param['workOrder']);
  961. // $printDetail = $this->PrintDetailGet($param['workOrder'],$param['yjno'],$param['gxh']);
  962. // if (empty($printDetail)){
  963. // $this->success('未找到工艺信息');
  964. // }
  965. // $number = 0;
  966. // foreach ($printDetail as $key=>$value){
  967. // $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
  968. // $number = $number+$value['允损比例'];
  969. // }
  970. // $data['制单'] = $param['PrepareDocument'];
  971. // $data['审核'] = $param['examine'];
  972. // $data['目标合格率'] = 100-$number.'%';
  973. // $data['materiel'] = $materiel;
  974. // $data['printDetail'] = $printDetail;
  975. // $this->success('成功',$data);
  976. // }
  977. /**
  978. * 打印作业通知单->工单及印件资料获取
  979. * @param $workOrder
  980. * @return mixed
  981. */
  982. // public function workOrderDetailGet($workOrder,$yjno)
  983. // {
  984. // $sql = "SELECT
  985. // RTRIM( a.Gd_lx) AS 工单类型,
  986. // RTRIM( a.Gd_gdbh ) AS 生产批次号,
  987. // RTRIM( a.销售订单号 ) AS 销售订单号,
  988. // RTRIM( a.Gd_客户代号 ) AS 客户代号,
  989. // RTRIM( a.Gd_客户名称 ) AS 客户名称,
  990. // RTRIM( a.成品代号 ) AS 产品代码,
  991. // RTRIM( a.成品名称 ) AS 产品名称,
  992. // RTRIM( a.产品版本号 ) AS 版本号,
  993. // RTRIM( a.警语版面 ) AS 警语版面,
  994. // RTRIM( a.码源数量 ) AS 码源数量,
  995. // RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
  996. // RTRIM( a.接单日期 ) AS 开单日期,
  997. // RTRIM( a.交货日期 ) AS 交货日期,
  998. // RTRIM( a.Gd_desc ) AS 工单说明,
  999. // RTRIM( a.投料率 ) AS 投料率,
  1000. // RTRIM( a.订单数量 ) AS 订单数量,
  1001. // RTRIM( a.平均合格率 ) AS 平均合格率,
  1002. // RTRIM( a.投料大箱 ) AS 订货数量,
  1003. // RTRIM( a.排产时库存 ) AS 排产时库存,
  1004. // RTRIM( b.yj_Yjno ) AS 印件,
  1005. // RTRIM( b.yj_Yjdh ) AS 印件代号,
  1006. // RTRIM( b.yj_yjmc ) AS 印件名称,
  1007. // RTRIM( b.yj_平张投料 ) AS 平张投料量,
  1008. // RTRIM( b.yj_zzmc ) AS 纸张名称,
  1009. // RTRIM( b.yj_tlgg ) AS 投料规格,
  1010. // RTRIM( b.yj_ks ) AS 开数,
  1011. // RTRIM( b.yj_ls ) AS 联数,
  1012. // RTRIM( b.yj_desc ) AS 印件备注
  1013. // FROM
  1014. // `工单_基本资料` AS a
  1015. // JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh
  1016. // WHERE
  1017. // a.Gd_gdbh = '{$workOrder}' AND a.行号 = 1 AND b.yj_Yjno = '{$yjno}'";
  1018. // $list = Db::query($sql);
  1019. // if (empty($list)){
  1020. // $this->success('未找到订单数据');
  1021. // }
  1022. // $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
  1023. // $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
  1024. // if (strpos($list[0]['产品名称'],'条') !== false){
  1025. // $list[0]['订货数量'] = (int)$list[0]['订单数量']*40;
  1026. // $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/250);
  1027. // }else{
  1028. // $list[0]['订货数量'] = (int)$list[0]['订单数量']*4;
  1029. // $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/2500);
  1030. // }
  1031. // $list[0]['联数'] = (int)$list[0]['联数'];
  1032. // $list[0]['印件代号及名称'] = $list[0]['印件代号'].' '.$list[0]['印件名称'];
  1033. //// $list[0]['投料数量'] = $list[0]['订货数量'];
  1034. // unset($list[0]['印件代号'],$list[0]['印件名称']);
  1035. // return($list[0]);
  1036. // }
  1037. /**打印作业流程单->物料资料获取
  1038. * @param $workOrder
  1039. * @return bool|\PDOStatement|string|\think\Collection
  1040. * @throws \think\db\exception\DataNotFoundException
  1041. * @throws \think\db\exception\ModelNotFoundException
  1042. * @throws \think\exception\DbException
  1043. */
  1044. // public function MaterielDetailGet($workOrder)
  1045. // {
  1046. // $where = [
  1047. // 'BOM_工单编号' => $workOrder,
  1048. // ];
  1049. // $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
  1050. // $list = \db('工单_bom资料')->where($where)->field($filed)->select();
  1051. // if (!empty($list)){
  1052. // foreach ($list as $key=>$value){
  1053. // $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
  1054. // $list[$key]['计划用量'] = (float)$value['计划用量'];
  1055. // unset($list[$key]['物料编码'],$list[$key]['物料名称']);
  1056. // }
  1057. // }
  1058. // return $list;
  1059. // }
  1060. /**
  1061. * 打印作业流程单->工艺资料获取
  1062. * @param $workOrder
  1063. * @return bool|\PDOStatement|string|\think\Collection
  1064. * @throws \think\db\exception\DataNotFoundException
  1065. * @throws \think\db\exception\ModelNotFoundException
  1066. * @throws \think\exception\DbException
  1067. */
  1068. // public function PrintDetailGet($workOrder,$yjno,$gxh)
  1069. // {
  1070. // $where = [
  1071. // 'Gy0_gdbh' => $workOrder,
  1072. // 'Gy0_yjno' => $yjno,
  1073. // 'Gy0_gxh' => ['<=',$gxh]
  1074. // ];
  1075. // $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  1076. // rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
  1077. // rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
  1078. // $list = \db('工单_工艺资料')
  1079. // ->where($where)
  1080. // ->field($filed)
  1081. // ->select();
  1082. // if (empty($list)){
  1083. // $this->success('工单工艺为空');
  1084. // }
  1085. // foreach ($list as $key=>$value){
  1086. // if ($value['yjno']<10){
  1087. // $value['yjno'] = '0'.$value['yjno'];
  1088. // }
  1089. // if ($value['gxh']<10){
  1090. // $value['gxh'] = '0'.$value['gxh'];
  1091. // }
  1092. // if ($value['add_gxmc'] !== null){
  1093. //
  1094. // $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  1095. // }else{
  1096. // $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  1097. // }
  1098. // $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
  1099. // $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
  1100. // if ((int)$value['计划接货数'] === 0){
  1101. // $list[$key]['允损比例'] = 0;
  1102. // }else{
  1103. // $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
  1104. // }
  1105. // unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
  1106. // }
  1107. // return $list;
  1108. // }
  1109. /**
  1110. * 获取小时产能
  1111. * @ApiMethod (GET)
  1112. * @param void
  1113. * @return void
  1114. * @throws \think\db\exception\DataNotFoundException
  1115. * @throws \think\db\exception\ModelNotFoundException
  1116. * @throws \think\exception\DbException
  1117. */
  1118. // public function capacityList()
  1119. // {
  1120. // if ($this->request->isGet() === false){
  1121. // $this->error('请求错误');
  1122. // }
  1123. // $param = $this->request->param();
  1124. // if (empty($param)){
  1125. // $this->error('参数错误');
  1126. // }
  1127. // $machine = explode(' ',$param['machine'])[0];
  1128. // $number = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(排单小时定额) as 小时产能')->find();
  1129. // if (empty($number)){
  1130. // $this->error('未找到小时产能');
  1131. // }
  1132. // $this->success('成功',$number['小时产能']);
  1133. // }
  1134. /**
  1135. * 新增工单->添加工单
  1136. * @ApiMethod (POST)
  1137. * @param
  1138. */
  1139. public function WorkOrderAdd()
  1140. {
  1141. // var_dump(1);exit;
  1142. if (Request::instance()->isPost() === false){
  1143. $this->error('请求错误');
  1144. }
  1145. $param = Request::instance()->post();
  1146. if (empty($param)){
  1147. $this->error('参数错误');
  1148. }
  1149. $param['Sys_rq'] = date('Y-m-d H:i:s');
  1150. $param['gd_statu'] = '1-计划中';
  1151. $prefix = substr($param['订单编号'], 0, 2); // e.g., "DC"
  1152. $maxOrder = \db('工单_基本资料')
  1153. ->where('订单编号', 'like', "{$prefix}%")
  1154. ->order('订单编号', 'desc')
  1155. ->limit(1)
  1156. ->value('订单编号');
  1157. if ($maxOrder) {
  1158. $numericPart = substr($maxOrder, 2);
  1159. $newNumericPart = str_pad((int)$numericPart + 1, strlen($numericPart), '0', STR_PAD_LEFT);
  1160. $param['订单编号'] = $prefix . $newNumericPart;
  1161. } else {
  1162. $param['订单编号'] = $param['订单编号'];
  1163. }
  1164. $sql= \db('工单_基本资料')->fetchSql(true)->insert($param);
  1165. $res = \db()->query($sql);
  1166. if ($res !== false){
  1167. $this->success('成功');
  1168. }else{
  1169. $this->error('失败');
  1170. }
  1171. }
  1172. /**
  1173. * 新增工单->客户代号列表获取
  1174. * @return void
  1175. * @throws \think\db\exception\BindParamException
  1176. * @throws \think\exception\PDOException
  1177. */
  1178. // public function ClientList()
  1179. // {
  1180. // if ($this->request->isGet() === false){
  1181. // $this->error('请求错误');
  1182. // }
  1183. // $param = $this->request->param();
  1184. // if (isset($param['search'])){
  1185. // $where = $param['search'].'%';
  1186. // $sql = "SELECT DISTINCT
  1187. // (客户编号),rtrim(客户名称 ) as 客户名称
  1188. // FROM
  1189. // `产品_基本资料`
  1190. // WHERE
  1191. // 客户编号 LIKE "."'".$where."'"."
  1192. // OR
  1193. // 客户名称 LIKE "."'".$where."'"."
  1194. // GROUP BY
  1195. // 客户编号
  1196. // order by
  1197. // 客户编号";
  1198. // }else{
  1199. // $sql = "SELECT DISTINCT
  1200. // (客户编号),rtrim(客户名称 ) as 客户名称
  1201. // FROM
  1202. // `产品_基本资料`
  1203. // GROUP BY
  1204. // 客户编号
  1205. // order by
  1206. // 客户编号";
  1207. // }
  1208. // $list = \db()->query($sql);
  1209. // if (empty($list)){
  1210. // $this->success('未找到客户列表');
  1211. // }
  1212. // foreach ($list as $key=>$value){
  1213. // if (empty($value['客户编号'])){
  1214. // unset($list[$key]);
  1215. // }else{
  1216. // $list[$key]['客户编号'] = rtrim($value['客户编号']);
  1217. // $list[$key]['name'] = rtrim($value['客户编号']).'【'.$value['客户名称'].'】';
  1218. // if ($value['客户编号'] == '1098'){
  1219. // $list[$key]['客户名称'] = '打样专用';
  1220. // }
  1221. // }
  1222. // }
  1223. // $list = array_values($list);
  1224. // $this->success('成功',$list);
  1225. // }
  1226. /**
  1227. * 新增工单->产品代号获取
  1228. * @ApiMethod (GET)
  1229. * @param void
  1230. * @return void
  1231. * @throws \think\db\exception\DataNotFoundException
  1232. * @throws \think\db\exception\ModelNotFoundException
  1233. * @throws \think\exception\DbException
  1234. */
  1235. // public function ProductCodeList()
  1236. // {
  1237. // if ($this->request->isGet() === false){
  1238. // $this->error('请求错误');
  1239. // }
  1240. // $param = $this->request->param();
  1241. // if (isset($param['cilent']) === false){
  1242. // $this->error('参数错误');
  1243. // }
  1244. // $where = ['产品编号'=>['like',$param['cilent'].'%']];
  1245. // $list = \db('产品_基本资料')
  1246. // ->where($where)
  1247. // ->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
  1248. // ->select();
  1249. // if (empty($list)){
  1250. // $this->success('未获取到产品数据');
  1251. // }
  1252. // foreach ($list as $key=>$value){
  1253. // $list[$key]['name'] = $value['产品编号'].'【'.$value['产品名称'].'】';
  1254. // }
  1255. // $this->success('成功',$list);
  1256. // }
  1257. /**
  1258. * 新增印件资料->印件资料添加
  1259. * @return void
  1260. * @throws \think\db\exception\BindParamException
  1261. * @throws \think\exception\PDOException
  1262. */
  1263. public function PrintDetailAdd()
  1264. {
  1265. if (Request::instance()->isPost() === false){
  1266. $this->error('请求错误');
  1267. }
  1268. $param = Request::instance()->post();
  1269. if (empty($param)){
  1270. $this->error('参数错误');
  1271. }
  1272. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1273. $process = [
  1274. ['1','仓库出库'],['2','裁剪'],['3','车缝'],['4','后道收样'],['5','大烫'],['6','总检'],['7','包装']
  1275. ];
  1276. $processDetail = [];
  1277. foreach ($process as $key=>$value){
  1278. $total = null;
  1279. if ($key !== 0){
  1280. $total = $param['zdtotal'];
  1281. }
  1282. $processDetail[$key] = [
  1283. '订单编号' => $param['订单编号'],
  1284. '子订单编号' => $param['子订单编号'],
  1285. '款号' => $param['款号'],
  1286. '颜色' => $param['颜色'],
  1287. '颜色备注' => $param['颜色备注'],
  1288. '工序编号' => $value[0],
  1289. '工序名称' => $value[1],
  1290. '计划产量' => $total,
  1291. 'Sys_id' => $param['Sys_id'],
  1292. 'Sys_rq' => $param['Sys_rq']
  1293. ];
  1294. }
  1295. //开启事务
  1296. db()->startTrans();
  1297. try{
  1298. $priSql = \db('工单_印件资料')->fetchSql(true)->insert($param);
  1299. $priRes = \db()->query($priSql);
  1300. $proSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($processDetail);
  1301. $proRes = \db()->query($proSql);
  1302. // 提交事务
  1303. db()->commit();
  1304. } catch (\Exception $e) {
  1305. // 回滚事务
  1306. db()->rollback();
  1307. $this->error($e->getMessage());
  1308. }
  1309. if ($priRes !== false && $proRes !== false){
  1310. $this->success('成功');
  1311. }else{
  1312. $this->error('失败');
  1313. }
  1314. }
  1315. /**
  1316. * 新增工艺资料->工艺资料添加
  1317. * @return void
  1318. * @throws \think\db\exception\BindParamException
  1319. * @throws \think\exception\PDOException
  1320. */
  1321. // public function ProcessDetailAdd()
  1322. // {
  1323. // if (Request::instance()->isPost() === false){
  1324. // $this->error('请求错误');
  1325. // }
  1326. // $param = Request::instance()->post();
  1327. // if (empty($param)){
  1328. // $this->error('参数错误');
  1329. // }
  1330. // $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  1331. // if (empty($lastId)){
  1332. // $lastId = 0;
  1333. // }else{
  1334. // $lastId = $lastId + 1;
  1335. // }
  1336. // if (empty($param['Gy0_shdh'])){
  1337. // $param['Gy0_Rate0'] = 0;
  1338. // $param['Gy0_Rate1'] = 0;
  1339. // }else{
  1340. // $detail = \db('dic_lzsh')->field('sys_rate0,sys_rate1')->where('sys_bh',$param['Gy0_shdh'])->find();
  1341. // $param['Gy0_Rate0'] = $detail['sys_rate0'];
  1342. // $param['Gy0_Rate1'] = $detail['sys_rate1'];
  1343. // }
  1344. // $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1345. // $param['Mod_rq'] = '1900-01-01 00:00:00';
  1346. // $param['Gy0_sj1'] = '1900-01-01 00:00:00';
  1347. // $param['Gy0_sj2'] = '1900-01-01 00:00:00';
  1348. // $param['PD_WG'] = '1900-01-01 00:00:00';
  1349. // $param['UniqId'] = $lastId;
  1350. // $sql = \db('工单_工艺资料')
  1351. // ->fetchSql(true)
  1352. // ->insert($param);
  1353. // $res = \db()->query($sql);
  1354. // //获取平张投料
  1355. // $number = \db('工单_印件资料')
  1356. // ->where('Yj_Gdbh',$param['Gy0_gdbh'])
  1357. // ->where('yj_Yjno',$param['Gy0_yjno'])
  1358. // ->value('rtrim(yj_平张投料)');
  1359. // //分配工艺计划产量
  1360. // if ((int)$number >0){
  1361. // $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],$param['Gy0_gxh'],$number);
  1362. // }
  1363. // if ($res !== false){
  1364. // $this->success('成功');
  1365. // }else{
  1366. // $this->error('失败');
  1367. // }
  1368. //
  1369. // }
  1370. /**
  1371. * 新增工艺资料->印件编号获取
  1372. * @return void
  1373. * @throws \think\db\exception\DataNotFoundException
  1374. * @throws \think\db\exception\ModelNotFoundException
  1375. * @throws \think\exception\DbException
  1376. */
  1377. // public function PrintDetailList()
  1378. // {
  1379. // if ($this->request->isGet() === false){
  1380. // $this->error('请求错误');
  1381. // }
  1382. // $param = $this->request->param();
  1383. // if (empty($param)){
  1384. // $this->error('参数错误');
  1385. // }
  1386. // $printList = \db('工单_印件资料')
  1387. // ->where('Yj_Gdbh',$param['workOrder'])
  1388. // ->order('yj_Yjno')
  1389. // ->select();
  1390. // if (empty($printList)){
  1391. // $this->success('未找到该工单印件资料');
  1392. // }
  1393. // $list = [];
  1394. // foreach ($printList as $key=>$value){
  1395. // $list[$key]['name'] = rtrim($value['yj_Yjno']).'-->'.rtrim($value['yj_yjmc']);
  1396. // $list[$key]['no'] = rtrim($value['yj_Yjno']);
  1397. // }
  1398. // $this->success('成功',$list);
  1399. // }
  1400. /**
  1401. * 子订单列表
  1402. * @return null
  1403. * @throws \think\db\exception\DataNotFoundException
  1404. * @throws \think\db\exception\ModelNotFoundException
  1405. * @throws \think\exception\DbException
  1406. */
  1407. public function PrintListData()
  1408. {
  1409. // 检查请求方式
  1410. if ($this->request->isGet() === false) {
  1411. $this->error('请求错误');
  1412. }
  1413. $param = $this->request->param();
  1414. // 检查参数是否存在
  1415. if (isset($param) === false) {
  1416. $this->error('参数错误');
  1417. }
  1418. // 查询型号
  1419. $where['Mod_rq'] = null;
  1420. $xhdata = \db('工单_印件资料')
  1421. ->where('订单编号', $param['order'])
  1422. ->where($where)
  1423. ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  1424. ->select();
  1425. $arr = [];
  1426. // 收集cm1到cm10的非空非null值
  1427. foreach ($xhdata as $key => $value) {
  1428. for ($i = 1; $i <= 10; $i++) {
  1429. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  1430. array_push($arr, $value['cm' . $i]);
  1431. }
  1432. }
  1433. }
  1434. $arr = array_unique($arr);
  1435. sort($arr);
  1436. // 查询详细列表
  1437. $list = \db('工单_印件资料')
  1438. ->where('订单编号', $param['order'])
  1439. ->where($where)
  1440. ->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')
  1441. ->select();
  1442. // 遍历列表并处理cm和cmsl字段
  1443. foreach ($list as $key => $value) {
  1444. for ($i = 1; $i <= 10; $i++) {
  1445. if ($value['cm' . $i] !== '') {
  1446. // 如果 cmsl 的值为 0,则设置为空字符串
  1447. $list[$key][$value['cm' . $i]] = ($value['cmsl' . $i] === 0) ? '' : $value['cmsl' . $i];
  1448. }
  1449. // 删除原有的 cm 和 cmsl 字段
  1450. unset($list[$key]['cm' . $i], $list[$key]['cmsl' . $i]);
  1451. }
  1452. }
  1453. // 自定义型号排序
  1454. $customOrder = array('XS','S', 'M', 'L', 'XL','XXL', '2XL', '3XL', '4XL');
  1455. usort($arr, function ($a, $b) use ($customOrder) {
  1456. $posA = array_search($a, $customOrder);
  1457. $posB = array_search($b, $customOrder);
  1458. return $posA - $posB;
  1459. });
  1460. // 返回结果
  1461. $data['型号'] = $arr;
  1462. $data['列表'] = $list;
  1463. $this->success('成功', $data);
  1464. }
  1465. /**
  1466. * 工单资料管理->印件资料删除
  1467. * @return void
  1468. * @throws \think\Exception
  1469. * @throws \think\exception\PDOException
  1470. */
  1471. public function PrintDetailDel()
  1472. {
  1473. if ($this->request->isGet() === false){
  1474. $this->error('请求错误');
  1475. }
  1476. $param = $this->request->param();
  1477. if (isset($param['UniqId']) === false){
  1478. $this->error('参数错误');
  1479. }
  1480. $printId = explode(',',$param['UniqId']);
  1481. $i = 0;
  1482. foreach ($printId as $value){
  1483. $res = \db('工单_印件资料')
  1484. ->where('Uniqid',$value)
  1485. ->update(['Mod_rq'=>date('Y-m-d H:i:s',time())]);
  1486. if ($res === false){
  1487. $i++;
  1488. }
  1489. }
  1490. if ($i === 0){
  1491. $this->success('删除成功');
  1492. }else{
  1493. $this->error('删除失败');
  1494. }
  1495. }
  1496. /**
  1497. * 月度车间报工汇总->报工删除记录
  1498. */
  1499. public function ProcessDetailDel()
  1500. {
  1501. if ($this->request->isGet() === false){
  1502. $this->error('请求错误');
  1503. }
  1504. // $where['mod_rq'] = ['neq', ''];
  1505. // $list = \db('设备_产量计酬')->alias('c')
  1506. // ->field('c.订单编号,j.客户编号,c.mod_rq,c.delsys_id,c.款号,j.款式,,,,,,,,')
  1507. // ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
  1508. // ->where($where)
  1509. // ->order('c.mod_rq desc')
  1510. // ->select();
  1511. // echo "<pre>";
  1512. // print_r($list);
  1513. // echo "<pre>";
  1514. $where['a.mod_rq'] = ['neq', ''];
  1515. $list = \db('设备_产量计酬')->alias('a')
  1516. ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
  1517. ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
  1518. ->field('
  1519. b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数,b.颜色备注,
  1520. a.数量, a.sys_rq as 上报时间,a.UniqId,a.mod_rq,a.delsys_id,a.sczl_bh,
  1521. j.客户编号,j.生产款号,j.款式
  1522. ')
  1523. ->where($where)
  1524. ->order('a.mod_rq desc')
  1525. ->group('a.UniqId')
  1526. ->select();
  1527. // 提取所有的尺码,并去重
  1528. $sizeList = array_values(array_unique(array_column($list, '尺码')));
  1529. // 动态将尺码的数量添加到每个订单中,并替换已完成字段
  1530. foreach ($list as &$item) {
  1531. $size = $item['尺码'];
  1532. $item[$size] = $item['数量']; // 动态添加尺码字段,值为数量
  1533. // unset($item['数量']); // 移除原来的已完成字段
  1534. }
  1535. $data['total'] = count($list);
  1536. $data['table'] = $list;
  1537. $this->success('成功',$data);
  1538. }
  1539. /**
  1540. * 工艺资料添加->工序损耗代码
  1541. */
  1542. // public function WastageList()
  1543. // {
  1544. // if ($this->request->isGet() === false){
  1545. // $this->error('请求错误');
  1546. // }
  1547. // $param = $this->request->param();
  1548. // if (empty($param['process'])){
  1549. // $this->error('参数错误');
  1550. // }
  1551. // $order = \db('dic_lzsh')
  1552. // ->where('sys_mc','like',$param['process'].'%')
  1553. // ->value('rtrim(sys_bh) as 编号');
  1554. // $this->success('成功',$order);
  1555. // }
  1556. /**
  1557. * 获取产品附件列表
  1558. */
  1559. // public function getAnnexTable(){
  1560. // if(!$this->request->isGet()){
  1561. // $this->error('请求方式错误');
  1562. // }
  1563. // $req = $this->request->param();
  1564. // if (isset($req['cpdh']) && !empty($req['cpdh'])){
  1565. // $where['关联产品'] = ['LIKE','%'.$req['cpdh'].'%'];
  1566. // }else{
  1567. // $this->error('参数错误');
  1568. // }
  1569. // $rows = db('产品_技术附件')
  1570. // ->where($where)
  1571. // ->select();
  1572. // foreach ($rows as $key=>&$value){
  1573. // if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  1574. // $value['附件内容'] = '';
  1575. // }
  1576. // }
  1577. // $this->success('成功',$rows);
  1578. // }
  1579. /**
  1580. * 产品附件新增
  1581. */
  1582. // public function annexAdd(){
  1583. // if(!$this->request->isPost()){
  1584. // $this->error('请求方式错误');
  1585. // }
  1586. // $req = $this->request->param();
  1587. //
  1588. // $arr = [
  1589. // 'sys_id',
  1590. // '序号',
  1591. // '附件备注',
  1592. // '附件内容',
  1593. // '附件类型',
  1594. // '适用工序',
  1595. // '关联产品'
  1596. // ];
  1597. // $data = [];
  1598. // foreach ($arr as $key => $value){
  1599. // if (!isset($req[$value])){
  1600. // $this->error('参数错误',$value,$key+1);
  1601. // }
  1602. // $data[$value] = $req[$value];
  1603. // }
  1604. // $data['sys_rq'] = date('Y-m-d H:i:s');
  1605. //
  1606. // //开启事务
  1607. // db()->startTrans();
  1608. // try{
  1609. // $sql = db('产品_技术附件')->fetchSql(true)->insert($data);
  1610. // $bool = db()->query($sql);
  1611. // // 提交事务
  1612. // db()->commit();
  1613. // } catch (\Exception $e) {
  1614. // // 回滚事务
  1615. // db()->rollback();
  1616. // $this->error($e->getMessage());
  1617. // }
  1618. //
  1619. // if($bool===false) $this->error('失败');
  1620. //
  1621. // $this->success('成功');
  1622. // }
  1623. /**
  1624. * 产品附件修改
  1625. * @ApiMethod (GET)
  1626. * @param string 'UniqId'
  1627. */
  1628. // public function annexDel()
  1629. // {
  1630. // if(!$this->request->isGet()){
  1631. // $this->error('请求方式错误');
  1632. // }
  1633. // $req = $this->request->param();
  1634. //
  1635. // if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  1636. // $this->error('参数错误','UniqId',100);
  1637. // }
  1638. //
  1639. // //开启事务
  1640. // db()->startTrans();
  1641. // try{
  1642. // $bool = db('产品_技术附件')->where('UniqId',$req['UniqId'])->delete();
  1643. // // 提交事务
  1644. // db()->commit();
  1645. // } catch (\Exception $e) {
  1646. // // 回滚事务
  1647. // db()->rollback();
  1648. // $this->error($e->getMessage());
  1649. // }
  1650. //
  1651. // if($bool===false) $this->error('失败');
  1652. //
  1653. // $this->success('成功');
  1654. //
  1655. // }
  1656. /**
  1657. * 获取产品附件列表
  1658. */
  1659. // public function getGdAnnexTable(){
  1660. // if(!$this->request->isGet()){
  1661. // $this->error('请求方式错误');
  1662. // }
  1663. // $req = $this->request->param();
  1664. // if (isset($req['gdbh']) && !empty($req['gdbh'])){
  1665. // $where['关联编号'] = ['LIKE','%'.$req['gdbh'].'%'];
  1666. // }else{
  1667. // $this->error('参数错误');
  1668. // }
  1669. // $rows = db('工单_相关附件')
  1670. // ->where($where)
  1671. // ->select();
  1672. // foreach ($rows as $key=>&$value){
  1673. // if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  1674. // $value['附件内容'] = '';
  1675. // }
  1676. // }
  1677. // $this->success('成功',$rows);
  1678. // }
  1679. /**
  1680. * 产品附件新增
  1681. */
  1682. public function gdAnnexAdd(){
  1683. if(!$this->request->isPost()){
  1684. $this->error('请求方式错误');
  1685. }
  1686. // 获取请求参数
  1687. $req = $this->request->param();
  1688. // 检查附件备注是否为 '技术附件'
  1689. if (isset($req['附件备注']) && $req['附件备注'] === '技术附件') {
  1690. // 查询工单状态
  1691. $order = \db('工单_基本资料')->where('订单编号', $req['关联编号'])->find();
  1692. if ($order) {
  1693. // 如果工单状态不是 '2-生产中',则更新工单状态
  1694. if ($order['gd_statu'] !== '2-生产中') {
  1695. // 更新工单状态为 '2-生产中'
  1696. \db('工单_基本资料')->where('订单编号', $req['关联编号'])->update(['gd_statu' => '2-生产中']);
  1697. }
  1698. } else {
  1699. // 工单不存在时返回错误信息
  1700. return $this->error('订单不存在');
  1701. }
  1702. }
  1703. $arr = [
  1704. 'sys_id',
  1705. '附件备注',
  1706. '附件内容',
  1707. '附件类型',
  1708. '关联编号'
  1709. ];
  1710. $data = [];
  1711. foreach ($arr as $key => $value){
  1712. if (!isset($req[$value])){
  1713. $this->error('参数错误',$value,$key+1);
  1714. }
  1715. $data[$value] = $req[$value];
  1716. }
  1717. $data['sys_rq'] = date('Y-m-d H:i:s');
  1718. //检测目录是否存在
  1719. if(is_dir(ROOT_PATH.'public/uploads/'.$req['关联编号']) == null)
  1720. {
  1721. mkdir(ROOT_PATH.'public/uploads/'.$req['关联编号'],0777,true);
  1722. }
  1723. $base64Data = $req['附件内容'];
  1724. if (strpos($base64Data, 'base64,') !== false) {
  1725. $base64Data = explode('base64,', $base64Data)[1]; // 去掉前缀
  1726. }
  1727. // 解码 Base64 数据
  1728. $tempFileContent = base64_decode($base64Data);
  1729. // 创建一个临时文件
  1730. $tempFile = tempnam(sys_get_temp_dir(), 'excel_') . '.xlsx';
  1731. // 将解码后的内容写入临时文件
  1732. file_put_contents($tempFile, $tempFileContent);
  1733. // 加载 Excel 文件
  1734. $spreadsheet =IOFactory::load($tempFile);
  1735. //储存pdf地址
  1736. $address = '';
  1737. // 遍历每个工作表
  1738. foreach ($spreadsheet->getAllSheets() as $index => $sheet) {
  1739. // 创建新 Spreadsheet 对象,仅包含当前工作表
  1740. $pdfSpreadsheet = new Spreadsheet();
  1741. $pdfSpreadsheet->addExternalSheet($sheet);
  1742. // 设置 PDF 写入器
  1743. $pdfWriter = new Tcpdf($pdfSpreadsheet);
  1744. // 生成 PDF 文件名
  1745. $pdfFileName = 'output_sheet_' . ($index + 1) . '.pdf';
  1746. //设置保存地址
  1747. $pdfOutputPath = ROOT_PATH.'public/uploads/'.$req['关联编号'] . $pdfFileName;
  1748. // 保存到服务器指定目录
  1749. $pdfWriter->save($pdfOutputPath);
  1750. // 编辑pdf地址
  1751. $address = $pdfOutputPath.',' . $address;
  1752. }
  1753. // 清理临时文件
  1754. unlink($tempFile);;
  1755. //开启事务
  1756. db()->startTrans();
  1757. try{
  1758. $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  1759. $bool = db()->query($sql);
  1760. // 提交事务
  1761. db()->commit();
  1762. } catch (\Exception $e) {
  1763. // 回滚事务
  1764. db()->rollback();
  1765. $this->error($e->getMessage());
  1766. }
  1767. if($bool===false) $this->error('失败');
  1768. $this->success('成功');
  1769. }
  1770. /**
  1771. * 产品附件修改
  1772. * @ApiMethod (GET)
  1773. * @param string 'UniqId'
  1774. */
  1775. // public function gdAnnexDel()
  1776. // {
  1777. // if(!$this->request->isGet()){
  1778. // $this->error('请求方式错误');
  1779. // }
  1780. // $req = $this->request->param();
  1781. //
  1782. // if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  1783. // $this->error('参数错误','UniqId',100);
  1784. // }
  1785. //
  1786. // //开启事务
  1787. // db()->startTrans();
  1788. // try{
  1789. // $bool = db('工单_相关附件')->where('UniqId',$req['UniqId'])->delete();
  1790. // // 提交事务
  1791. // db()->commit();
  1792. // } catch (\Exception $e) {
  1793. // // 回滚事务
  1794. // db()->rollback();
  1795. // $this->error($e->getMessage());
  1796. // }
  1797. //
  1798. // if($bool===false) $this->error('失败');
  1799. //
  1800. // $this->success('成功');
  1801. //
  1802. // }
  1803. /**
  1804. * 引用工单资料数据查询
  1805. * @return void
  1806. * @throws \think\db\exception\DataNotFoundException
  1807. * @throws \think\db\exception\ModelNotFoundException
  1808. * @throws \think\exception\DbException
  1809. */
  1810. // public function WorkOrderDetailCope()
  1811. // {
  1812. // if ($this->request->isGet() === false){
  1813. // $this->error('请求错误');
  1814. // }
  1815. // $param = $this->request->param();
  1816. // if (empty($param['search'])){
  1817. // $this->error('参数错误');
  1818. // }
  1819. // $list = \Db('工单_基本资料')
  1820. // ->alias('a')
  1821. // ->field([
  1822. // 'rtrim(a.Gd_gdbh)' => '工单编号',
  1823. // 'rtrim(b.客户编号)' => '客户编号',
  1824. // 'rtrim(b.客户名称)' => '客户名称',
  1825. // 'rtrim(b.产品编号)' => '产品编号',
  1826. // 'rtrim(b.产品名称)' => '产品名称'
  1827. // ])
  1828. // ->join('产品_基本资料 b', 'a.成品代号 = b.产品编号')
  1829. // ->join('产品_工艺资料 c', 'a.成品代号 = c.Gy0_cpdh')
  1830. // ->join('产品_印件资料 d', 'a.成品代号 = d.yj_cpdh')
  1831. // ->where(function($query) use ($param) {
  1832. // $query->where('a.Gd_gdbh', 'like', '%'.$param['search'].'%')
  1833. // ->whereOr('a.成品名称', 'like', '%'.$param['search'].'%');
  1834. // })
  1835. // ->where(function($query) {
  1836. // $query->where('c.Gy0_cpdh', '<>', '')
  1837. // ->where('d.yj_cpdh', '<>', '')
  1838. // ->where('b.状态', 'not like', '%停用%')
  1839. // ->where('b.产品名称', 'not like', '%停用%');
  1840. // })
  1841. // ->group('a.Gd_gdbh')
  1842. // ->order('a.Uniqid desc')
  1843. // ->select();
  1844. // if (empty($list)){
  1845. // $this->success('未找到工单资料');
  1846. // }else{
  1847. // $this->success('成功',$list);
  1848. // }
  1849. // }
  1850. //
  1851. /**
  1852. * 引用产品印件、工艺资料
  1853. * @return void
  1854. * @throws \think\db\exception\BindParamException
  1855. * @throws \think\db\exception\DataNotFoundException
  1856. * @throws \think\db\exception\ModelNotFoundException
  1857. * @throws \think\exception\DbException
  1858. * @throws \think\exception\PDOException
  1859. */
  1860. // public function WorkOrderDetailListCope()
  1861. // {
  1862. // if (Request::instance()->isPost() === false){
  1863. // $this->error('请求错误');
  1864. // }
  1865. //
  1866. // $param = Request::instance()->post();
  1867. // if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
  1868. // $this->error('参数错误');
  1869. // }
  1870. // if (isset($param['sort'])){
  1871. // $priWhere['yj_yjno'] = ['>=',10];
  1872. // $proWhere['Gy0_yjno'] = ['>=',10];
  1873. // }else{
  1874. // $priWhere['yj_yjno'] = ['<',10];
  1875. // $proWhere['Gy0_yjno'] = ['<',10];
  1876. // }
  1877. // $list = \db('工单_基本资料')
  1878. // ->where('Gd_gdbh',$param['workorder'])
  1879. //// ->where('成品代号',$param['productCode'])
  1880. // ->field('行号,Gd_cpdh')
  1881. // ->select();
  1882. // //引用印件资料
  1883. // $PrintList = \db('产品_印件资料')
  1884. // ->where('yj_cpdh',$param['productCode'])
  1885. // ->where($priWhere)
  1886. // ->select();
  1887. // if (empty($PrintList)){
  1888. // $this->error('未找到印件资料');
  1889. // }
  1890. // $PrintLastId = \db('工单_印件资料')->order('Uniqid desc')->value('rtrim(Uniqid)');
  1891. // $number = \db('工单_基本资料')
  1892. // ->where('Gd_gdbh',$param['workorder'])
  1893. // ->where('成品代号',$param['productCode'])
  1894. // ->value('rtrim(计划投料)');
  1895. // $arr = [];
  1896. // foreach ($PrintList as $key => $value){
  1897. // foreach ($list as $k=>$v){
  1898. // if ($value['yj_yjdh'] === $v['Gd_cpdh']){
  1899. // $PrintList[$key]['Yj_Gdbh'] = $param['workorder'];
  1900. // $PrintList[$key]['yj_Yjno'] = $value['yj_yjno'];
  1901. // $PrintList[$key]['yj_Yjdh'] = $value['yj_yjdh'];
  1902. // $PrintList[$key]['yj_ks'] = $value['yj_ks'];
  1903. // $PrintList[$key]['yj_ls'] = $value['yj_ls'];
  1904. // $PrintList[$key]['yj_平张投料'] = $number;
  1905. // $PrintList[$key]['Sys_id'] = $value['sys_id'];
  1906. // $PrintList[$key]['Uniqid'] = $PrintLastId + $key + 1;
  1907. // $PrintList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  1908. // $PrintList[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  1909. // array_push($arr,[$value['yj_yjno'],$v['行号']]);
  1910. // }
  1911. // $sql = \db('工单_基本资料')
  1912. // ->where('Gd_gdbh',$param['workorder'])
  1913. // ->where('Gd_cpdh',$value['yj_yjdh'])
  1914. // ->fetchSql(true)
  1915. // ->update(['行号'=>$value['yj_yjno']]);
  1916. // \db()->query($sql);
  1917. // }
  1918. // 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']);
  1919. // }
  1920. // //引用工艺资料
  1921. // $processWhere = [
  1922. // 'Gy0_方案' => $param['option'],
  1923. // 'Gy0_cpdh' => $param['productCode']
  1924. // ];
  1925. // $ProcessList = \db('产品_工艺资料')
  1926. // ->where($processWhere)
  1927. // ->where($proWhere)
  1928. // ->order('Gy0_yjno,Gy0_gxh')
  1929. // ->select();
  1930. // if (empty($ProcessList)){
  1931. // $this->error('未找到产品工艺资料');
  1932. // }
  1933. // $ProcesslastId = \db('工单_工艺资料')->order('UniqId desc')->value('rtrim(UniqId)');
  1934. // foreach ($ProcessList as $key=>$value){
  1935. // if (empty(trim($value['Gy0_shdh']))){
  1936. // $rate['rate0'] = 0;
  1937. // $rate['rate1'] = 0;
  1938. // }else{
  1939. // $rate = \db('dic_lzsh')->where('sys_bh',$value['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  1940. // if (empty($rate)){
  1941. // $this->error('该产品印件号'.$value['Gy0_yjno'].'工序号为'.$value['gy0_gxmc'].'的损耗代号错误,请调整之后再引用');
  1942. // }
  1943. // }
  1944. // //设置默认机台
  1945. // $machineList = \db('设备_基本资料')
  1946. // ->where('生产工序','like','%'.$value['gy0_gxmc'].'%')
  1947. // ->order('设备编号')
  1948. // ->value('设备编号');
  1949. // $ProcessList[$key]['Gy0_sbbh'] = '';
  1950. // if (!empty($machineList)){
  1951. // $ProcessList[$key]['Gy0_sbbh'] = $machineList;
  1952. // }
  1953. // $ProcessList[$key]['Gy0_yjno'] = $value['Gy0_yjno'];
  1954. // $ProcessList[$key]['Gy0_gdbh'] = $param['workorder'];
  1955. // $ProcessList[$key]['Gy0_gxmc'] = $value['gy0_gxmc'];
  1956. // $ProcessList[$key]['Gy0_SITE'] = $value['Gy0_site'];
  1957. // $ProcessList[$key]['Gy0_shdh'] = $value['Gy0_shdh'];
  1958. // $ProcessList[$key]['Gy0_Rate0'] = $rate['rate0'];
  1959. // $ProcessList[$key]['Gy0_Rate1'] = $rate['rate1'];
  1960. // $ProcessList[$key]['Gy0_ks'] = $value['Gy0_Ks'];
  1961. // $ProcessList[$key]['Gy0_ms'] = $value['Gy0_Ms'];
  1962. // $ProcessList[$key]['Gy0_oil'] = $value['Gy0_Oil'];
  1963. // $ProcessList[$key]['Gy0_计划接货数'] = 0;
  1964. // $ProcessList[$key]['Gy0_计划损耗'] = 0;
  1965. // $ProcessList[$key]['无形损承担比例'] = 0;
  1966. // $ProcessList[$key]['超节损承担比例'] = 1;
  1967. // $ProcessList[$key]['超节损核算单价'] = 0;
  1968. // $ProcessList[$key]['Gy0_sj1'] = '1900-01-01 00:00:00';
  1969. // $ProcessList[$key]['Gy0_sj2'] = '1900-01-01 00:00:00';
  1970. // $ProcessList[$key]['UniqId'] = $ProcesslastId + $key + 1;
  1971. // $ProcessList[$key]['PD_WG'] = '1900-01-01 00:00:00';
  1972. // $ProcessList[$key]['Sys_rq'] = date('Y-m-d H:i:s', time());
  1973. // 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']);
  1974. // }
  1975. // //插入数据
  1976. // \db()->startTrans();
  1977. // try {
  1978. // \db('工单_工艺资料')->where('Gy0_gdbh',$param['workorder'])->delete();
  1979. // $processSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($ProcessList);
  1980. // \db()->query($processSql);
  1981. // \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->delete();
  1982. // $printSql = \db('工单_印件资料')->fetchSql(true)->insertAll($PrintList);
  1983. // \db()->query($printSql);
  1984. // \db()->commit();
  1985. // }catch (\Exception $e){
  1986. // \db()->rollback();
  1987. // }
  1988. // //计算工序计划生产数量
  1989. // if ($number !== null){
  1990. // $list = \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->field('yj_Yjno,yj_平张投料')->select();
  1991. // foreach ($list as $value){
  1992. // if ((int)$value['yj_平张投料'] >0){
  1993. // $this->PlannedProcessYield($param['workorder'],$value['yj_Yjno'],0,$value['yj_平张投料']);
  1994. // }
  1995. // }
  1996. // }
  1997. // $this->success('成功');
  1998. // }
  1999. /**
  2000. * 引用产品印件、工艺资料->信息获取
  2001. * @return void
  2002. * @throws \think\db\exception\DataNotFoundException
  2003. * @throws \think\db\exception\ModelNotFoundException
  2004. * @throws \think\exception\DbException
  2005. */
  2006. // public function ProductCopeDetail()
  2007. // {
  2008. // if ($this->request->isGet() === false){
  2009. // $this->error('请求错误');
  2010. // }
  2011. // $param = $this->request->param();
  2012. // if (empty($param['workorder'])){
  2013. // $this->error('参数错误');
  2014. // }
  2015. // $list = \db('工单_基本资料')
  2016. // ->alias('a')
  2017. // ->field([
  2018. // 'rtrim(a.Gd_gdbh)' => '工单编号',
  2019. // 'rtrim(b.客户编号)' => '客户编号',
  2020. // 'rtrim(b.客户名称)' => '客户名称',
  2021. // 'rtrim(b.产品编号)' => '产品编号',
  2022. // 'rtrim(b.产品名称)' => '产品名称'
  2023. // ])
  2024. // ->join('产品_基本资料 b','a.成品代号 = b.产品编号')
  2025. // ->where('a.Gd_gdbh',$param['workorder'])
  2026. // ->find();
  2027. // if (empty($list)){
  2028. // $this->error('未找到工单信息');
  2029. // }
  2030. // $option = \db('产品_工艺资料')
  2031. // ->field('rtrim(Gy0_方案) as 方案')
  2032. // ->where('Gy0_cpdh',$list['产品编号'])
  2033. // ->group('Gy0_方案')
  2034. // ->select();
  2035. // $list['方案'] = $option;
  2036. // $this->success('成功',$list);
  2037. // }
  2038. /**
  2039. * 工艺资料计划产量重新分配
  2040. * @param string $workOrder 工单
  2041. * @param int $yjno 印件号
  2042. * @param int $gxh 工序号
  2043. * @param int $feed 平张投料
  2044. * @return bool
  2045. * @throws \think\Exception
  2046. * @throws \think\db\exception\BindParamException
  2047. * @throws \think\db\exception\DataNotFoundException
  2048. * @throws \think\db\exception\ModelNotFoundException
  2049. * @throws \think\exception\DbException
  2050. * @throws \think\exception\PDOException
  2051. */
  2052. // public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
  2053. // {
  2054. // if ($gxh === 0){
  2055. // $where = [
  2056. // 'Gy0_gdbh'=>$workOrder,
  2057. // 'Gy0_yjno'=>$yjno,
  2058. // ];
  2059. // }else{
  2060. // $where = [
  2061. // 'Gy0_gdbh'=>$workOrder,
  2062. // 'Gy0_yjno'=>$yjno,
  2063. // 'Gy0_gxh'=>['>=',$gxh]
  2064. // ];
  2065. // }
  2066. // //获取工艺资料
  2067. // $processList = \db('工单_工艺资料')
  2068. // ->where($where)
  2069. // ->field('Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
  2070. // ->order('Gy0_gxh')
  2071. // ->select();
  2072. // if (empty($processList)){
  2073. // $this->success('未找到该工单工序资料');
  2074. // }
  2075. // //计算损耗定额和计划产量
  2076. // $production = [];
  2077. // $i = 0;
  2078. // foreach ($processList as $key=>$value){
  2079. // if ($key === 0){
  2080. // array_push($production,$feed);
  2081. // }
  2082. // $wastage = 0;
  2083. // if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
  2084. // $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
  2085. // }
  2086. //
  2087. // if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
  2088. // $wastage = round($wastage * $value['Gy0_ms']);
  2089. // }
  2090. // if ((int)$value['Gy0_ls'] === 1 && $key>=1){
  2091. // $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
  2092. // }else{
  2093. // $number = $production[$key];
  2094. // }
  2095. // if ($key>=1 && (int)$processList[$key-1]['Gy0_ls'] === 1 && (int)$value['Gy0_ls'] > 1){
  2096. // $number = $number/(int)$value['Gy0_ls'];
  2097. // }
  2098. // array_push($production,ceil($number-$wastage));
  2099. // $processSql = \db('工单_工艺资料')
  2100. // ->where('UniqId',$value['UniqId'])
  2101. // ->fetchSql(true)
  2102. // ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
  2103. // $res = \db()->query($processSql);
  2104. // if ($res === false){
  2105. // $i++;
  2106. // }
  2107. // }
  2108. // if ($i===0){
  2109. // return true;
  2110. // }else{
  2111. // return false;
  2112. // }
  2113. // }
  2114. /**
  2115. * 工单资料删除
  2116. * @return void
  2117. * @throws \think\exception\PDOException
  2118. */
  2119. // public function WorkOrderDel()
  2120. // {
  2121. // if ($this->request->isGet() === false){
  2122. // $this->error('请求错误');
  2123. // }
  2124. // $param = $this->request->param();
  2125. // if (isset($param['UniqId']) === false){
  2126. // $this->error('参数错误');
  2127. // }
  2128. // $WorkOrderId = explode(',',$param['UniqId']);
  2129. // $i = 0;
  2130. // foreach ($WorkOrderId as $key=>$value){
  2131. // //获取工单编号
  2132. // $workorder = \db('工单_基本资料')
  2133. // ->where('Uniqid',$value)
  2134. // ->value('rtrim(Gd_gdbh)');
  2135. // //删除工单资料、工艺资料、印件资料
  2136. // \db()->startTrans();
  2137. // try {
  2138. // \db('工单_基本资料')->where('Gd_gdbh',$workorder)->delete();
  2139. // if (!empty(\db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->find())){
  2140. // \db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->delete();
  2141. // }
  2142. // if (!empty(\db('工单_印件资料')->where('Yj_Gdbh',$workorder)->find())){
  2143. // \db('工单_印件资料')->where('Yj_Gdbh',$workorder)->delete();
  2144. // }
  2145. // if (!empty(\db('工单_bom资料')->where('BOM_工单编号',$workorder)->find())){
  2146. // \db('工单_bom资料')->where('BOM_工单编号',$workorder)->delete();
  2147. // }
  2148. // \db()->commit();
  2149. // }catch (\Exception $e){
  2150. // \db()->rollback();
  2151. // $i++;
  2152. // }
  2153. // }
  2154. // if ($i === 0){
  2155. // $this->success('删除成功');
  2156. // }else{
  2157. // $this->error('删除失败');
  2158. // }
  2159. // }
  2160. /**
  2161. * 修正核算参数-》工单产品信息获取
  2162. * @return void
  2163. * @throws \think\db\exception\DataNotFoundException
  2164. * @throws \think\db\exception\ModelNotFoundException
  2165. * @throws \think\exception\DbException
  2166. */
  2167. // public function ProductNameData()
  2168. // {
  2169. // if ($this->request->isGet() === false){
  2170. // $this->error('请求错误');
  2171. // }
  2172. // $workOrder = input('workOrder');
  2173. // if (empty($workOrder)){
  2174. // $this->error('参数错误');
  2175. // }
  2176. // $orderList = \db('工单_基本资料')
  2177. // ->field('rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称')
  2178. // ->where('Gd_gdbh',$workOrder)
  2179. // ->find();
  2180. // $this->success('成功',$orderList);
  2181. // }
  2182. /**
  2183. * 获取联数
  2184. * @return void
  2185. * @throws \think\db\exception\DataNotFoundException
  2186. * @throws \think\db\exception\ModelNotFoundException
  2187. * @throws \think\exception\DbException
  2188. */
  2189. // public function getCouplet()
  2190. // {
  2191. // if ($this->request->isGet() === false){
  2192. // $this->error('请求错误');
  2193. // }
  2194. // $param = $this->request->param();
  2195. // if (empty($param['gdbh']) || empty($param['yjno'])){
  2196. // $this->error('参数错误');
  2197. // }
  2198. // $list = \db('工单_印件资料')
  2199. // ->where('Yj_gdbh',$param['gdbh'])
  2200. // ->where('yj_Yjno',$param['yjno'])
  2201. // ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
  2202. // ->find();
  2203. // $process = \db('工单_工艺资料')
  2204. // ->where('Gy0_gdbh',$param['gdbh'])
  2205. // ->where('Gy0_yjno',$param['yjno'])
  2206. // ->order('Gy0_gxh desc')
  2207. // ->value('Gy0_gxh');
  2208. // $list['工序号'] = $process + 1;
  2209. // $this->success('成功',$list);
  2210. // }
  2211. public function orderPrint(){
  2212. if ($this->request->isGet() === false){$this->error('请求错误');}
  2213. $param = $this->request->param();
  2214. if (empty($param['order'])){$this->error('参数错误');}
  2215. //订单信息
  2216. $list = \db('工单_基本资料')
  2217. ->where('订单编号',$param['order'])
  2218. ->where('Mod_rq',null)
  2219. ->field('订单编号,img,生产款号,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,要求')
  2220. ->find();
  2221. //表格表头
  2222. $xhdata = \db('工单_印件资料')
  2223. ->where('订单编号',$param['order'])
  2224. ->where('Mod_rq',null)
  2225. ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  2226. ->select();
  2227. $arr = [];
  2228. foreach ($xhdata as $key => $value){
  2229. for($i=1;$i<=10;$i++){
  2230. if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2231. array_push($arr,$value['cm'.$i]);
  2232. }
  2233. }
  2234. }
  2235. $arr = array_unique($arr);
  2236. $where['Mod_rq'] = null;
  2237. $porlis = \db('工单_印件资料')
  2238. ->where('订单编号',$param['order'])
  2239. ->where('船样',0)
  2240. ->where($where)
  2241. ->field('子订单编号')
  2242. ->select();
  2243. $subOrder = $porlis[0]['子订单编号'];
  2244. // 找到子订单编号中的 '-' 位置
  2245. $dashPos = strpos($subOrder, '-');
  2246. if ($dashPos !== false) {
  2247. // 提取 '-' 后面的部分
  2248. $afterDash = substr($subOrder, $dashPos + 1);
  2249. // 判断长度是否等于2或等于4
  2250. if (strlen($afterDash) == 2) {
  2251. // // 查询船样为0的数据
  2252. // $processlist = \db('工单_印件资料')
  2253. // ->where('订单编号', $param['order'])
  2254. // ->where($where)
  2255. // ->where('船样', 0)
  2256. // ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  2257. // cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  2258. // cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  2259. // ->select();
  2260. //
  2261. // foreach ($processlist as $key => $value) {
  2262. // // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  2263. // for ($i = 1; $i <= 10; $i++) {
  2264. // if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  2265. // $processlist[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  2266. // }
  2267. // // 移除���始的 cm 和 cmsl 字段
  2268. // unset($processlist[$key]['cm' . $i], $processlist[$key]['cmsl' . $i]);
  2269. // }
  2270. // // 添加条码字段,值为子订单编号
  2271. // $processlist[$key]['条码'] = $value['子订单编号'];
  2272. // }
  2273. //
  2274. //// 用于存储合并后的数据
  2275. // $mergedData = [];
  2276. //
  2277. //// 按颜色备注进行合并
  2278. // foreach ($processlist as $item) {
  2279. // $key = $item['颜色备注'];
  2280. //
  2281. // if (!isset($mergedData[$key])) {
  2282. // $mergedData[$key] = $item;
  2283. // } else {
  2284. // // 合并尺码对应的数量
  2285. // foreach ($item as $size => $quantity) {
  2286. // if (is_numeric($size)) {
  2287. // if (!isset($mergedData[$key][$size])) {
  2288. // $mergedData[$key][$size] = 0;
  2289. // }
  2290. // $mergedData[$key][$size] += $quantity;
  2291. // }
  2292. // }
  2293. // // 合并 zdtotal
  2294. // $mergedData[$key]['zdtotal'] += $item['zdtotal'];
  2295. // }
  2296. // }
  2297. //
  2298. //// 将合并后的数据转换为索引数组
  2299. // $processlist = array_values($mergedData);
  2300. //
  2301. //// 如果有 0 的值,清空为 ''
  2302. // foreach ($processlist as &$row) {
  2303. // foreach ($row as $key => $value) {
  2304. // if ($value === 0) {
  2305. // $row[$key] = '';
  2306. // }
  2307. // }
  2308. // }
  2309. //
  2310. //// 对数组进行排序
  2311. // sort($processlist);
  2312. //
  2313. //// 自定义排序顺序
  2314. // $customOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL'];
  2315. // usort($processlist, function($a, $b) use ($customOrder) {
  2316. // $posA = array_search($a, $customOrder);
  2317. // $posB = array_search($b, $customOrder);
  2318. // return $posA - $posB;
  2319. // });
  2320. //
  2321. //// 查询船样为1的数据
  2322. // $chuanyang = \db('工单_印件资料')
  2323. // ->where('订单编号', $param['order'])
  2324. // ->where($where)
  2325. // ->where('船样', 1)
  2326. // ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  2327. // cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  2328. // cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  2329. // ->select();
  2330. //
  2331. // foreach ($chuanyang as $key => $value) {
  2332. // // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  2333. // for ($i = 1; $i <= 10; $i++) {
  2334. // if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  2335. // $chuanyang[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  2336. // }
  2337. // // 移除原始的 cm 和 cmsl 字段
  2338. // unset($chuanyang[$key]['cm' . $i], $chuanyang[$key]['cmsl' . $i]);
  2339. // }
  2340. // // 添加条码字段,值为子订单编号
  2341. // $chuanyang[$key]['条码'] = $value['子订单编号'];
  2342. // }
  2343. //
  2344. //// 将船样为1的数据添加到船样为0的数据后面
  2345. // $finalList = array_merge($processlist, $chuanyang);
  2346. //
  2347. // $data['process'] = $finalList;
  2348. // 查询船样为0的数据
  2349. $processlist = \db('工单_印件资料')
  2350. ->where('订单编号', $param['order'])
  2351. ->where($where)
  2352. ->where('船样', 0)
  2353. ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  2354. cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  2355. cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  2356. ->select();
  2357. foreach ($processlist as $key => $value) {
  2358. // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  2359. for ($i = 1; $i <= 10; $i++) {
  2360. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  2361. $processlist[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  2362. }
  2363. // 移除原始的 cm 和 cmsl 字段
  2364. unset($processlist[$key]['cm' . $i], $processlist[$key]['cmsl' . $i]);
  2365. }
  2366. }
  2367. // 用于存储合并后的数据
  2368. $mergedData = [];
  2369. // 按颜色备注进行合并
  2370. foreach ($processlist as $item) {
  2371. $key = $item['颜色备注'];
  2372. if (!isset($mergedData[$key])) {
  2373. $mergedData[$key] = $item;
  2374. // 添加条码字段,值为子订单编号
  2375. $mergedData[$key]['条码'] = $item['子订单编号'];
  2376. } else {
  2377. // 合并尺码对应的数量
  2378. foreach ($item as $size => $quantity) {
  2379. if (is_numeric($size)) {
  2380. if (!isset($mergedData[$key][$size])) {
  2381. $mergedData[$key][$size] = 0;
  2382. }
  2383. $mergedData[$key][$size] += $quantity;
  2384. }
  2385. }
  2386. // 合并 zdtotal
  2387. $mergedData[$key]['zdtotal'] += $item['zdtotal'];
  2388. }
  2389. }
  2390. // 查询船样为1的数据
  2391. $chuanyang = \db('工单_印件资料')
  2392. ->where('订单编号', $param['order'])
  2393. ->where($where)
  2394. ->where('船样', 1)
  2395. ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  2396. cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  2397. cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  2398. ->select();
  2399. foreach ($chuanyang as $key => $value) {
  2400. // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  2401. for ($i = 1; $i <= 10; $i++) {
  2402. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  2403. $chuanyang[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  2404. }
  2405. // 移除原始的 cm 和 cmsl 字段
  2406. unset($chuanyang[$key]['cm' . $i], $chuanyang[$key]['cmsl' . $i]);
  2407. }
  2408. // 添加条码字段,值为子订单编号
  2409. $chuanyang[$key]['条码'] = $value['子订单编号'];
  2410. }
  2411. // 将合并后的数据插入到相应颜色备注的原始数据尾部
  2412. $finalList = [];
  2413. $groupedData = [];
  2414. // 将原始数据按颜色备注分组
  2415. foreach ($processlist as $item) {
  2416. $key = $item['颜色备注'];
  2417. if (!isset($groupedData[$key])) {
  2418. $groupedData[$key] = [];
  2419. }
  2420. $groupedData[$key][] = $item;
  2421. }
  2422. // 将合并后的数据插入到对应的颜色备注组的尾部
  2423. foreach ($groupedData as $key => $items) {
  2424. $finalList = array_merge($finalList, $items); // 先添加原始数据
  2425. if (isset($mergedData[$key])) {
  2426. $finalList[] = $mergedData[$key]; // 在组的尾部添加合并数据
  2427. }
  2428. }
  2429. // 将船样为1的数据添加到最终列表中
  2430. $finalList = array_merge($finalList, $chuanyang);
  2431. // 最终数据结构
  2432. $data['process'] = $finalList;
  2433. $data['order'] = $list;
  2434. $data['xhdata'] = $arr;
  2435. $this->success('成功',$data);
  2436. } elseif (strlen($afterDash) == 4) {
  2437. // 获取印件资料
  2438. $processlist = \db('工单_印件资料')
  2439. ->where('订单编号', $param['order'])
  2440. ->where($where)
  2441. ->where('船样', 0)
  2442. ->field('子订单编号, 颜色, 款号, zdtotal, 颜色备注, color_id, 船样,
  2443. cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
  2444. cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
  2445. ->select();
  2446. // 保存格式化后的数据
  2447. $formattedData = [];
  2448. // 遍历数据进行尺码转换并添加到输出数组
  2449. foreach ($processlist as $item) {
  2450. for ($i = 1; $i <= 10; $i++) {
  2451. if (!empty($item['cm' . $i])) {
  2452. $item[$item['cm' . $i]] = $item['cmsl' . $i];
  2453. }
  2454. unset($item['cm' . $i], $item['cmsl' . $i]);
  2455. }
  2456. $formattedData[] = $item;
  2457. }
  2458. // 用于存储每个 color_id 和颜色备注的合并数据
  2459. $mergedData = [];
  2460. // 进行合并
  2461. foreach ($formattedData as $item) {
  2462. $key = $item['color_id'] . '|' . $item['颜色备注'];
  2463. if (!isset($mergedData[$key])) {
  2464. $mergedData[$key] = $item;
  2465. $mergedData[$key]['条码'] = $item['子订单编号']; // 初始化条码
  2466. } else {
  2467. // 合并 zdtotal 和尺码数量
  2468. $mergedData[$key]['zdtotal'] += $item['zdtotal'];
  2469. foreach (['36', '38', '40', '42', '44', '46', '48'] as $size) {
  2470. if (isset($item[$size])) {
  2471. $mergedData[$key][$size] = ($mergedData[$key][$size] ?? 0) + $item[$size];
  2472. }
  2473. }
  2474. // 优先选择以 "00" 结尾的条码
  2475. if (substr($item['子订单编号'], -2) == '00') {
  2476. $mergedData[$key]['条码'] = $item['子订单编号'];
  2477. }
  2478. }
  2479. }
  2480. // 将合并后的数据添加到原始数据的末尾,并排序
  2481. $finalOutput = $formattedData;
  2482. // 按 color_id 和 颜色备注 分组,并在每组末尾添加合并后的条码数据
  2483. foreach ($mergedData as $key => $mergeItem) {
  2484. $mergeItem['合并标记'] = true; // 用于标记这是合并后的数据
  2485. $finalOutput[] = $mergeItem;
  2486. }
  2487. // 对最终数组进行排序
  2488. usort($finalOutput, function($a, $b) {
  2489. // 先按 color_id 排序
  2490. $compare = strcmp($a['color_id'], $b['color_id']);
  2491. if ($compare === 0) {
  2492. // 在 color_id 相同的情况下,再按 颜色备注 排序
  2493. $compare = strcmp($a['颜色备注'], $b['颜色备注']);
  2494. if ($compare === 0) {
  2495. // 在 颜色备注相同的情况下,按 子订单编号 排序
  2496. // 如果一项是合并标记的条码数据,另一项不是,则合并标记的条码数据排在后面
  2497. if (isset($a['合并标记']) && !isset($b['合并标记'])) {
  2498. return 1;
  2499. } elseif (!isset($a['合并标记']) && isset($b['合并标记'])) {
  2500. return -1;
  2501. }
  2502. return strcmp($a['子订单编号'], $b['子订单编号']);
  2503. }
  2504. return $compare;
  2505. }
  2506. return $compare;
  2507. });
  2508. // 查询仅获取船样为 1 的数据
  2509. $chuanyang = \db('工单_印件资料')
  2510. ->where('订单编号', $param['order'])
  2511. ->where($where)
  2512. ->where('船样', 1)
  2513. ->field('子订单编号, 颜色, 款号, zdtotal, 颜色备注, color_id, 船样,
  2514. cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
  2515. cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
  2516. ->select();
  2517. $chuanyangvval = [];
  2518. // 遍历船样为 1 的数据,进行尺码转换
  2519. foreach ($chuanyang as $item) {
  2520. for ($i = 1; $i <= 10; $i++) {
  2521. if (!empty($item['cm' . $i])) {
  2522. $item[$item['cm' . $i]] = $item['cmsl' . $i];
  2523. }
  2524. unset($item['cm' . $i], $item['cmsl' . $i]);
  2525. }
  2526. $item['条码'] = $item['子订单编号'];
  2527. $chuanyangvval[] = $item;
  2528. }
  2529. // 合并船样和非船样的数据并去重
  2530. $final = array_map("unserialize", array_unique(array_map("serialize", array_merge($finalOutput, $chuanyangvval))));
  2531. // 最后清除带有条码的数据中的子订单编号和颜色信息
  2532. foreach ($final as &$item) {
  2533. if (isset($item['条码']) && $item['船样'] == 0) {
  2534. $item['子订单编号'] = '';
  2535. $item['颜色'] = '';
  2536. $item['款号'] = '';
  2537. unset($item['子订单编号'], $item['颜色']);
  2538. }
  2539. }
  2540. $data['process'] = $final;
  2541. $data['order'] = $list;
  2542. $data['xhdata'] = $arr;
  2543. $this->success('成功', $data);
  2544. } else {
  2545. echo "子订单编号 - 后不是2位也不是4位:$afterDash";
  2546. }
  2547. } else {
  2548. echo "子订单编号中没有找到'-'";
  2549. }
  2550. // $where['Mod_rq'] = null;
  2551. // $list = \db('工单_基本资料')
  2552. // ->where('订单编号',$param['order'])
  2553. // ->where($where)
  2554. // ->field('订单编号,img,生产款号,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,要求')
  2555. // ->find();
  2556. //
  2557. // //表格表头
  2558. // $xhdata = \db('工单_印件资料')
  2559. // ->where('订单编号',$param['order'])
  2560. // ->where('船样',0)
  2561. // ->where($where)
  2562. // ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  2563. // ->select();
  2564. // $arr = [];
  2565. // foreach ($xhdata as $key => $value){
  2566. // for($i=1;$i<=10;$i++){
  2567. // if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2568. // array_push($arr,$value['cm'.$i]);
  2569. // }
  2570. // }
  2571. // }
  2572. // $arr = array_unique($arr);
  2573. // $processlist = \db('工单_印件资料')
  2574. // ->where('订单编号', $param['order'])
  2575. // ->where($where)
  2576. // ->where('船样', 0)
  2577. // ->field('子订单编号, 颜色, 款号, zdtotal, 颜色备注, color_id,
  2578. // cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
  2579. // cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
  2580. // ->select();
  2581. // $mergedList = [];
  2582. // $summaryList = []; // 用于存储汇总数据
  2583. // foreach ($processlist as $item) {
  2584. // $colorId = $item['color_id'];
  2585. // $subOrderSuffix = substr($item['子订单编号'], -2);
  2586. //
  2587. // // 判断是否为汇总项(子订单编号后两位为 "00")
  2588. // if ($subOrderSuffix === '00') {
  2589. // // 初始化汇总数据
  2590. // $summaryList[$colorId] = [
  2591. // '子订单编号' => $item['子订单编号'],
  2592. // '条码' => $item['子订单编号'],
  2593. // '颜色' => $item['颜色'],
  2594. // '款号' => $item['款号'],
  2595. // 'zdtotal' => 0, // 累计总量
  2596. // '颜色备注' => $item['颜色备注'],
  2597. // 'color_id' => $colorId,
  2598. // 'cm1' => $item['cm1'],
  2599. // 'cm2' => $item['cm2'],
  2600. // 'cm3' => $item['cm3'],
  2601. // 'cm4' => $item['cm4'],
  2602. // 'cm5' => $item['cm5'],
  2603. // 'cm6' => $item['cm6'],
  2604. // 'cm7' => $item['cm7'],
  2605. // 'cm8' => $item['cm8'],
  2606. // 'cm9' => $item['cm9'],
  2607. // 'cm10' => $item['cm10'],
  2608. // 'cmsl1' => 0,
  2609. // 'cmsl2' => 0,
  2610. // 'cmsl3' => 0,
  2611. // 'cmsl4' => 0,
  2612. // 'cmsl5' => 0,
  2613. // 'cmsl6' => 0,
  2614. // 'cmsl7' => 0,
  2615. // 'cmsl8' => 0,
  2616. // 'cmsl9' => 0,
  2617. // 'cmsl10' => 0,
  2618. // ];
  2619. // }
  2620. //
  2621. // // 如果该 color_id 已经存在于汇总数组中,累加数量
  2622. // if (isset($summaryList[$colorId])) {
  2623. // $summaryList[$colorId]['cmsl1'] += $item['cmsl1'];
  2624. // $summaryList[$colorId]['cmsl2'] += $item['cmsl2'];
  2625. // $summaryList[$colorId]['cmsl3'] += $item['cmsl3'];
  2626. // $summaryList[$colorId]['cmsl4'] += $item['cmsl4'];
  2627. // $summaryList[$colorId]['cmsl5'] += $item['cmsl5'];
  2628. // $summaryList[$colorId]['cmsl6'] += $item['cmsl6'];
  2629. // $summaryList[$colorId]['cmsl7'] += $item['cmsl7'];
  2630. // $summaryList[$colorId]['cmsl8'] += $item['cmsl8'];
  2631. // $summaryList[$colorId]['cmsl9'] += $item['cmsl9'];
  2632. // $summaryList[$colorId]['cmsl10'] += $item['cmsl10'];
  2633. // $summaryList[$colorId]['zdtotal'] += $item['zdtotal'];
  2634. // }
  2635. //
  2636. // // 将原数据保留到结果数组中
  2637. // $mergedList[] = $item;
  2638. // }
  2639. //
  2640. //// 将汇总数据追加到结果数组中
  2641. // foreach ($summaryList as $summary) {
  2642. // $mergedList[] = $summary;
  2643. // }
  2644. // foreach ($mergedList as $key=>$value){
  2645. // for($i=1;$i<=10;$i++){
  2646. // if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2647. // $mergedList[$key][$value['cm'.$i]] = $value['cmsl'.$i];
  2648. // }
  2649. // unset($mergedList[$key]['cm'.$i],$mergedList[$key]['cmsl'.$i]);
  2650. // }
  2651. // }
  2652. // // 如果有0清空为 ''
  2653. // foreach ($mergedList as &$row) {
  2654. // foreach ($row as $key => $value) {
  2655. // if ($value === 0) {
  2656. // $row[$key] = '';
  2657. // }
  2658. // }
  2659. // }
  2660. //
  2661. // $data['order'] = $list;
  2662. // sort($arr);
  2663. // $data['xhdata'] = $arr;
  2664. // $data['process'] = $mergedList;
  2665. //
  2666. // $this->success('成功', $data);
  2667. }
  2668. // public function orderPrint()
  2669. // {
  2670. // if ($this->request->isGet() === false){
  2671. // $this->error('请求错误');
  2672. // }
  2673. // $param = $this->request->param();
  2674. // if (empty($param['order'])){
  2675. // $this->error('参数错误');
  2676. // }
  2677. //
  2678. // $wheres['Mod_rq'] = null;
  2679. //
  2680. // $porlis = \db('工单_印件资料')
  2681. // ->where('订单编号',$param['order'])
  2682. // ->where('船样',0)
  2683. // ->where($wheres)
  2684. // ->field('子订单编号')
  2685. // ->select();
  2686. //
  2687. // $subOrder = $porlis[0]['子订单编号'];
  2688. // // 找到子订单编号中的 '-' 位置
  2689. // $dashPos = strpos($subOrder, '-');
  2690. // if ($dashPos !== false) {
  2691. // // 提取 '-' 后面的部分
  2692. // $afterDash = substr($subOrder, $dashPos + 1);
  2693. // // 判断长度是否等于2或等于4
  2694. // if (strlen($afterDash) == 2) {
  2695. // $where['Mod_rq'] = null;
  2696. // $list = \db('工单_基本资料')
  2697. // ->where('订单编号',$param['order'])
  2698. // ->where($where)
  2699. // ->field('订单编号,img,生产款号,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,要求')
  2700. // ->find();
  2701. //
  2702. // //表格表头
  2703. // $xhdata = \db('工单_印件资料')
  2704. // ->where('订单编号',$param['order'])
  2705. // ->where('船样',0)
  2706. // ->where($where)
  2707. // ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  2708. // ->select();
  2709. // $arr = [];
  2710. // foreach ($xhdata as $key => $value){
  2711. // for($i=1;$i<=10;$i++){
  2712. // if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2713. // array_push($arr,$value['cm'.$i]);
  2714. // }
  2715. // }
  2716. // }
  2717. // $arr = array_unique($arr);
  2718. // //初始打印格式
  2719. // $processlist = \db('工单_印件资料')
  2720. // ->where('订单编号',$param['order'])
  2721. // ->where($where)
  2722. // ->where('船样',0)
  2723. // // ->where('子订单编号','like','%00')
  2724. // ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  2725. // cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  2726. // cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  2727. // ->select();
  2728. //
  2729. // if(!$processlist){
  2730. // $processlist = \db('工单_印件资料')
  2731. // ->where('订单编号',$param['order'])
  2732. // ->where('船样',0)
  2733. // ->where($where)
  2734. // ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  2735. // cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  2736. // cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  2737. // ->select();
  2738. // }
  2739. // foreach ($processlist as $key=>$value){
  2740. // for($i=1;$i<=10;$i++){
  2741. // if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2742. // $processlist[$key][$value['cm'.$i]] = $value['cmsl'.$i];
  2743. // }
  2744. // unset($processlist[$key]['cm'.$i],$processlist[$key]['cmsl'.$i]);
  2745. // }
  2746. // }
  2747. // // 如果有0清空为 ''
  2748. // foreach ($processlist as &$row) {
  2749. // foreach ($row as $key => $value) {
  2750. // if ($value === 0) {
  2751. // $row[$key] = '';
  2752. // }
  2753. // }
  2754. // }
  2755. // echo "<pre>";
  2756. // print_r($processlist);
  2757. // echo "<pre>";
  2758. // $data['order'] = $list;
  2759. // sort($arr);
  2760. // $data['xhdata'] = $arr;
  2761. // $data['process'] = $processlist;
  2762. // $this->success('成功',$data);
  2763. // } elseif (strlen($afterDash) == 4) {
  2764. // $where['Mod_rq'] = null;
  2765. // $list = \db('工单_基本资料')
  2766. // ->where('订单编号',$param['order'])
  2767. // ->where($where)
  2768. // ->field('订单编号,img,生产款号,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,要求')
  2769. // ->find();
  2770. //
  2771. // //表格表头
  2772. // $xhdata = \db('工单_印件资料')
  2773. // ->where('订单编号',$param['order'])
  2774. // ->where('船样',0)
  2775. // ->where($where)
  2776. // ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  2777. // ->select();
  2778. // $arr = [];
  2779. // foreach ($xhdata as $key => $value){
  2780. // for($i=1;$i<=10;$i++){
  2781. // if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2782. // array_push($arr,$value['cm'.$i]);
  2783. // }
  2784. // }
  2785. // }
  2786. // $arr = array_unique($arr);
  2787. // $processlist = \db('工单_印件资料')
  2788. // ->where('订单编号', $param['order'])
  2789. // ->where($where)
  2790. // ->where('船样', 0)
  2791. // ->field('子订单编号, 颜色, 款号, zdtotal, 颜色备注, color_id,
  2792. // cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
  2793. // cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
  2794. // ->select();
  2795. // $mergedList = [];
  2796. // $summaryList = []; // 用于存储汇总数据
  2797. // foreach ($processlist as $item) {
  2798. // $colorId = $item['color_id'];
  2799. // $subOrderSuffix = substr($item['子订单编号'], -2);
  2800. //
  2801. // // 判断是否为汇总项(子订单编号后两位为 "00")
  2802. // if ($subOrderSuffix === '00') {
  2803. // // 初始化汇总数据
  2804. // $summaryList[$colorId] = [
  2805. // '子订单编号' => $item['子订单编号'],
  2806. // '条码' => $item['子订单编号'],
  2807. // '颜色' => $item['颜色'],
  2808. // '款号' => $item['款号'],
  2809. // 'zdtotal' => 0, // 累计总量
  2810. // '颜色备注' => $item['颜色备注'],
  2811. // 'color_id' => $colorId,
  2812. // 'cm1' => $item['cm1'],
  2813. // 'cm2' => $item['cm2'],
  2814. // 'cm3' => $item['cm3'],
  2815. // 'cm4' => $item['cm4'],
  2816. // 'cm5' => $item['cm5'],
  2817. // 'cm6' => $item['cm6'],
  2818. // 'cm7' => $item['cm7'],
  2819. // 'cm8' => $item['cm8'],
  2820. // 'cm9' => $item['cm9'],
  2821. // 'cm10' => $item['cm10'],
  2822. // 'cmsl1' => 0,
  2823. // 'cmsl2' => 0,
  2824. // 'cmsl3' => 0,
  2825. // 'cmsl4' => 0,
  2826. // 'cmsl5' => 0,
  2827. // 'cmsl6' => 0,
  2828. // 'cmsl7' => 0,
  2829. // 'cmsl8' => 0,
  2830. // 'cmsl9' => 0,
  2831. // 'cmsl10' => 0,
  2832. // ];
  2833. // }
  2834. //
  2835. // // 如果该 color_id 已经存在于汇总数组中,累加数量
  2836. // if (isset($summaryList[$colorId])) {
  2837. // $summaryList[$colorId]['cmsl1'] += $item['cmsl1'];
  2838. // $summaryList[$colorId]['cmsl2'] += $item['cmsl2'];
  2839. // $summaryList[$colorId]['cmsl3'] += $item['cmsl3'];
  2840. // $summaryList[$colorId]['cmsl4'] += $item['cmsl4'];
  2841. // $summaryList[$colorId]['cmsl5'] += $item['cmsl5'];
  2842. // $summaryList[$colorId]['cmsl6'] += $item['cmsl6'];
  2843. // $summaryList[$colorId]['cmsl7'] += $item['cmsl7'];
  2844. // $summaryList[$colorId]['cmsl8'] += $item['cmsl8'];
  2845. // $summaryList[$colorId]['cmsl9'] += $item['cmsl9'];
  2846. // $summaryList[$colorId]['cmsl10'] += $item['cmsl10'];
  2847. // $summaryList[$colorId]['zdtotal'] += $item['zdtotal'];
  2848. // }
  2849. //
  2850. // // 将原数据保留到结果数组中
  2851. // $mergedList[] = $item;
  2852. // }
  2853. //
  2854. //// 将汇总数据追加到结果数组中
  2855. // foreach ($summaryList as $summary) {
  2856. // $mergedList[] = $summary;
  2857. // }
  2858. // foreach ($mergedList as $key=>$value){
  2859. // for($i=1;$i<=10;$i++){
  2860. // if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2861. // $mergedList[$key][$value['cm'.$i]] = $value['cmsl'.$i];
  2862. // }
  2863. // unset($mergedList[$key]['cm'.$i],$mergedList[$key]['cmsl'.$i]);
  2864. // }
  2865. // }
  2866. // // 如果有0清空为 ''
  2867. // foreach ($mergedList as &$row) {
  2868. // foreach ($row as $key => $value) {
  2869. // if ($value === 0) {
  2870. // $row[$key] = '';
  2871. // }
  2872. // }
  2873. // }
  2874. //
  2875. // $data['order'] = $list;
  2876. // sort($arr);
  2877. // $data['xhdata'] = $arr;
  2878. // $data['process'] = $mergedList;
  2879. //
  2880. // $this->success('成功', $data);
  2881. // } else {
  2882. // echo "子订单编号 - 后不是2位也不是4位:$afterDash";
  2883. // }
  2884. // } else {
  2885. // echo "子订单编号中没有找到'-'";
  2886. // }
  2887. //
  2888. //
  2889. //// $where['Mod_rq'] = null;
  2890. //// $list = \db('工单_基本资料')
  2891. //// ->where('订单编号',$param['order'])
  2892. //// ->where($where)
  2893. //// ->field('订单编号,img,生产款号,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,要求')
  2894. //// ->find();
  2895. ////
  2896. //// //表格表头
  2897. //// $xhdata = \db('工单_印件资料')
  2898. //// ->where('订单编号',$param['order'])
  2899. //// ->where('船样',0)
  2900. //// ->where($where)
  2901. //// ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  2902. //// ->select();
  2903. //// $arr = [];
  2904. //// foreach ($xhdata as $key => $value){
  2905. //// for($i=1;$i<=10;$i++){
  2906. //// if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2907. //// array_push($arr,$value['cm'.$i]);
  2908. //// }
  2909. //// }
  2910. //// }
  2911. //// $arr = array_unique($arr);
  2912. //
  2913. //// $processlist = \db('工单_印件资料')
  2914. //// ->where('订单编号', $param['order'])
  2915. //// ->where($where)
  2916. //// ->where('船样', 0)
  2917. //// ->field('子订单编号, 颜色, 款号, zdtotal, 颜色备注, color_id,
  2918. //// cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
  2919. //// cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
  2920. //// ->select();
  2921. //// $mergedList = [];
  2922. //// $summaryList = []; // 用于存储汇总数据
  2923. //// foreach ($processlist as $item) {
  2924. //// $colorId = $item['color_id'];
  2925. //// $subOrderSuffix = substr($item['子订单编号'], -2);
  2926. ////
  2927. //// // 判断是否为汇总项(子订单编号后两位为 "00")
  2928. //// if ($subOrderSuffix === '00') {
  2929. //// // 初始化汇总数据
  2930. //// $summaryList[$colorId] = [
  2931. //// '子订单编号' => $item['子订单编号'],
  2932. //// '条码' => $item['子订单编号'],
  2933. //// '颜色' => $item['颜色'],
  2934. //// '款号' => $item['款号'],
  2935. //// 'zdtotal' => 0, // 累计总量
  2936. //// '颜色备注' => $item['颜色备注'],
  2937. //// 'color_id' => $colorId,
  2938. //// 'cm1' => $item['cm1'],
  2939. //// 'cm2' => $item['cm2'],
  2940. //// 'cm3' => $item['cm3'],
  2941. //// 'cm4' => $item['cm4'],
  2942. //// 'cm5' => $item['cm5'],
  2943. //// 'cm6' => $item['cm6'],
  2944. //// 'cm7' => $item['cm7'],
  2945. //// 'cm8' => $item['cm8'],
  2946. //// 'cm9' => $item['cm9'],
  2947. //// 'cm10' => $item['cm10'],
  2948. //// 'cmsl1' => 0,
  2949. //// 'cmsl2' => 0,
  2950. //// 'cmsl3' => 0,
  2951. //// 'cmsl4' => 0,
  2952. //// 'cmsl5' => 0,
  2953. //// 'cmsl6' => 0,
  2954. //// 'cmsl7' => 0,
  2955. //// 'cmsl8' => 0,
  2956. //// 'cmsl9' => 0,
  2957. //// 'cmsl10' => 0,
  2958. //// ];
  2959. //// }
  2960. ////
  2961. //// // 如果该 color_id 已经存在于汇总数组中,累加数量
  2962. //// if (isset($summaryList[$colorId])) {
  2963. //// $summaryList[$colorId]['cmsl1'] += $item['cmsl1'];
  2964. //// $summaryList[$colorId]['cmsl2'] += $item['cmsl2'];
  2965. //// $summaryList[$colorId]['cmsl3'] += $item['cmsl3'];
  2966. //// $summaryList[$colorId]['cmsl4'] += $item['cmsl4'];
  2967. //// $summaryList[$colorId]['cmsl5'] += $item['cmsl5'];
  2968. //// $summaryList[$colorId]['cmsl6'] += $item['cmsl6'];
  2969. //// $summaryList[$colorId]['cmsl7'] += $item['cmsl7'];
  2970. //// $summaryList[$colorId]['cmsl8'] += $item['cmsl8'];
  2971. //// $summaryList[$colorId]['cmsl9'] += $item['cmsl9'];
  2972. //// $summaryList[$colorId]['cmsl10'] += $item['cmsl10'];
  2973. //// $summaryList[$colorId]['zdtotal'] += $item['zdtotal'];
  2974. //// }
  2975. ////
  2976. //// // 将原数据保留到结果数组中
  2977. //// $mergedList[] = $item;
  2978. //// }
  2979. ////
  2980. ////// 将汇总数据追加到结果数组中
  2981. //// foreach ($summaryList as $summary) {
  2982. //// $mergedList[] = $summary;
  2983. //// }
  2984. //// foreach ($mergedList as $key=>$value){
  2985. //// for($i=1;$i<=10;$i++){
  2986. //// if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2987. //// $mergedList[$key][$value['cm'.$i]] = $value['cmsl'.$i];
  2988. //// }
  2989. //// unset($mergedList[$key]['cm'.$i],$mergedList[$key]['cmsl'.$i]);
  2990. //// }
  2991. //// }
  2992. //// // 如果有0清空为 ''
  2993. //// foreach ($mergedList as &$row) {
  2994. //// foreach ($row as $key => $value) {
  2995. //// if ($value === 0) {
  2996. //// $row[$key] = '';
  2997. //// }
  2998. //// }
  2999. //// }
  3000. ////
  3001. //// $data['order'] = $list;
  3002. //// sort($arr);
  3003. //// $data['xhdata'] = $arr;
  3004. //// $data['process'] = $mergedList;
  3005. ////
  3006. //// $this->success('成功', $data);
  3007. //
  3008. //
  3009. // }
  3010. /**
  3011. * 订单编号自动获取
  3012. * @return void
  3013. * @throws \think\db\exception\DataNotFoundException
  3014. * @throws \think\db\exception\ModelNotFoundException
  3015. * @throws \think\exception\DbException
  3016. */
  3017. public function getWorkOrder()
  3018. {
  3019. if ($this->request->isGet() === false){
  3020. $this->error('请求错误');
  3021. }
  3022. $time =substr( date('Ym',time()),2);
  3023. $lastOrder = \db('工单_基本资料')
  3024. ->where('订单编号','like','%'.$time.'%')
  3025. ->order('Uniqid desc')
  3026. ->find();
  3027. if (empty($lastOrder)){
  3028. $newNumber = 1;
  3029. }else{
  3030. $lastNumber = substr($lastOrder['订单编号'],6);
  3031. $newNumber = (int)$lastNumber + 1;
  3032. }
  3033. if ($newNumber<10){
  3034. $newOrder = 'DC'.$time.'00'.$newNumber;
  3035. }elseif ($newNumber>=10 && $newNumber<100){
  3036. $newOrder = 'DC'.$time.'0'.$newNumber;
  3037. }else{
  3038. $newOrder = 'DC'.$time.$newNumber;
  3039. }
  3040. $this->success('成功',$newOrder);
  3041. }
  3042. /**
  3043. * 获取子订单编号
  3044. * @return void
  3045. * @throws \think\db\exception\DataNotFoundException
  3046. * @throws \think\db\exception\ModelNotFoundException
  3047. * @throws \think\exception\DbException
  3048. */
  3049. public function getSuborder(){
  3050. // 确保是GET请求
  3051. if ($this->request->isGet() === false) {
  3052. $this->error('请求错误');
  3053. }
  3054. $param = $this->request->param();
  3055. if (empty($param) || !isset($param['cy']) || !isset($param['order'])) {
  3056. $this->error('参数错误');
  3057. }
  3058. // 判断是否“船样”获取对应的子订单编号
  3059. if ($param['cy'] == '否') {
  3060. //1.通过色系名称查询对应的编号
  3061. $colorlist = \db('工单_颜色编号')
  3062. ->field('colorcode, colorname')
  3063. ->where('colorname', $param['colorname'] ?? '')
  3064. ->find();
  3065. if (empty($colorlist)) {
  3066. $this->error('未找到对应的颜色编号');
  3067. }
  3068. $num = $param['order'] . '-' . $colorlist['colorcode'];
  3069. // 查询子订单编号
  3070. $data = \db('工单_印件资料')
  3071. ->field('子订单编号,cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  3072. ->where('子订单编号', 'like', '%' . $num . '%')
  3073. ->where('船样', '=', 0)
  3074. ->order('子订单编号', 'desc')
  3075. ->find();
  3076. if (empty($data)) {
  3077. // 如果没有找到数据,生成默认的订单编号,后两位从00开始
  3078. $order = $param['order'] . '-' . $colorlist['colorcode'] . '00';
  3079. } else {
  3080. if (strlen($data['子订单编号']) == 12) {
  3081. $data = \db('工单_印件资料')
  3082. ->where('订单编号',$param['order'])
  3083. ->where('船样',0)
  3084. ->order('子订单编号 desc')
  3085. ->find();
  3086. if(empty($data)){
  3087. $order = $param['order'].'-01';
  3088. }else{
  3089. $num = (int)substr($data['子订单编号'],10) + 1;
  3090. if ($num<10){
  3091. $order = $param['order'].'-0'.$num;
  3092. }else{
  3093. $order = $param['order'].'-'.$num;
  3094. }
  3095. }
  3096. }else{
  3097. // 如果找到数据,提取子订单编号并递增
  3098. $order = $data['子订单编号'];
  3099. if (preg_match('/(.*-' . $colorlist['colorcode'] . ')(\d{2})$/', $order, $matches)) {
  3100. $prefix = $matches[1]; // 前缀部分(包括订单编号和颜色代码)
  3101. $number = $matches[2]; // 数字部分(后两位)
  3102. // 循环生成子订单编号并检查数据库中是否存在相同编号
  3103. do {
  3104. $incrementedNumber = (int)$number + 1;
  3105. // 将数字部分补充为两位数,例如 1 -> 01,2 -> 02
  3106. $order = $prefix . str_pad($incrementedNumber, 2, '0', STR_PAD_LEFT);
  3107. $exists = \db('工单_印件资料')->where('子订单编号', '=', $order)->find();
  3108. $number = $incrementedNumber; // 更新 number 用于下一次循环
  3109. } while ($exists); // 如果存在相同编号则继续循环递增
  3110. } else {
  3111. $this->error('订单编号格式错误');
  3112. }
  3113. }
  3114. }
  3115. //2.获取色系名称信息
  3116. $colorlist = \db('工单_颜色编号')->select();
  3117. //3.获取历史尺码数据
  3118. $cm_list = \db('工单_印件资料')
  3119. ->where('订单编号', $param['order'])
  3120. ->group('订单编号')
  3121. ->find();
  3122. $cm_data = [];
  3123. if ($cm_list) {
  3124. // 精准筛选字段名以 "cm" 开头并跟1到2位数字的字段
  3125. foreach ($cm_list as $key => $value) {
  3126. if (preg_match('/^cm\d{1,2}$/', $key)) {
  3127. $cm_data[$key] = $value ?? ''; // 如果值为 null,设为空字符串
  3128. }
  3129. }
  3130. } else {
  3131. // 如果查询结果为空,将 cm1 到 cm10 都设置为空
  3132. for ($i = 1; $i <= 10; $i++) {
  3133. $cm_data["cm$i"] = '';
  3134. }
  3135. }
  3136. $result = ['order' => $order,'colorlist' => $colorlist,'cm' => $cm_data];
  3137. $this->success('成功', $result);
  3138. } else if ($param['cy'] == '是') {
  3139. //1.获取船样子订单编号
  3140. $data = \db('工单_印件资料')
  3141. ->where('订单编号', $param['order'])
  3142. ->where('船样', '=', 1)
  3143. ->order('子订单编号 asc')
  3144. ->find();
  3145. if (empty($data)) {
  3146. // 如果没有数据,初始子订单编号为 '99'
  3147. $order = $param['order'] . '-99';
  3148. } else {
  3149. // 提取子订单编号中的数字部分
  3150. $subOrder = $data['子订单编号']; // 例如 "DC2410006-99"
  3151. if (preg_match('/-(\d+)$/', $subOrder, $matches)) {
  3152. $numberPart = (int)$matches[1]; // 提取到的数字部分
  3153. $newNumber = $numberPart - 1; // 减 1
  3154. // 将新的数字拼接回订单编号
  3155. $order = preg_replace('/-\d+$/', '-' . $newNumber, $subOrder);
  3156. } else {
  3157. $this->error('订单编号格式错误');
  3158. }
  3159. }
  3160. $this->success('成功', $order);
  3161. }
  3162. }
  3163. /**
  3164. * 获取PO号 【代码展示未用到】
  3165. */
  3166. public function getPonumber() {
  3167. if ($this->request->isGet() === false){
  3168. $this->error('请求错误');
  3169. }
  3170. $param = $this->request->param();
  3171. if (empty($param)){
  3172. $this->error('参数错误');
  3173. }
  3174. // $num = substr($param['child_order'], 0, 12); // 如果需要,可以用这个方式截取子订单编号
  3175. // $sql = "SELECT * FROM `工单_印件资料` WHERE `子订单编号` LIKE '{$num}%' ORDER BY `子订单编号` DESC LIMIT 1";
  3176. // $data = \db()->query($sql);
  3177. $colorlist = \db('工单_颜色编号')
  3178. ->field('colorcode,colorname')
  3179. ->where('colorname',$param['child_order'])
  3180. ->find();
  3181. $num = $param['order'] . '-' . $colorlist['colorcode']; // 生成 num,用于模糊查询
  3182. $data = \db('工单_印件资料')
  3183. ->where('子订单编号', 'like', '%' . $num . '%')
  3184. ->order('子订单编号', 'desc')
  3185. ->find();
  3186. if(count($data) === 1){
  3187. $order = $num.'01';
  3188. }else{
  3189. $number = (int)substr($data['子订单编号'],12,14) + 1;
  3190. if ($num<10){
  3191. $order = $num.'0'.$number;
  3192. }else{
  3193. $order = $num.$number;
  3194. }
  3195. }
  3196. $this->success('成功',$order);
  3197. }
  3198. /**
  3199. * 订单资料修改
  3200. * @return void
  3201. * @throws \think\Exception
  3202. * @throws \think\db\exception\BindParamException
  3203. * @throws \think\exception\PDOException
  3204. */
  3205. public function WorkOrderEdit()
  3206. {
  3207. if (Request::instance()->isPost() === false){
  3208. $this->error('请求错误');
  3209. }
  3210. $param = Request::instance()->post();
  3211. if (empty($param)){
  3212. $this->error('参数错误');
  3213. }
  3214. $id = $param['id'];
  3215. unset($param['id']);
  3216. $sql = \db('工单_基本资料')
  3217. ->where('Uniqid',$id)
  3218. ->fetchSql(true)
  3219. ->update($param);
  3220. $res = \db()->query($sql);
  3221. if ($res === false){
  3222. $this->error('失败');
  3223. }else{
  3224. $this->success('成功');
  3225. }
  3226. }
  3227. /**
  3228. * 颜色资料修改
  3229. * @return void
  3230. * @throws \think\Exception
  3231. * @throws \think\db\exception\BindParamException
  3232. * @throws \think\exception\PDOException
  3233. */
  3234. public function PrintDataEdit()
  3235. {
  3236. if(Request::instance()->post() === false){
  3237. $this->error('请求错误');
  3238. }
  3239. $param = Request::instance()->post();
  3240. if (empty($param)){
  3241. $this->error('参数错误');
  3242. }
  3243. // $id = $param['id'];
  3244. // unset($param['id']);
  3245. // $findlist = \db('工单_印件资料')
  3246. // ->where('Uniqid', $param['id'])
  3247. // ->find();
  3248. $updata = [
  3249. '订单编号' => $param['订单编号'],
  3250. '子订单编号' => $param['子订单编号'],
  3251. '款号' => $param['款号'],
  3252. '船样' => $param['船样'],
  3253. '颜色' => $param['颜色'],
  3254. 'color_id' => $param['color_id'],
  3255. '颜色备注' => $param['颜色备注'],
  3256. 'zdtotal' => $param['zdtotal']
  3257. ];
  3258. for ($i = 1; $i <= 10; $i++) {
  3259. $updata["cmsl{$i}"] = isset($param["cmsl{$i}"]) ? $param["cmsl{$i}"] : '';
  3260. }
  3261. $sql = \db('工单_印件资料')
  3262. ->where('Uniqid', $param['id'])
  3263. ->fetchSql(true)
  3264. ->update($updata);
  3265. $res = \db()->query($sql);
  3266. if ($res !== false) {
  3267. $this->success('修改成功');
  3268. } else {
  3269. $this->error('修改失败');
  3270. }
  3271. // $child_order = substr($param['子订单编号'],0,12);
  3272. // $list = \db('工单_印件资料')
  3273. // ->field('sum(cmsl1) as cmsl1,sum(cmsl2) as cmsl2,sum(cmsl3) as cmsl3,sum(cmsl4) as cmsl4
  3274. // ,sum(cmsl5) as cmsl5,sum(cmsl6) as cmsl6,sum(cmsl7) as cmsl7,sum(cmsl8) as cmsl8
  3275. // ,sum(cmsl9) as cmsl9,sum(cmsl10) as cmsl10')
  3276. // ->where('子订单编号','like',$child_order.'%')
  3277. // ->where('子订单编号','<>',$child_order.'00')
  3278. // ->where('Mod_rq',null)
  3279. // ->find();
  3280. // $num_sql = \db('工单_印件资料')->where('子订单编号',$child_order.'00')->fetchSql(true)->update($list);
  3281. // $result = \db()->query($num_sql);
  3282. // if ($res === false || $result === false){
  3283. // $this->error('修改失败');
  3284. // }else{
  3285. // $this->success('修改成功');
  3286. // }
  3287. // if(Request::instance()->post() === false){
  3288. // $this->error('请求错误');
  3289. // }
  3290. // $param = Request::instance()->post();
  3291. // if (empty($param)){
  3292. // $this->error('参数错误');
  3293. // }
  3294. // $id = $param['id'];
  3295. // unset($param['id']);
  3296. //
  3297. // $sql = \db('工单_印件资料')
  3298. // ->where('Uniqid',$id)
  3299. // ->fetchSql(true)
  3300. // ->update($param);
  3301. //
  3302. // $res = \db()->query($sql);
  3303. // $child_order = substr($param['子订单编号'],0,12);
  3304. // $list = \db('工单_印件资料')
  3305. // ->field('sum(cmsl1) as cmsl1,sum(cmsl2) as cmsl2,sum(cmsl3) as cmsl3,sum(cmsl4) as cmsl4
  3306. // ,sum(cmsl5) as cmsl5,sum(cmsl6) as cmsl6,sum(cmsl7) as cmsl7,sum(cmsl8) as cmsl8
  3307. // ,sum(cmsl9) as cmsl9,sum(cmsl10) as cmsl10')
  3308. // ->where('子订单编号','like',$child_order.'%')
  3309. // ->where('子订单编号','<>',$child_order.'00')
  3310. // ->where('Mod_rq',null)
  3311. // ->find();
  3312. // $num_sql = \db('工单_印件资料')->where('子订单编号',$child_order.'00')->fetchSql(true)->update($list);
  3313. // $result = \db()->query($num_sql);
  3314. // if ($res === false || $result === false){
  3315. // $this->error('修改失败');
  3316. // }else{
  3317. // $this->success('修改成功');
  3318. // }
  3319. }
  3320. /**
  3321. * 图片上传
  3322. * @return void
  3323. */
  3324. // public function ImgUpload(){
  3325. // $file = request()->file('image');
  3326. // if($file){
  3327. // $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
  3328. // if($info){
  3329. // $fileName = $info->getSaveName();
  3330. // $this->success('成功','public' . DS . 'uploads'. DS . $fileName);
  3331. // }else{
  3332. // $res = $file->getError();
  3333. // $this->error('失败',$res);
  3334. // }
  3335. // }
  3336. // }
  3337. public function ImgUpload(){
  3338. $file = request()->file('image');
  3339. if($file){
  3340. $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
  3341. if($info){
  3342. $fileName = $info->getSaveName();
  3343. $imageUrl = '/uploads/' . str_replace('\\', '/', $fileName);
  3344. return json(['code' => 0, 'msg' => '成功', 'data' => ['url' => $imageUrl]]);
  3345. }else{
  3346. $res = $file->getError();
  3347. return json(['code' => 1, 'msg' => '失败', 'data' => $res]);
  3348. }
  3349. }
  3350. return json(['code' => 1, 'msg' => '没有文件上传', 'data' => null]);
  3351. }
  3352. /**
  3353. * 工单技术附件
  3354. * @return void
  3355. * @throws \think\db\exception\DataNotFoundException
  3356. * @throws \think\db\exception\ModelNotFoundException
  3357. * @throws \think\exception\DbException
  3358. */
  3359. public function OrderAttachments()
  3360. {
  3361. if ($this->request->isGet() === false){
  3362. $this->error('请求错误');
  3363. }
  3364. $param = $this->request->param();
  3365. if (empty($param)){
  3366. $this->error('参数错误');
  3367. }
  3368. $list = \db('工单_相关附件')
  3369. ->where('关联编号',$param['order'])
  3370. ->where('附件备注',$param['desc'])
  3371. ->whereNull('Mod_rq')
  3372. ->order('sys_rq desc')
  3373. ->limit(1)
  3374. ->select();
  3375. $this->success('成功',$list);
  3376. }
  3377. }