WorkOrder.php 123 KB

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