WorkOrder.php 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292
  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. // if (Request::instance()->isPost() === false){
  1114. // $this->error('请求错误');
  1115. // }
  1116. // $param = Request::instance()->post();
  1117. // if (empty($param) || isset($param['UniqId']) === false){
  1118. // $this->error('参数错误');
  1119. // }
  1120. // // 获取修改前原始数据
  1121. // $oldData = \db('工单_工艺资料')
  1122. // ->where('UniqId', $param['UniqId'])
  1123. // ->find();
  1124. // //获取工单损耗代号数据
  1125. // if (empty($param['Gy0_shdh'])){
  1126. // $rate['rate0'] = 0;
  1127. // $rate['rate1'] = 0;
  1128. // }else{
  1129. // $rate = \db('dic_lzsh')->where('sys_bh',$param['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  1130. // }
  1131. // if ($param['备选工序'] == ''){
  1132. // $param['备选工序'] = null;
  1133. // }
  1134. // $param['Gy0_Rate0']= isset($rate['rate0'])?$rate['rate0']:0;
  1135. // $param['Gy0_Rate1'] = isset($rate['rate1'])?$rate['rate1']:0;
  1136. // $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  1137. // $UniqId = $param['UniqId'];
  1138. // unset($param['UniqId']);
  1139. // //获取工单第一道工艺编号
  1140. // $minGxh = \db('工单_工艺资料')->where('Gy0_gdbh',$param['Gy0_gdbh'])->column('min(Gy0_gxh) as gxh');
  1141. // //修改工艺资料
  1142. // $sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
  1143. // $res = \db()->query($sql);
  1144. // //获取工艺资料数据
  1145. // $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
  1146. // //如果是第一道工序需从印件资料中获取计划产量
  1147. // $list['计划接货数'] = \db('工单_印件资料')->where('Yj_Gdbh',$param['Gy0_gdbh'])->where('yj_Yjno',$param['Gy0_yjno'])->column('yj_平张投料')[0];
  1148. // //修改工单状态
  1149. // $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
  1150. // if ($status['status'] !== '2-生产中'){
  1151. // $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  1152. // Db::query($statusSql);
  1153. // }
  1154. // //重新分配工序计划产量
  1155. // if ((int)$list['计划接货数'] > 0){
  1156. // $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],0,$list['计划接货数']);
  1157. // }
  1158. // // 记录变更日志
  1159. // if ($res) {
  1160. // $newData = array_merge($oldData, $param); // 合并新旧数据
  1161. // $changes = [];
  1162. //
  1163. // // 动态对比所有参数字段(排除系统字段)
  1164. // $excludeFields = ['UniqId', 'Mod_rq'];
  1165. // foreach ($param as $field => $newValue) {
  1166. // if (in_array($field, $excludeFields)) continue;
  1167. //
  1168. // $oldValue = $oldData[$field] ?? 'NULL';
  1169. // if ($oldValue != $newValue) {
  1170. // $changes[] = [
  1171. // 'field' => $field,
  1172. // 'old' => $oldValue,
  1173. // 'new' => $newValue
  1174. // ];
  1175. // }
  1176. // }
  1177. //
  1178. // // 批量插入日志
  1179. // if (!empty($changes)) {
  1180. // $logData = [];
  1181. // foreach ($changes as $change) {
  1182. // $logData[] = [
  1183. // 'Gd_gdbh' => $oldData['Gy0_gdbh'],
  1184. // 'yjno' => $oldData['Gy0_yjno'],
  1185. // 'gxh' => $oldData['Gy0_gxh'],
  1186. // 'ModifyUser' => $param['Sys_id'],
  1187. // 'ModifyTime' => date('Y-m-d H:i:s'),
  1188. // 'FieldName' => $change['field'],
  1189. // 'OldValue' => $change['old'],
  1190. // 'NewValue' => $change['new'],
  1191. // 'ModifySource' => '工艺调整'
  1192. // ];
  1193. // }
  1194. // $logSql = \db('系统操作日志表')->fetchSql(true)->insertAll($logData);
  1195. // \db()->query($logSql);
  1196. // }
  1197. // }
  1198. // if ($res !== false){
  1199. // $this->success('成功');
  1200. // }else{
  1201. // $this->error('失败');
  1202. // }
  1203. // }
  1204. public function ProcessDetailEdit()
  1205. {
  1206. Db::startTrans();
  1207. try {
  1208. // 请求验证
  1209. if (!Request::instance()->isPost()) {
  1210. throw new Exception('非法请求方法');
  1211. }
  1212. $param = Request::instance()->post();
  1213. if (empty($param) || !isset($param['UniqId'])) {
  1214. throw new Exception('缺少必要参数');
  1215. }
  1216. $UniqId = $param['UniqId'];
  1217. // 获取原始数据(全字段)
  1218. $oldData = Db::name('工单_工艺资料')
  1219. ->where('UniqId', $UniqId)
  1220. ->find();
  1221. if (!$oldData) {
  1222. throw new Exception('目标数据不存在');
  1223. }
  1224. // 动态构建更新数据 --------------------------------------------------------
  1225. $updateData = [];
  1226. $logsData = [];
  1227. $systemFields = array('UniqId', 'Mod_rq'); // 显式声明数组
  1228. // 合并所有有效字段(PHP7.2兼容写法)
  1229. foreach ($param as $key => $value) {
  1230. if (!in_array($key, $systemFields)) {
  1231. $updateData[$key] = $value;
  1232. $logsData[$key] = $value;
  1233. }
  1234. }
  1235. // 处理业务逻辑字段
  1236. if (empty($param['Gy0_shdh'])) {
  1237. $updateData['Gy0_Rate0'] = 0;
  1238. $updateData['Gy0_Rate1'] = 0;
  1239. } else {
  1240. $rate = Db::name('dic_lzsh')
  1241. ->where('sys_bh', $param['Gy0_shdh'])
  1242. ->field('rtrim(sys_rate0) as rate0, rtrim(sys_rate1) as rate1')
  1243. ->find();
  1244. $rate = $rate ? $rate : array('rate0' => 0, 'rate1' => 0);
  1245. $updateData['Gy0_Rate0'] = $rate['rate0'];
  1246. $updateData['Gy0_Rate1'] = $rate['rate1'];
  1247. }
  1248. // 添加系统字段
  1249. $updateData['Mod_rq'] = date('Y-m-d H:i:s');
  1250. // 执行全字段更新(PHP7.2兼容的回调函数)-----------------------------------
  1251. $rawSql = Db::name('工单_工艺资料')
  1252. ->where('UniqId', $UniqId)
  1253. ->fetchSql(true)
  1254. ->update($updateData);
  1255. // 中文字段安全处理(传统匿名函数写法)
  1256. $safeSql = preg_replace_callback(
  1257. '/`([\x{4e00}-\x{9fa5}]+)`/u',
  1258. function($matches) {
  1259. return '`' . addslashes($matches[1]) . '`';
  1260. },
  1261. $rawSql
  1262. );
  1263. // 执行并验证
  1264. $affected = Db::execute($safeSql);
  1265. if ($affected < 0) {
  1266. throw new Exception('数据库执行失败');
  1267. }
  1268. // 记录全字段变更日志 -----------------------------------------------------
  1269. $changes = array();
  1270. foreach ($logsData as $field => $newValue) {
  1271. $oldValue = isset($oldData[$field]) ? $oldData[$field] : 'NULL';
  1272. // 严格值比较(PHP7.2兼容的类型转换)
  1273. if ((string)$oldValue !== (string)$newValue) {
  1274. $changes[] = array(
  1275. 'field' => $field,
  1276. 'old' => $oldValue,
  1277. 'new' => $newValue
  1278. );
  1279. }
  1280. }
  1281. if (!empty($changes)) {
  1282. $logs = array();
  1283. foreach ($changes as $change) {
  1284. $logs[] = array(
  1285. 'Gd_gdbh' => $oldData['Gy0_gdbh'],
  1286. 'yjno' => $oldData['Gy0_yjno'],
  1287. 'gxh' => $oldData['Gy0_gxh'],
  1288. 'ModifyUser' => $param['Sys_id'],
  1289. 'ModifyTime' => date('Y-m-d H:i:s'),
  1290. 'FieldName' => $change['field'],
  1291. 'OldValue' => $change['old'],
  1292. 'NewValue' => $change['new'],
  1293. 'ModifySource' => '工艺调整'
  1294. );
  1295. }
  1296. Db::name('系统操作日志表')->insertAll($logs);
  1297. }
  1298. //获取工单第一道工艺编号
  1299. $minGxh = \db('工单_工艺资料')->where('Gy0_gdbh',$param['Gy0_gdbh'])->column('min(Gy0_gxh) as gxh');
  1300. //获取工艺资料数据
  1301. $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
  1302. //如果是第一道工序需从印件资料中获取计划产量
  1303. $list['计划接货数'] = \db('工单_印件资料')->where('Yj_Gdbh',$param['Gy0_gdbh'])->where('yj_Yjno',$param['Gy0_yjno'])->column('yj_平张投料')[0];
  1304. //修改工单状态
  1305. $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
  1306. if ($status['status'] !== '2-生产中'){
  1307. $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  1308. Db::query($statusSql);
  1309. }
  1310. //重新分配工序计划产量
  1311. if ((int)$list['计划接货数'] > 0){
  1312. $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],0,$list['计划接货数']);
  1313. }
  1314. Db::commit();
  1315. $this->success('操作成功');
  1316. } catch (Exception $e) {
  1317. Db::rollback();
  1318. $this->error($e->getMessage());
  1319. }
  1320. }
  1321. /**
  1322. * 工艺资料编辑->机台列表获取
  1323. * @return void
  1324. * @throws \think\db\exception\DataNotFoundException
  1325. * @throws \think\db\exception\ModelNotFoundException
  1326. * @throws \think\exception\DbException
  1327. */
  1328. public function MachineList()
  1329. {
  1330. if ($this->request->isGet() === false){
  1331. $this->error('请求错误');
  1332. }
  1333. $param = $this->request->param();
  1334. if (empty($param)){
  1335. $this->error('参数错误');
  1336. }
  1337. $list = \db('设备_基本资料')
  1338. ->where('使用部门',$param['address'])
  1339. ->where('sys_sbID','<>','')
  1340. ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
  1341. ->order('设备编组,设备编号')
  1342. ->select();
  1343. if (empty($list)){
  1344. $this->success('未找到该车间机台');
  1345. }
  1346. $data = [];
  1347. foreach ($list as $key=>$value){
  1348. $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
  1349. }
  1350. $this->success('成功',$data);
  1351. }
  1352. /**
  1353. * 打印作业通知单->工单印件和工序获取
  1354. * @ApiMethod (GET)
  1355. * @return void
  1356. * @throws \think\db\exception\DataNotFoundException
  1357. * @throws \think\db\exception\ModelNotFoundException
  1358. * @throws \think\exception\DbException
  1359. */
  1360. public function PrintCodeList()
  1361. {
  1362. if ($this->request->isGet() === false){
  1363. $this->error('请求错误');
  1364. }
  1365. $param = $this->request->param();
  1366. if (empty($param)){
  1367. $this->error('参数错误');
  1368. }
  1369. $list = \db('工单_印件资料')
  1370. ->field([
  1371. 'rtrim(yj_Yjno)' => '印件号',
  1372. 'rtrim(yj_yjmc)' => '印件名称'
  1373. ])
  1374. ->where('Yj_Gdbh',$param['workOrder'])
  1375. ->select();
  1376. $this->success('成功',$list);
  1377. }
  1378. /**
  1379. * 打印作业通知单->工艺编号获取
  1380. * @ApiMethod (GET)
  1381. * @return void
  1382. * @throws \think\db\exception\DataNotFoundException
  1383. * @throws \think\db\exception\ModelNotFoundException
  1384. * @throws \think\exception\DbException
  1385. */
  1386. public function ProcessCodeList()
  1387. {
  1388. if ($this->request->isGet() === false){
  1389. $this->error('请求错误');
  1390. }
  1391. $param = $this->request->param();
  1392. if (empty($param)){
  1393. $this->error('参数错误');
  1394. }
  1395. $list = \db('工单_工艺资料')
  1396. ->field('rtrim(Gy0_gxh) as 工序号')
  1397. ->where([
  1398. 'Gy0_gdbh' => $param['workOrder'],
  1399. 'Gy0_yjno' => $param['yjno']
  1400. ])
  1401. ->select();
  1402. $this->success('成功',$list);
  1403. }
  1404. /**
  1405. * 打印作业通知单
  1406. * @ApiMethod (POST)
  1407. * @param void
  1408. * @return void
  1409. * @throws \think\db\exception\DataNotFoundException
  1410. * @throws \think\db\exception\ModelNotFoundException
  1411. * @throws \think\exception\DbException
  1412. */
  1413. public function PrintJobOrder()
  1414. {
  1415. if ($this->request->isGet() === false) {
  1416. $this->error('请求错误');
  1417. }
  1418. $param = $this->request->param();
  1419. if (empty($param)){
  1420. $this->error('参数错误');
  1421. }
  1422. $data = $this->workOrderDetailGet($param['workOrder'],$param['yjno']);
  1423. if (empty($data)){
  1424. $this->success('未找到工单信息');
  1425. }
  1426. $materiel = $this->MaterielDetailGet($param['workOrder']);
  1427. $printDetail = $this->PrintDetailGet($param['workOrder'],$param['yjno'],$param['gxh']);
  1428. if (empty($printDetail)){
  1429. $this->success('未找到工艺信息');
  1430. }
  1431. $number = 0;
  1432. foreach ($printDetail as $key=>$value){
  1433. $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
  1434. $number = $number+$value['允损比例'];
  1435. }
  1436. $data['制单'] = $param['PrepareDocument'];
  1437. $data['审核'] = $param['examine'];
  1438. $data['目标合格率'] = 100-$number.'%';
  1439. $data['materiel'] = $materiel;
  1440. $data['printDetail'] = $printDetail;
  1441. $this->success('成功',$data);
  1442. }
  1443. /**
  1444. * 打印作业通知单->工单及印件资料获取
  1445. * @param $workOrder
  1446. * @return mixed
  1447. */
  1448. public function workOrderDetailGet($workOrder,$yjno)
  1449. {
  1450. $sql = "SELECT
  1451. RTRIM( a.Gd_lx) AS 工单类型,
  1452. RTRIM( a.Gd_gdbh ) AS 生产批次号,
  1453. RTRIM( a.销售订单号 ) AS 销售订单号,
  1454. RTRIM( a.Gd_客户代号 ) AS 客户代号,
  1455. RTRIM( a.Gd_客户名称 ) AS 客户名称,
  1456. RTRIM( a.成品代号 ) AS 产品代码,
  1457. RTRIM( a.成品名称 ) AS 产品名称,
  1458. RTRIM( a.产品版本号 ) AS 版本号,
  1459. RTRIM( a.警语版面 ) AS 警语版面,
  1460. RTRIM( a.码源数量 ) AS 码源数量,
  1461. RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
  1462. RTRIM( a.接单日期 ) AS 开单日期,
  1463. RTRIM( a.交货日期 ) AS 交货日期,
  1464. RTRIM( a.Gd_desc ) AS 工单说明,
  1465. RTRIM( a.投料率 ) AS 投料率,
  1466. RTRIM( a.订单数量 ) AS 订单数量,
  1467. RTRIM( a.平均合格率 ) AS 平均合格率,
  1468. RTRIM( a.投料大箱 ) AS 订货数量,
  1469. RTRIM( a.排产时库存 ) AS 排产时库存,
  1470. RTRIM( b.yj_Yjno ) AS 印件,
  1471. RTRIM( b.yj_Yjdh ) AS 印件代号,
  1472. RTRIM( b.yj_yjmc ) AS 印件名称,
  1473. RTRIM( b.yj_平张投料 ) AS 平张投料量,
  1474. RTRIM( b.yj_zzmc ) AS 纸张名称,
  1475. RTRIM( b.yj_tlgg ) AS 投料规格,
  1476. RTRIM( b.yj_ks ) AS 开数,
  1477. RTRIM( b.yj_ls ) AS 联数,
  1478. RTRIM( b.yj_desc ) AS 印件备注
  1479. FROM
  1480. `工单_基本资料` AS a
  1481. JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh
  1482. WHERE
  1483. a.Gd_gdbh = '{$workOrder}' AND b.yj_Yjno = '{$yjno}'";
  1484. $list = Db::query($sql);
  1485. if (empty($list)){
  1486. $this->success('未找到订单数据');
  1487. }
  1488. $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
  1489. $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
  1490. if (strpos($list[0]['产品名称'],'条') !== false){
  1491. $list[0]['订货数量'] = (int)$list[0]['订单数量']*40;
  1492. $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/250);
  1493. }else{
  1494. $list[0]['订货数量'] = (int)$list[0]['订单数量']*4;
  1495. $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/2500);
  1496. }
  1497. $list[0]['联数'] = (int)$list[0]['联数'];
  1498. $list[0]['印件代号及名称'] = $list[0]['印件代号'].' '.$list[0]['印件名称'];
  1499. // $list[0]['投料数量'] = $list[0]['订货数量'];
  1500. unset($list[0]['印件代号'],$list[0]['印件名称']);
  1501. return($list[0]);
  1502. }
  1503. /**打印作业流程单->物料资料获取
  1504. * @param $workOrder
  1505. * @return bool|\PDOStatement|string|\think\Collection
  1506. * @throws \think\db\exception\DataNotFoundException
  1507. * @throws \think\db\exception\ModelNotFoundException
  1508. * @throws \think\exception\DbException
  1509. */
  1510. public function MaterielDetailGet($workOrder)
  1511. {
  1512. $where = [
  1513. 'BOM_工单编号' => $workOrder,
  1514. ];
  1515. $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
  1516. $list = \db('工单_bom资料')->where($where)->field($filed)->select();
  1517. if (!empty($list)){
  1518. foreach ($list as $key=>$value){
  1519. $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
  1520. $list[$key]['计划用量'] = (float)$value['计划用量'];
  1521. unset($list[$key]['物料编码'],$list[$key]['物料名称']);
  1522. }
  1523. }
  1524. return $list;
  1525. }
  1526. /**
  1527. * 打印作业流程单->工艺资料获取
  1528. * @param $workOrder
  1529. * @return bool|\PDOStatement|string|\think\Collection
  1530. * @throws \think\db\exception\DataNotFoundException
  1531. * @throws \think\db\exception\ModelNotFoundException
  1532. * @throws \think\exception\DbException
  1533. */
  1534. public function PrintDetailGet($workOrder,$yjno,$gxh)
  1535. {
  1536. $where = [
  1537. 'Gy0_gdbh' => $workOrder,
  1538. 'Gy0_yjno' => $yjno,
  1539. 'Gy0_gxh' => ['<=',$gxh]
  1540. ];
  1541. $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  1542. rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
  1543. rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
  1544. $list = \db('工单_工艺资料')
  1545. ->where($where)
  1546. ->field($filed)
  1547. ->select();
  1548. if (empty($list)){
  1549. $this->success('工单工艺为空');
  1550. }
  1551. foreach ($list as $key=>$value){
  1552. if ($value['yjno']<10){
  1553. $value['yjno'] = '0'.$value['yjno'];
  1554. }
  1555. if ($value['gxh']<10){
  1556. $value['gxh'] = '0'.$value['gxh'];
  1557. }
  1558. if ($value['add_gxmc'] !== null){
  1559. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  1560. }else{
  1561. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  1562. }
  1563. $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
  1564. $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
  1565. if ((int)$value['计划接货数'] === 0){
  1566. $list[$key]['允损比例'] = 0;
  1567. }else{
  1568. $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
  1569. }
  1570. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
  1571. }
  1572. return $list;
  1573. }
  1574. /**
  1575. * 获取小时产能
  1576. * @ApiMethod (GET)
  1577. * @param void
  1578. * @return void
  1579. * @throws \think\db\exception\DataNotFoundException
  1580. * @throws \think\db\exception\ModelNotFoundException
  1581. * @throws \think\exception\DbException
  1582. */
  1583. public function capacityList()
  1584. {
  1585. if ($this->request->isGet() === false){
  1586. $this->error('请求错误');
  1587. }
  1588. $param = $this->request->param();
  1589. if (empty($param)){
  1590. $this->error('参数错误');
  1591. }
  1592. $machine = explode(' ',$param['machine'])[0];
  1593. $number = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(排单小时定额) as 小时产能')->find();
  1594. if (empty($number)){
  1595. $this->error('未找到小时产能');
  1596. }
  1597. $this->success('成功',$number['小时产能']);
  1598. }
  1599. /**
  1600. * 新增工单->添加工单
  1601. * @ApiMethod (POST)
  1602. * @param
  1603. * @return void
  1604. * @throws \think\Exception
  1605. * @throws \think\db\exception\BindParamException
  1606. * @throws \think\db\exception\DataNotFoundException
  1607. * @throws \think\db\exception\ModelNotFoundException
  1608. * @throws \think\exception\DbException
  1609. * @throws \think\exception\PDOException
  1610. */
  1611. public function WorkOrderAdd()
  1612. {
  1613. if (Request::instance()->isPost() === false){
  1614. $this->error('请求错误');
  1615. }
  1616. $param = Request::instance()->post();
  1617. if (empty($param)){
  1618. $this->error('参数错误');
  1619. }
  1620. if (isset($param['sort'])){
  1621. $sort = 2;
  1622. unset($param['sort']);
  1623. }else{
  1624. $sort = 1;
  1625. }
  1626. $num = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->count();
  1627. //插入产品资料
  1628. $productData = \db('产品_基本资料')
  1629. ->where('产品编号',$param['cpdh'])
  1630. ->count();
  1631. if ($productData === 0) {
  1632. $clientCode = substr($param['cpdh'], 0, 5);
  1633. $product = [
  1634. '客户编号' => $clientCode,
  1635. '客户名称' => $param['khmc'],
  1636. '产品编号' => $param['cpdh'],
  1637. '产品名称' => $param['cpmc'],
  1638. '计量单位' => '万张',
  1639. '状态' => '',
  1640. 'Mod_rq' => date('Y-m-d H:i:s', time()),
  1641. 'UniqID' => \db('产品_基本资料')->order('UniqID desc')->value('UniqID') + 1,
  1642. ];
  1643. if (strpos($product['产品名称'], '小盒') === false) {
  1644. $product['产品类别'] = '条盒';
  1645. } else {
  1646. $product['产品类别'] = '小盒';
  1647. }
  1648. $productSql = \db('产品_基本资料')->fetchSql(true)->insert($product);
  1649. \db()->query($productSql);
  1650. }
  1651. //添加工单
  1652. $productDetail = \db('产品_基本资料')->where('产品编号',$param['cpdh'])->find();
  1653. if (empty($productDetail)){
  1654. $productDetail['客户料号'] = '';
  1655. }
  1656. $lastId = \db('工单_基本资料')->order('Uniqid desc')->value('Uniqid');
  1657. $data = [
  1658. 'Gd_lx' =>$param['zdgd'],
  1659. 'Gd_生产分类' =>$param['sclx'],
  1660. '成本处理类别' =>'',
  1661. 'Gd_gdbh' =>$param['gdbh'],
  1662. '行号' =>$num+1 ,
  1663. 'Gd_客户代号' =>$param['khdh'],
  1664. 'Gd_客户名称' =>$param['khmc'],
  1665. 'Gd_khdh' =>$param['khdh'],
  1666. 'Gd_khmc' =>$param['khmc'],
  1667. '客户料号' =>rtrim($productDetail['客户料号']),
  1668. '客户ERP编码' =>$param['erp'],
  1669. 'Gd_cpdh' =>'',
  1670. 'Gd_cpmc' =>'',
  1671. '成品代号' =>$param['cpdh'],
  1672. '成品名称' =>$param['cpmc'],
  1673. '产品版本号' =>$param['bbh'],
  1674. '销售订单号' =>$param['xsddh'],
  1675. '警语版面' =>$param['jybm'],
  1676. '码源数量' =>$param['mysl'],
  1677. '排产时库存' =>$param['kcdx'],
  1678. '投料大箱' =>$param['tldx'],
  1679. '投料率' =>$param['tll'],
  1680. '平均合格率' =>$param['hgl'],
  1681. '进程备注' =>$param['jcbz'],
  1682. 'Gd_desc' =>$param['remark'],
  1683. '开单日期' =>date('Y-m-d H:i:s',time()),
  1684. '接单日期' =>$param['start'],
  1685. '交货日期' =>$param['end'],
  1686. '订单数量' =>$param['number'],
  1687. '计量单位' =>$param['tldw'],
  1688. '计划投料' =>$param['pztl'],
  1689. '实际投料' =>$param['wxz'],
  1690. '产品单价' =>0,
  1691. '入仓日期' =>'1900-01-01 00:00:00',
  1692. '工单入仓数量' =>0,
  1693. '工单制程废品' => 0,
  1694. '工单质检废品' => 0,
  1695. '工单无形损' => 0,
  1696. '工单计划损耗' => 0,
  1697. '工单完工日期' => $param['end'],
  1698. '投料确认' => '',
  1699. 'gd_statu' => '3-计划中',
  1700. '直接人工' => 0,
  1701. '分摊人工' => 0,
  1702. '直接材料' => 0,
  1703. '考核直接材料' => 0,
  1704. '分摊材料' => 0,
  1705. '考核分摊材料' => 0,
  1706. '直接折旧' => 0,
  1707. '水电气费' => 0,
  1708. '分摊空调' => 0,
  1709. '分摊锅炉' => 0,
  1710. '分摊废气处理' => 0,
  1711. '分摊空压机' => 0,
  1712. '分摊鼓风机' => 0,
  1713. '分摊其他' => 0,
  1714. '待摊人工' => 0,
  1715. '待摊折旧' => 0,
  1716. '待摊场地租金' => 0,
  1717. '待摊其他费用' => 0,
  1718. '加工费' => 0,
  1719. '加工费单价' => 0,
  1720. '成本考核_胶印' => 1,
  1721. '成本考核_凹印' => 1,
  1722. '成本考核_丝印' => 1,
  1723. '成本考核_模切' => 1,
  1724. '成本考核_检验' => 1,
  1725. '印版费' => 0,
  1726. 'V23制造成本' => 0,
  1727. 'Prt_rq' => date('Y-m-d H:i:s',time()),
  1728. 'Sys_id' => $param['Sys_id'],
  1729. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  1730. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  1731. 'U8UID' => '',
  1732. 'Uniqid' => $lastId+1,
  1733. '工序加工费' => 0,
  1734. '工单分类' => $sort,
  1735. ];
  1736. $sql= \db('工单_基本资料')->fetchSql(true)->insert($data);
  1737. $res = \db()->query($sql);
  1738. //创建日志数据
  1739. $logs = array(
  1740. 'Gd_gdbh' => $data['Gd_gdbh'],
  1741. 'ModifyUser' => $param['Sys_id'],
  1742. 'ModifyTime' => date('Y-m-d H:i:s'),
  1743. 'ModifySource' => '工单添加'
  1744. );
  1745. \db('系统操作日志表')->insert($logs);
  1746. if ($res !== false){
  1747. $this->success('成功');
  1748. }else{
  1749. $this->error('失败');
  1750. }
  1751. }
  1752. /**
  1753. * 新增工单->客户代号列表获取
  1754. * @return void
  1755. * @throws \think\db\exception\BindParamException
  1756. * @throws \think\exception\PDOException
  1757. */
  1758. public function ClientList()
  1759. {
  1760. if ($this->request->isGet() === false){
  1761. $this->error('请求错误');
  1762. }
  1763. $param = $this->request->param();
  1764. if (isset($param['search'])){
  1765. $where = $param['search'].'%';
  1766. $sql = "SELECT DISTINCT
  1767. (客户编号),rtrim(客户名称 ) as 客户名称
  1768. FROM
  1769. `产品_基本资料`
  1770. WHERE
  1771. 客户编号 LIKE "."'".$where."'"."
  1772. OR
  1773. 客户名称 LIKE "."'".$where."'"."
  1774. GROUP BY
  1775. 客户编号
  1776. order by
  1777. 客户编号";
  1778. }else{
  1779. $sql = "SELECT DISTINCT
  1780. (客户编号),rtrim(客户名称 ) as 客户名称
  1781. FROM
  1782. `产品_基本资料`
  1783. GROUP BY
  1784. 客户编号
  1785. order by
  1786. 客户编号";
  1787. }
  1788. $list = \db()->query($sql);
  1789. if (empty($list)){
  1790. $this->success('未找到客户列表');
  1791. }
  1792. foreach ($list as $key=>$value){
  1793. if (empty($value['客户编号'])){
  1794. unset($list[$key]);
  1795. }else{
  1796. $list[$key]['客户编号'] = rtrim($value['客户编号']);
  1797. $list[$key]['name'] = rtrim($value['客户编号']).'【'.$value['客户名称'].'】';
  1798. if ($value['客户编号'] == '1098'){
  1799. $list[$key]['客户名称'] = '打样专用';
  1800. }
  1801. }
  1802. }
  1803. $list = array_values($list);
  1804. $this->success('成功',$list);
  1805. }
  1806. /**
  1807. * 新增工单->产品代号获取
  1808. * @ApiMethod (GET)
  1809. * @param void
  1810. * @return void
  1811. * @throws \think\db\exception\DataNotFoundException
  1812. * @throws \think\db\exception\ModelNotFoundException
  1813. * @throws \think\exception\DbException
  1814. */
  1815. public function ProductCodeList()
  1816. {
  1817. if ($this->request->isGet() === false){
  1818. $this->error('请求错误');
  1819. }
  1820. $param = $this->request->param();
  1821. if (isset($param['cilent']) === false){
  1822. $this->error('参数错误');
  1823. }
  1824. $where = ['产品编号'=>['like',$param['cilent'].'%']];
  1825. $list = \db('产品_基本资料')
  1826. ->where($where)
  1827. ->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
  1828. ->limit(50)
  1829. ->select();
  1830. if (empty($list)){
  1831. $this->success('未获取到产品数据');
  1832. }
  1833. $res = db('产品_工艺资料')->where('Gy0_cpdh',$list[0]['产品编号'])->distinct(true)->column('rtrim(Gy0_方案) as gy_plan');
  1834. $list[0]['gy'] = $res;
  1835. foreach ($list as $key=>$value){
  1836. $list[$key]['name'] = $value['产品编号'].'【'.$value['产品名称'].'】';
  1837. $list[$key]['yj'] = db('产品_印件资料')->where('yj_cpdh',$value['产品编号'])->column('yj_yjno');
  1838. }
  1839. $this->success('成功',$list);
  1840. }
  1841. /**
  1842. * 新增印件资料->印件资料添加
  1843. * @return void
  1844. * @throws \think\db\exception\BindParamException
  1845. * @throws \think\exception\PDOException
  1846. */
  1847. public function PrintDetailAdd()
  1848. {
  1849. if (Request::instance()->isPost() === false){
  1850. $this->error('请求错误');
  1851. }
  1852. $param = Request::instance()->post();
  1853. if (empty($param)){
  1854. $this->error('参数错误');
  1855. }
  1856. $lastId = \db('工单_印件资料')->order('Uniqid desc')->value('Uniqid');
  1857. if (empty($lastId)){
  1858. $lastId = 0;
  1859. }else{
  1860. $lastId = $lastId + 1;
  1861. }
  1862. $param['Uniqid'] = $lastId;
  1863. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1864. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  1865. //判断印件号是否存在在工单基本资料表中,存在不增加行号,不存在增加行号
  1866. if (empty(\db('工单_基本资料')->where('Gd_gdbh',$param['Yj_Gdbh'])->where('行号',$param['yj_Yjno'])->find())){
  1867. $list = \db('工单_基本资料')->where('Gd_gdbh',$param['Yj_Gdbh'])->find();
  1868. $list['行号'] = $param['yj_Yjno'];
  1869. $list['Gd_cpdh'] = $param['yj_Yjdh'];
  1870. $list['Gd_cpmc'] = $param['yj_yjmc'];
  1871. $list['Sys_id'] = $param['Sys_id'];
  1872. $list['Sys_rq'] = $param['Sys_rq'];
  1873. $list['Mod_rq'] = $param['Mod_rq'];
  1874. unset($list['Uniqid']);
  1875. $workSql = \db('工单_基本资料')->fetchSql(true)->insert($list);
  1876. }else{
  1877. $data['Gd_cpdh'] = $param['yj_Yjdh'];
  1878. $data['Gd_cpmc'] = $param['yj_yjmc'];
  1879. $workSql = \db('工单_基本资料')
  1880. ->where('Gd_gdbh',$param['Yj_Gdbh'])
  1881. ->where('行号',$param['yj_Yjno'])
  1882. ->fetchSql(true)
  1883. ->update($data);
  1884. }
  1885. //开启事务
  1886. Db::startTrans();
  1887. try{
  1888. $sql = \db('工单_印件资料')->fetchSql(true)->insert($param);
  1889. $res = \db()->query($sql);
  1890. $workRes = \db()->query($workSql);
  1891. //提交事务
  1892. \db()->commit();
  1893. } catch (\Exception $e) {
  1894. // 回滚事务
  1895. \db()->rollback();
  1896. }
  1897. if ($res !== false && $workRes !== false){
  1898. $this->success('成功');
  1899. }else{
  1900. $this->error('失败');
  1901. }
  1902. }
  1903. /**
  1904. * 新增工艺资料->工艺资料添加
  1905. * @return void
  1906. * @throws \think\db\exception\BindParamException
  1907. * @throws \think\exception\PDOException
  1908. */
  1909. public function ProcessDetailAdd()
  1910. {
  1911. if (Request::instance()->isPost() === false){
  1912. $this->error('请求错误');
  1913. }
  1914. $param = Request::instance()->post();
  1915. if (empty($param)){
  1916. $this->error('参数错误');
  1917. }
  1918. $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  1919. if (empty($lastId)){
  1920. $lastId = 0;
  1921. }else{
  1922. $lastId = $lastId + 1;
  1923. }
  1924. if (empty($param['Gy0_shdh'])){
  1925. $param['Gy0_Rate0'] = 0;
  1926. $param['Gy0_Rate1'] = 0;
  1927. }else{
  1928. $detail = \db('dic_lzsh')->field('sys_rate0,sys_rate1')->where('sys_bh',$param['Gy0_shdh'])->find();
  1929. $param['Gy0_Rate0'] = $detail['sys_rate0'];
  1930. $param['Gy0_Rate1'] = $detail['sys_rate1'];
  1931. }
  1932. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1933. $param['Mod_rq'] = '1900-01-01 00:00:00';
  1934. $param['Gy0_sj1'] = '1900-01-01 00:00:00';
  1935. $param['Gy0_sj2'] = '1900-01-01 00:00:00';
  1936. $param['PD_WG'] = '1900-01-01 00:00:00';
  1937. $param['UniqId'] = $lastId;
  1938. //添加工序
  1939. $sql = \db('工单_工艺资料')
  1940. ->fetchSql(true)
  1941. ->insert($param);
  1942. $res = \db()->query($sql);
  1943. //获取平张投料
  1944. $number = \db('工单_印件资料')
  1945. ->where('Yj_Gdbh',$param['Gy0_gdbh'])
  1946. ->where('yj_Yjno',$param['Gy0_yjno'])
  1947. ->value('rtrim(yj_平张投料)');
  1948. //分配工艺计划产量
  1949. if ((int)$number >0){
  1950. $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],0,$number);
  1951. }
  1952. //操作日志数据
  1953. $logs = array(
  1954. 'Gd_gdbh' => $param['Gy0_gdbh'],
  1955. 'yjno' => $param['Gy0_yjno'],
  1956. 'gxh' => $param['Gy0_gxh'],
  1957. 'ModifyUser' => $param['Sys_id'],
  1958. 'ModifyTime' => date('Y-m-d H:i:s'),
  1959. 'ModifySource' => '工艺新增'
  1960. );
  1961. \db('系统操作日志表')->insert($logs);
  1962. if ($res !== false){
  1963. $this->success('成功');
  1964. }else{
  1965. $this->error('失败');
  1966. }
  1967. }
  1968. /**
  1969. * 新增工艺资料->印件编号获取
  1970. * @return void
  1971. * @throws \think\db\exception\DataNotFoundException
  1972. * @throws \think\db\exception\ModelNotFoundException
  1973. * @throws \think\exception\DbException
  1974. */
  1975. public function PrintDetailList()
  1976. {
  1977. if ($this->request->isGet() === false){
  1978. $this->error('请求错误');
  1979. }
  1980. $param = $this->request->param();
  1981. if (empty($param)){
  1982. $this->error('参数错误');
  1983. }
  1984. $printList = \db('工单_印件资料')
  1985. ->where('Yj_Gdbh',$param['workOrder'])
  1986. ->order('yj_Yjno')
  1987. ->select();
  1988. if (empty($printList)){
  1989. $this->success('未找到该工单印件资料');
  1990. }
  1991. $list = [];
  1992. foreach ($printList as $key=>$value){
  1993. $list[$key]['name'] = rtrim($value['yj_Yjno']).'-->'.rtrim($value['yj_yjmc']);
  1994. $list[$key]['no'] = rtrim($value['yj_Yjno']);
  1995. }
  1996. $this->success('成功',$list);
  1997. }
  1998. /**
  1999. * 工单资料管理->印件资料删除
  2000. * @return void
  2001. * @throws \think\Exception
  2002. * @throws \think\exception\PDOException
  2003. */
  2004. public function PrintDetailDel()
  2005. {
  2006. if ($this->request->isGet() === false){
  2007. $this->error('请求错误');
  2008. }
  2009. $param = $this->request->param();
  2010. if (isset($param['UniqId']) === false){
  2011. $this->error('参数错误');
  2012. }
  2013. $printId = explode(',',$param['UniqId']);
  2014. $i = 0;
  2015. foreach ($printId as $value){
  2016. $res = \db('工单_印件资料')
  2017. ->where('Uniqid',$value)
  2018. ->delete();
  2019. if ($res === false){
  2020. $i++;
  2021. }
  2022. }
  2023. if ($i === 0){
  2024. $this->success('删除成功');
  2025. }else{
  2026. $this->error('删除失败');
  2027. }
  2028. }
  2029. /**
  2030. * 工单资料管理->工艺资料删除
  2031. * @return void
  2032. * @throws \think\Exception
  2033. * @throws \think\exception\PDOException
  2034. */
  2035. public function ProcessDetailDel()
  2036. {
  2037. if ($this->request->isGet() === false){
  2038. $this->error('请求错误');
  2039. }
  2040. $param = $this->request->param();
  2041. if (isset($param['UniqId']) === false){
  2042. $this->error('参数错误');
  2043. }
  2044. $printId = explode(',',$param['UniqId']);
  2045. $i = 0;
  2046. //获取工单编号、印件号
  2047. $codeList = \db('工单_工艺资料')
  2048. ->where('UniqId',$printId[0])
  2049. ->field('rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_yjno) as 印件号')
  2050. ->find();
  2051. //获取平张投料数量
  2052. $number = \db('工单_印件资料')
  2053. ->where([
  2054. 'Yj_Gdbh' => $codeList['工单编号'],
  2055. 'yj_Yjno' => $codeList['印件号']
  2056. ])
  2057. ->value('rtrim(yj_平张投料)');
  2058. // 新增:批量获取要删除的工序号
  2059. $gxhList = \db('工单_工艺资料')
  2060. ->where('UniqId', 'in', $printId)
  2061. ->column('rtrim(Gy0_gxh) as gxh', 'UniqId');
  2062. //循环删除工艺资料
  2063. $deletedGxh = [];
  2064. foreach ($printId as $value){
  2065. $process = \db('工单_工艺资料')
  2066. ->where('UniqId',$value)
  2067. ->find();
  2068. $processCount = \db('设备_产量计酬')
  2069. ->where('sczl_gdbh',$process['Gy0_gdbh'])
  2070. ->where('sczl_yjno',$process['Gy0_yjno'])
  2071. ->where('sczl_gxh',$process['Gy0_gxh'])
  2072. ->count();
  2073. if ($processCount > 0){
  2074. $this->error('工序'.$process['Gy0_gxh'].'已上报数据,无法删除,请核对');
  2075. }
  2076. $res = \db('工单_工艺资料')
  2077. ->where('UniqId',$value)
  2078. ->delete();
  2079. if ($res) {
  2080. // 记录成功删除的工序号
  2081. if (isset($gxhList[$value])) {
  2082. $deletedGxh[] = $gxhList[$value];
  2083. }
  2084. } else {
  2085. $i++;
  2086. }
  2087. }
  2088. //重新分配工艺计划产量
  2089. if ((int)$number>0){
  2090. $this->PlannedProcessYield($codeList['工单编号'],$codeList['印件号'],0,$number);
  2091. }
  2092. // 新增:写入操作日志
  2093. \db('系统操作日志表')->insert([
  2094. 'ModifyUser' => $param['sys_id'],
  2095. 'ModifyTime' => date('Y-m-d H:i:s',time()),
  2096. 'Gd_gdbh' => $codeList['工单编号'],
  2097. 'yjno' => $codeList['印件号'],
  2098. 'gxh' => implode(',', $deletedGxh),
  2099. 'ModifySource' => '工艺资料删除'
  2100. ]);
  2101. if ($i === 0){
  2102. $this->success('删除成功');
  2103. }else{
  2104. $this->error('删除失败');
  2105. }
  2106. }
  2107. /**
  2108. * 工艺资料添加->工序损耗代码
  2109. * @return void
  2110. * @throws \think\db\exception\DataNotFoundException
  2111. * @throws \think\db\exception\ModelNotFoundException
  2112. * @throws \think\exception\DbException
  2113. */
  2114. public function WastageList()
  2115. {
  2116. if ($this->request->isGet() === false){
  2117. $this->error('请求错误');
  2118. }
  2119. $param = $this->request->param();
  2120. if (empty($param['process'])){
  2121. $this->error('参数错误');
  2122. }
  2123. if (strlen($param['process'])>6){
  2124. $param['process'] = substr($param['process'],0,6);
  2125. }
  2126. $order = \db('dic_lzsh')
  2127. ->where('sys_mc','like',$param['process'].'%')
  2128. ->value('rtrim(sys_bh) as 编号');
  2129. $this->success('成功',$order);
  2130. }
  2131. /**
  2132. * 获取产品附件列表
  2133. */
  2134. public function getAnnexTable(){
  2135. if(!$this->request->isGet()){
  2136. $this->error('请求方式错误');
  2137. }
  2138. $req = $this->request->param();
  2139. if (isset($req['cpdh']) && !empty($req['cpdh'])){
  2140. $where['关联产品'] = ['LIKE','%'.$req['cpdh'].'%'];
  2141. }else{
  2142. $this->error('参数错误');
  2143. }
  2144. $rows = db('产品_技术附件')
  2145. ->where($where)
  2146. ->select();
  2147. foreach ($rows as $key=>&$value){
  2148. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  2149. $value['附件内容'] = '';
  2150. }
  2151. }
  2152. $this->success('成功',$rows);
  2153. }
  2154. /**
  2155. * 产品附件新增
  2156. */
  2157. public function annexAdd(){
  2158. if(!$this->request->isPost()){
  2159. $this->error('请求方式错误');
  2160. }
  2161. $req = $this->request->param();
  2162. $arr = [
  2163. 'sys_id',
  2164. '序号',
  2165. '附件备注',
  2166. '附件内容',
  2167. '附件类型',
  2168. '适用工序',
  2169. '关联产品'
  2170. ];
  2171. $data = [];
  2172. foreach ($arr as $key => $value){
  2173. if (!isset($req[$value])){
  2174. $this->error('参数错误',$value,$key+1);
  2175. }
  2176. $data[$value] = $req[$value];
  2177. }
  2178. $data['sys_rq'] = date('Y-m-d H:i:s');
  2179. //查询UniqId
  2180. $UniqId = db('产品_技术附件')->max('UniqId');
  2181. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  2182. //开启事务
  2183. db()->startTrans();
  2184. try{
  2185. $sql = db('产品_技术附件')->fetchSql(true)->insert($data);
  2186. $bool = db()->query($sql);
  2187. // 提交事务
  2188. db()->commit();
  2189. } catch (\Exception $e) {
  2190. // 回滚事务
  2191. db()->rollback();
  2192. $this->error($e->getMessage());
  2193. }
  2194. if($bool===false) $this->error('失败');
  2195. $this->success('成功');
  2196. }
  2197. /**
  2198. * 产品附件修改
  2199. * @ApiMethod (GET)
  2200. * @param string 'UniqId'
  2201. */
  2202. public function annexDel()
  2203. {
  2204. if(!$this->request->isGet()){
  2205. $this->error('请求方式错误');
  2206. }
  2207. $req = $this->request->param();
  2208. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  2209. $this->error('参数错误','UniqId',100);
  2210. }
  2211. //开启事务
  2212. db()->startTrans();
  2213. try{
  2214. $bool = db('产品_技术附件')->where('UniqId',$req['UniqId'])->delete();
  2215. // 提交事务
  2216. db()->commit();
  2217. } catch (\Exception $e) {
  2218. // 回滚事务
  2219. db()->rollback();
  2220. $this->error($e->getMessage());
  2221. }
  2222. if($bool===false) $this->error('失败');
  2223. $this->success('成功');
  2224. }
  2225. /**
  2226. * 获取产品附件列表
  2227. */
  2228. public function getGdAnnexTable(){
  2229. if(!$this->request->isGet()){
  2230. $this->error('请求方式错误');
  2231. }
  2232. $req = $this->request->param();
  2233. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  2234. $where['关联编号'] = ['LIKE','%'.$req['gdbh'].'%'];
  2235. }else{
  2236. $this->error('参数错误');
  2237. }
  2238. $rows = db('工单_相关附件')
  2239. ->where($where)
  2240. ->select();
  2241. foreach ($rows as $key=>&$value){
  2242. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  2243. $value['附件内容'] = '';
  2244. }
  2245. }
  2246. $this->success('成功',$rows);
  2247. }
  2248. /**
  2249. * 产品附件新增
  2250. */
  2251. public function gdAnnexAdd(){
  2252. if(!$this->request->isPost()){
  2253. $this->error('请求方式错误');
  2254. }
  2255. $req = $this->request->param();
  2256. $arr = [
  2257. 'sys_id',
  2258. '附件备注',
  2259. '附件内容',
  2260. '附件类型',
  2261. '关联编号'
  2262. ];
  2263. $data = [];
  2264. foreach ($arr as $key => $value){
  2265. if (!isset($req[$value])){
  2266. $this->error('参数错误',$value,$key+1);
  2267. }
  2268. $data[$value] = $req[$value];
  2269. }
  2270. $data['sys_rq'] = date('Y-m-d H:i:s');
  2271. //查询UniqId
  2272. $UniqId = db('工单_相关附件')->max('UniqId');
  2273. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  2274. //开启事务
  2275. db()->startTrans();
  2276. try{
  2277. $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  2278. $bool = db()->query($sql);
  2279. // 提交事务
  2280. db()->commit();
  2281. } catch (\Exception $e) {
  2282. // 回滚事务
  2283. db()->rollback();
  2284. $this->error($e->getMessage());
  2285. }
  2286. if($bool===false) $this->error('失败');
  2287. $this->success('成功');
  2288. }
  2289. /**
  2290. * 产品附件修改
  2291. * @ApiMethod (GET)
  2292. * @param string 'UniqId'
  2293. */
  2294. public function gdAnnexDel()
  2295. {
  2296. if(!$this->request->isGet()){
  2297. $this->error('请求方式错误');
  2298. }
  2299. $req = $this->request->param();
  2300. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  2301. $this->error('参数错误','UniqId',100);
  2302. }
  2303. //开启事务
  2304. db()->startTrans();
  2305. try{
  2306. $bool = db('工单_相关附件')->where('UniqId',$req['UniqId'])->delete();
  2307. // 提交事务
  2308. db()->commit();
  2309. } catch (\Exception $e) {
  2310. // 回滚事务
  2311. db()->rollback();
  2312. $this->error($e->getMessage());
  2313. }
  2314. if($bool===false) $this->error('失败');
  2315. $this->success('成功');
  2316. }
  2317. /**
  2318. * 引用工单资料数据查询
  2319. * @return void
  2320. * @throws \think\db\exception\DataNotFoundException
  2321. * @throws \think\db\exception\ModelNotFoundException
  2322. * @throws \think\exception\DbException
  2323. */
  2324. public function WorkOrderDetailCope()
  2325. {
  2326. if ($this->request->isGet() === false){
  2327. $this->error('请求错误');
  2328. }
  2329. $param = $this->request->param();
  2330. if (empty($param['search'])){
  2331. $this->error('参数错误');
  2332. }
  2333. $list = \Db('工单_基本资料')
  2334. ->alias('a')
  2335. ->field([
  2336. 'rtrim(a.Gd_gdbh)' => '工单编号',
  2337. 'rtrim(b.客户编号)' => '客户编号',
  2338. 'rtrim(b.客户名称)' => '客户名称',
  2339. 'rtrim(b.产品编号)' => '产品编号',
  2340. 'rtrim(b.产品名称)' => '产品名称'
  2341. ])
  2342. ->join('产品_基本资料 b', 'a.成品代号 = b.产品编号')
  2343. ->join('产品_工艺资料 c', 'a.成品代号 = c.Gy0_cpdh')
  2344. ->join('产品_印件资料 d', 'a.成品代号 = d.yj_cpdh')
  2345. ->where(function($query) use ($param) {
  2346. $query->where('a.Gd_gdbh', 'like', '%'.$param['search'].'%')
  2347. ->whereOr('a.成品名称', 'like', '%'.$param['search'].'%');
  2348. })
  2349. ->where(function($query) {
  2350. $query->where('c.Gy0_cpdh', '<>', '')
  2351. ->where('d.yj_cpdh', '<>', '')
  2352. ->where('b.状态', 'not like', '%停用%')
  2353. ->where('b.产品名称', 'not like', '%停用%');
  2354. })
  2355. ->group('a.Gd_gdbh')
  2356. ->order('a.Uniqid desc')
  2357. ->select();
  2358. if (empty($list)){
  2359. $this->success('未找到工单资料');
  2360. }else{
  2361. $this->success('成功',$list);
  2362. }
  2363. }
  2364. /**
  2365. * 引用产品印件、工艺资料
  2366. * @return void
  2367. * @throws \think\db\exception\BindParamException
  2368. * @throws \think\db\exception\DataNotFoundException
  2369. * @throws \think\db\exception\ModelNotFoundException
  2370. * @throws \think\exception\DbException
  2371. * @throws \think\exception\PDOException
  2372. */
  2373. public function WorkOrderDetailListCope()
  2374. {
  2375. if (Request::instance()->isPost() === false){
  2376. $this->error('请求错误');
  2377. }
  2378. $param = Request::instance()->post();
  2379. if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
  2380. $this->error('参数错误');
  2381. }
  2382. if (isset($param['sort'])){
  2383. $priWhere['yj_yjno'] = ['>=',10];
  2384. $proWhere['a.Gy0_yjno'] = ['>=',10];
  2385. }else{
  2386. $priWhere['yj_yjno'] = ['<',10];
  2387. $proWhere['a.Gy0_yjno'] = ['<',10];
  2388. }
  2389. $list = \db('工单_基本资料')
  2390. ->where('Gd_gdbh',$param['workorder'])
  2391. // ->where('成品代号',$param['productCode'])
  2392. ->field('行号,Gd_cpdh')
  2393. ->select();
  2394. $cpdhList = \db('工单_基本资料')
  2395. ->where('Gd_gdbh',$param['workorder'])
  2396. ->column('Gd_cpdh');
  2397. //引用印件资料
  2398. $PrintList = \db('产品_印件资料')
  2399. ->where('yj_cpdh',$param['productCode'])
  2400. ->whereIn('yj_yjdh',$cpdhList)
  2401. ->where($priWhere)
  2402. ->select();
  2403. if (empty($PrintList)){
  2404. $this->error('未找到印件资料');
  2405. }
  2406. $number = \db('工单_基本资料')
  2407. ->where('Gd_gdbh',$param['workorder'])
  2408. ->where('成品代号',$param['productCode'])
  2409. ->value('rtrim(计划投料)');
  2410. $arr = [];
  2411. foreach ($PrintList as $key => $value){
  2412. foreach ($list as $k=>$v){
  2413. if (rtrim($value['yj_yjdh']) === $v['Gd_cpdh']){
  2414. $PrintList[$key]['Yj_Gdbh'] = $param['workorder'];
  2415. $PrintList[$key]['yj_Yjno'] = $value['yj_yjno'];
  2416. $PrintList[$key]['yj_Yjdh'] = $value['yj_yjdh'];
  2417. $PrintList[$key]['yj_ks'] = $value['yj_ks'];
  2418. $PrintList[$key]['yj_ls'] = $value['yj_ls'];
  2419. $PrintList[$key]['yj_平张投料'] = $number;
  2420. $PrintList[$key]['Sys_id'] = $value['sys_id'];
  2421. // $PrintList[$key]['Uniqid'] = $PrintLastId + $key + 1;
  2422. $PrintList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  2423. $PrintList[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  2424. array_push($arr,[$value['yj_yjno'],$v['行号']]);
  2425. }
  2426. $sql = \db('工单_基本资料')
  2427. ->where('Gd_gdbh',$param['workorder'])
  2428. ->where('Gd_cpdh',$value['yj_yjdh'])
  2429. ->fetchSql(true)
  2430. ->update(['行号'=>$value['yj_yjno']]);
  2431. \db()->query($sql);
  2432. $bomSql = \db('工单_bom资料')
  2433. ->where('BOM_工单编号',$param['workorder'])
  2434. ->where('BOM_产品编号',$value['yj_yjdh'])
  2435. ->fetchSql(true)
  2436. ->update(['BOM_工单行号'=>$value['yj_yjno']]);
  2437. \db()->query($bomSql);
  2438. }
  2439. 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']);
  2440. }
  2441. //引用工艺资料
  2442. $processWhere = [
  2443. 'a.Gy0_方案' => $param['option'],
  2444. 'a.Gy0_cpdh' => $param['productCode']
  2445. ];
  2446. $yjnolist = \db('工单_基本资料')
  2447. ->where('Gd_gdbh',$param['workorder'])
  2448. ->column('Gd_cpdh');
  2449. $ProcessList = \db('产品_工艺资料')
  2450. ->alias('a')
  2451. ->field('a.*')
  2452. ->join('产品_印件资料 b','a.Gy0_cpdh = b.yj_cpdh AND a.Gy0_yjno = yj_yjno')
  2453. ->where($processWhere)
  2454. ->where($proWhere)
  2455. ->whereIn('b.yj_yjdh',$yjnolist)
  2456. ->order('Gy0_yjno,Gy0_gxh')
  2457. ->select();
  2458. if (empty($ProcessList)){
  2459. $this->error('未找到产品工艺资料');
  2460. }
  2461. $ProcesslastId = \db('工单_工艺资料')->order('UniqId desc')->value('rtrim(UniqId)');
  2462. foreach ($ProcessList as $key=>$value){
  2463. if (empty(trim($value['Gy0_shdh']))){
  2464. $rate['rate0'] = 0;
  2465. $rate['rate1'] = 0;
  2466. }else{
  2467. $rate = \db('dic_lzsh')->where('sys_bh',$value['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  2468. if (empty($rate)){
  2469. $this->error('该产品印件号'.$value['Gy0_yjno'].'工序号为'.$value['gy0_gxmc'].'的损耗代号错误,请调整之后再引用');
  2470. }
  2471. }
  2472. //设置默认机台
  2473. $machineList = \db('设备_基本资料')
  2474. ->where('生产工序','like','%'.$value['gy0_gxmc'].'%')
  2475. ->where('使用部门','<>','研发中心')
  2476. ->where('设备编组','<>','')
  2477. ->where('sys_sbID','<>','')
  2478. ->order('设备编号')
  2479. ->value('设备编号');
  2480. $ProcessList[$key]['Gy0_sbbh'] = '';
  2481. if (!empty($machineList)){
  2482. $ProcessList[$key]['Gy0_sbbh'] = $machineList;
  2483. }
  2484. $ProcessList[$key]['Gy0_yjno'] = $value['Gy0_yjno'];
  2485. $ProcessList[$key]['Gy0_gdbh'] = $param['workorder'];
  2486. $ProcessList[$key]['Gy0_gxmc'] = $value['gy0_gxmc'];
  2487. $ProcessList[$key]['Gy0_SITE'] = $value['Gy0_site'];
  2488. $ProcessList[$key]['Gy0_shdh'] = $value['Gy0_shdh'];
  2489. $ProcessList[$key]['Gy0_Rate0'] = $rate['rate0'];
  2490. $ProcessList[$key]['Gy0_Rate1'] = $rate['rate1'];
  2491. $ProcessList[$key]['Gy0_ks'] = $value['Gy0_Ks'];
  2492. $ProcessList[$key]['Gy0_ms'] = $value['Gy0_Ms'];
  2493. $ProcessList[$key]['Gy0_oil'] = $value['Gy0_Oil'];
  2494. $ProcessList[$key]['Gy0_计划接货数'] = 0;
  2495. $ProcessList[$key]['Gy0_计划损耗'] = 0;
  2496. $ProcessList[$key]['无形损承担比例'] = 0;
  2497. $ProcessList[$key]['超节损承担比例'] = 1;
  2498. $ProcessList[$key]['超节损核算单价'] = 0;
  2499. $ProcessList[$key]['Gy0_sj1'] = '1900-01-01 00:00:00';
  2500. $ProcessList[$key]['Gy0_sj2'] = '1900-01-01 00:00:00';
  2501. // $ProcessList[$key]['UniqId'] = $ProcesslastId + $key + 1;
  2502. $ProcessList[$key]['PD_WG'] = '1900-01-01 00:00:00';
  2503. $ProcessList[$key]['Sys_rq'] = date('Y-m-d H:i:s', time());
  2504. 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']);
  2505. }
  2506. //插入数据
  2507. \db()->startTrans();
  2508. try {
  2509. \db('工单_工艺资料')->where('Gy0_gdbh',$param['workorder'])->delete();
  2510. $processSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($ProcessList);
  2511. \db()->query($processSql);
  2512. \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->delete();
  2513. $printSql = \db('工单_印件资料')->fetchSql(true)->insertAll($PrintList);
  2514. \db()->query($printSql);
  2515. \db()->commit();
  2516. }catch (\Exception $e){
  2517. \db()->rollback();
  2518. // echo $e->getMessage();
  2519. }
  2520. //计算工序计划生产数量
  2521. if ($number !== null){
  2522. $list = \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->field('yj_Yjno,yj_平张投料')->select();
  2523. foreach ($list as $value){
  2524. if ((int)$value['yj_平张投料'] >0){
  2525. $this->PlannedProcessYield($param['workorder'],$value['yj_Yjno'],0,$value['yj_平张投料']);
  2526. }
  2527. }
  2528. }
  2529. $this->success('成功');
  2530. }
  2531. /**
  2532. * 引用产品印件、工艺资料->信息获取
  2533. * @return void
  2534. * @throws \think\db\exception\DataNotFoundException
  2535. * @throws \think\db\exception\ModelNotFoundException
  2536. * @throws \think\exception\DbException
  2537. */
  2538. public function ProductCopeDetail()
  2539. {
  2540. if ($this->request->isGet() === false){
  2541. $this->error('请求错误');
  2542. }
  2543. $param = $this->request->param();
  2544. if (empty($param['workorder'])){
  2545. $this->error('参数错误');
  2546. }
  2547. $list = \db('工单_基本资料')
  2548. ->alias('a')
  2549. ->field([
  2550. 'rtrim(a.Gd_gdbh)' => '工单编号',
  2551. 'rtrim(b.客户编号)' => '客户编号',
  2552. 'rtrim(b.客户名称)' => '客户名称',
  2553. 'rtrim(b.产品编号)' => '产品编号',
  2554. 'rtrim(b.产品名称)' => '产品名称'
  2555. ])
  2556. ->join('产品_基本资料 b','a.成品代号 = b.产品编号')
  2557. ->where('a.Gd_gdbh',$param['workorder'])
  2558. ->find();
  2559. if (empty($list)){
  2560. $this->error('未找到工单信息');
  2561. }
  2562. $option = \db('产品_工艺资料')
  2563. ->field('rtrim(Gy0_方案) as 方案')
  2564. ->where('Gy0_cpdh',$list['产品编号'])
  2565. ->group('Gy0_方案')
  2566. ->select();
  2567. $list['方案'] = $option;
  2568. $this->success('成功',$list);
  2569. }
  2570. /**
  2571. * 工艺资料计划产量重新分配
  2572. * @param string $workOrder 工单
  2573. * @param int $yjno 印件号
  2574. * @param int $gxh 工序号
  2575. * @param int $feed 平张投料
  2576. * @return bool
  2577. * @throws \think\Exception
  2578. * @throws \think\db\exception\BindParamException
  2579. * @throws \think\db\exception\DataNotFoundException
  2580. * @throws \think\db\exception\ModelNotFoundException
  2581. * @throws \think\exception\DbException
  2582. * @throws \think\exception\PDOException
  2583. */
  2584. public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
  2585. {
  2586. $where = [
  2587. 'Gy0_gdbh'=>$workOrder,
  2588. 'Gy0_yjno'=>$yjno,
  2589. ];
  2590. //获取工艺资料
  2591. $processList = \db('工单_工艺资料')
  2592. ->where($where)
  2593. ->field('CONCAT(rtrim(Gy0_gxmc),"[",rtrim(Add_gxmc),"]") as 工序名称,Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
  2594. ->order('Gy0_gxh')
  2595. ->select();
  2596. if (empty($processList)){
  2597. $this->success('未找到该工单工序资料');
  2598. }
  2599. $processDetail = \db('工单_工艺资料')
  2600. ->where($where)
  2601. ->field('CONCAT(rtrim(Gy0_gxmc),"[",rtrim(Add_gxmc),"]") as 工序名称,Gy0_ls as 联数')
  2602. ->select();
  2603. $number1 = $number2 = 1;
  2604. foreach ($processDetail as $k => $v) {
  2605. if (strpos($v['工序名称'],'分切') !== false) {
  2606. $number1 = $v['联数'];
  2607. }
  2608. if (strpos($v['工序名称'],'分切') === false && $v['联数'] > 1) {
  2609. $number2 = $v['联数'];
  2610. }
  2611. }
  2612. $Multiple = $number1/$number2;
  2613. if (is_int($Multiple) === false) {
  2614. $Multiple = 1;
  2615. }
  2616. //计算损耗定额和计划产量
  2617. $production = [];
  2618. $i = $m = 0;
  2619. foreach ($processList as $key=>$value){
  2620. if (strpos($v['工序名称'],'分切') !== false) {
  2621. $m = $key;
  2622. }
  2623. if ($key === 0){
  2624. array_push($production,$feed);
  2625. }else{
  2626. if ($key === $m+1){
  2627. $production[$key] = $production[$key]/$value['Gy0_ls']/$Multiple;
  2628. }else{
  2629. $production[$key] = $production[$key]/$value['Gy0_ls'];
  2630. }
  2631. }
  2632. $wastage = 0;
  2633. if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
  2634. $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
  2635. }
  2636. if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
  2637. $wastage = round($wastage * $value['Gy0_ms']);
  2638. }
  2639. array_push($production,ceil($production[$key]-$wastage)*$value['Gy0_ls']);
  2640. $processSql = \db('工单_工艺资料')
  2641. ->where('UniqId',$value['UniqId'])
  2642. ->fetchSql(true)
  2643. ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
  2644. $res = \db()->query($processSql);
  2645. if ($res === false){
  2646. $i++;
  2647. }
  2648. }
  2649. if ($i===0){
  2650. return true;
  2651. }else{
  2652. return false;
  2653. }
  2654. }
  2655. /**
  2656. * 工单资料删除
  2657. * @return void
  2658. * @throws \think\exception\PDOException
  2659. */
  2660. public function WorkOrderDel()
  2661. {
  2662. if ($this->request->isGet() === false){
  2663. $this->error('请求错误');
  2664. }
  2665. $param = $this->request->param();
  2666. if (isset($param['UniqId']) === false){
  2667. $this->error('参数错误');
  2668. }
  2669. $WorkOrderId = explode(',',$param['UniqId']);
  2670. $i = 0;
  2671. foreach ($WorkOrderId as $key=>$value){
  2672. //获取工单编号
  2673. $workorder = \db('工单_基本资料')
  2674. ->where('Uniqid',$value)
  2675. ->value('rtrim(Gd_gdbh)');
  2676. $status = \db('设备_产量计酬')
  2677. ->where('sczl_gdbh',$workorder)
  2678. ->count();
  2679. if ($status === 0){
  2680. //删除工单资料、工艺资料、印件资料
  2681. \db()->startTrans();
  2682. try {
  2683. \db('工单_基本资料')->where('Gd_gdbh',$workorder)->delete();
  2684. if (!empty(\db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->find())){
  2685. \db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->delete();
  2686. }
  2687. if (!empty(\db('工单_印件资料')->where('Yj_Gdbh',$workorder)->find())){
  2688. \db('工单_印件资料')->where('Yj_Gdbh',$workorder)->delete();
  2689. }
  2690. if (!empty(\db('工单_bom资料')->where('BOM_工单编号',$workorder)->find())){
  2691. \db('工单_bom资料')->where('BOM_工单编号',$workorder)->delete();
  2692. }
  2693. \db()->commit();
  2694. // 成功删除后记录日志
  2695. $logSql = \db('系统操作日志表')->fetchSql(true)->insert([
  2696. 'Gd_gdbh' => $workorder,
  2697. 'ModifyUser' => $param['sys_id'],
  2698. 'ModifyTime' => date('Y-m-d H:i:s'),
  2699. 'FieldName' => '工单删除',
  2700. 'NewValue' => '已删除',
  2701. 'ModifySource' => '工单删除'
  2702. ]);
  2703. \db()->query($logSql);
  2704. }catch (\Exception $e){
  2705. \db()->rollback();
  2706. $i++;
  2707. }
  2708. }else{
  2709. $this->error('工单'.$workorder.'已上报数据无法删除,请重新确认');
  2710. }
  2711. }
  2712. if ($i === 0){
  2713. $this->success('删除成功');
  2714. }else{
  2715. $this->error('删除失败');
  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. public function ProductNameData()
  2726. {
  2727. if ($this->request->isGet() === false){
  2728. $this->error('请求错误');
  2729. }
  2730. $workOrder = input('workOrder');
  2731. if (empty($workOrder)){
  2732. $this->error('参数错误');
  2733. }
  2734. $orderList = \db('工单_基本资料')
  2735. ->field('rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称')
  2736. ->where('Gd_gdbh',$workOrder)
  2737. ->find();
  2738. $this->success('成功',$orderList);
  2739. }
  2740. /**
  2741. * 获取联数
  2742. * @return void
  2743. * @throws \think\db\exception\DataNotFoundException
  2744. * @throws \think\db\exception\ModelNotFoundException
  2745. * @throws \think\exception\DbException
  2746. */
  2747. public function getCouplet()
  2748. {
  2749. if ($this->request->isGet() === false){
  2750. $this->error('请求错误');
  2751. }
  2752. $param = $this->request->param();
  2753. if (empty($param['gdbh']) || empty($param['yjno'])){
  2754. $this->error('参数错误');
  2755. }
  2756. $list = \db('工单_印件资料')
  2757. ->where('Yj_gdbh',$param['gdbh'])
  2758. ->where('yj_Yjno',$param['yjno'])
  2759. ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
  2760. ->find();
  2761. $process = \db('工单_工艺资料')
  2762. ->where('Gy0_gdbh',$param['gdbh'])
  2763. ->where('Gy0_yjno',$param['yjno'])
  2764. ->order('Gy0_gxh desc')
  2765. ->value('Gy0_gxh');
  2766. $list['工序号'] = $process + 1;
  2767. $this->success('成功',$list);
  2768. }
  2769. /**
  2770. * 糊盒工单配件完成度查询
  2771. * @return void
  2772. * @throws \think\db\exception\DataNotFoundException
  2773. * @throws \think\db\exception\ModelNotFoundException
  2774. * @throws \think\exception\DbException
  2775. */
  2776. public function Accessories()
  2777. {
  2778. if ($this->request->isGet() === false){
  2779. $this->error('请求错误');
  2780. }
  2781. $param = $this->request->param();
  2782. if (empty($param['batch'])){
  2783. $this->error('参数错误');
  2784. }
  2785. $list = \db('工单_基本资料')
  2786. ->alias('a')
  2787. ->join('工单_印件资料 b','a.Gd_gdbh=b.Yj_Gdbh')
  2788. ->join('成品入仓 c','a.Gd_gdbh=c.jjcp_gdbh and a.销售订单号 = c.订单编号 and b.yj_Yjno = c.jjcp_yjno','left')
  2789. ->where('a.销售订单号',$param['batch'])
  2790. ->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 入仓数量')
  2791. ->group('a.Gd_gdbh,b.yj_Yjno')
  2792. ->order('a.Gd_gdbh,b.yj_Yjno')
  2793. ->select();
  2794. if (empty($list)){
  2795. $this->error('未找到数据');
  2796. }else{
  2797. $this->success('成功',$list);
  2798. }
  2799. }
  2800. /**
  2801. *查询糊盒标准工单
  2802. * @return void
  2803. * @throws \think\db\exception\DataNotFoundException
  2804. * @throws \think\db\exception\ModelNotFoundException
  2805. * @throws \think\exception\DbException
  2806. *
  2807. */
  2808. public function HuheWorkOrderSearch()
  2809. {
  2810. if ($this->request->isGet() === false){
  2811. $this->error('请求错误');
  2812. }
  2813. $param = $this->request->param();
  2814. if (empty($param['search'])){
  2815. $this->error('参数错误');
  2816. }
  2817. $where['Gd_gdbh|Gd_cpmc|成品名称'] = ['like','%'.$param['search'].'%'];
  2818. $where['Gd_lx'] = '糊盒标准工单';
  2819. $list = \db('工单_基本资料')
  2820. ->field('Gd_gdbh as 工单编号,Gd_cpdh as 产品编号,Gd_cpmc as 产品名称,成品代号,成品名称,Uniqid')
  2821. ->where($where)
  2822. ->group('Gd_gdbh,Gd_cpdh,Gd_cpmc')
  2823. ->order('Gd_gdbh,Gd_cpdh')
  2824. ->select();
  2825. if (empty($list)){
  2826. $this->error('未找到数据');
  2827. }else{
  2828. $this->success('成功',$list);
  2829. }
  2830. }
  2831. /**
  2832. * 复制糊盒工单
  2833. * @return void
  2834. */
  2835. public function HuheWorkOrderCopy()
  2836. {
  2837. try {
  2838. // 1. 请求验证
  2839. if (!$this->request->isGet()) {
  2840. throw new \Exception('请求方式错误,请使用GET请求');
  2841. }
  2842. $param = $this->request->param();
  2843. $this->validateCopyParams($param);
  2844. // 2. 查询工单基本信息
  2845. $sourceWorkOrder = $this->getWorkOrderInfo($param['form_Uniqid'], ['Gd_gdbh', '行号']);
  2846. $targetWorkOrder = $this->getWorkOrderInfo($param['to_Uniqid'], ['Gd_gdbh', '行号', '订单数量', '实际投料']);
  2847. // 3. 复制印件资料和工艺资料
  2848. $this->copyPrintingData($sourceWorkOrder, $targetWorkOrder, $param['sys_id']);
  2849. $this->copyProcessData($sourceWorkOrder, $targetWorkOrder, $param['sys_id']);
  2850. $this->success('复制成功');
  2851. } catch (\Exception $e) {
  2852. $this->error($e->getMessage());
  2853. }
  2854. }
  2855. /**
  2856. * 验证复制所需的参数
  2857. * @param array $params
  2858. * @throws \Exception
  2859. */
  2860. private function validateCopyParams(array $params): void
  2861. {
  2862. if (empty($params['to_Uniqid'])) {
  2863. throw new \Exception('目标工单ID(to_Uniqid)不能为空');
  2864. }
  2865. if (empty($params['form_Uniqid'])) {
  2866. throw new \Exception('源工单ID(form_Uniqid)不能为空');
  2867. }
  2868. if (empty($params['sys_id'])) {
  2869. throw new \Exception('系统ID(sys_id)不能为空');
  2870. }
  2871. }
  2872. /**
  2873. * 获取工单信息
  2874. * @param string $uniqid 工单唯一标识
  2875. * @param array $fields 需要查询的字段
  2876. * @return array 工单信息
  2877. * @throws \Exception
  2878. */
  2879. private function getWorkOrderInfo(string $uniqid, array $fields = []): array
  2880. {
  2881. $info = \db('工单_基本资料')
  2882. ->field($fields)
  2883. ->where('Uniqid', $uniqid)
  2884. ->find();
  2885. if (empty($info)) {
  2886. throw new \Exception("工单不存在,ID: {$uniqid}");
  2887. }
  2888. return $info;
  2889. }
  2890. /**
  2891. * 复制印件资料
  2892. * @param array $sourceWorkOrder 源工单信息
  2893. * @param array $targetWorkOrder 目标工单信息
  2894. * @param string $sysId 系统ID
  2895. * @throws \Exception
  2896. */
  2897. private function copyPrintingData(array $sourceWorkOrder, array $targetWorkOrder, string $sysId): void
  2898. {
  2899. // 常量定义,便于维护
  2900. $tableName = '工单_印件资料';
  2901. $excludeFields = ['Uniqid', 'Yj_Gdbh', 'yj_Yjno', 'yj_成品数量', 'yj_平张投料', '印件完工日期', 'Sys_id', 'Sys_rq', 'Mod_rq'];
  2902. // 查询源印件资料
  2903. $printingData = \db($tableName)
  2904. ->where('Yj_Gdbh', $sourceWorkOrder['Gd_gdbh'])
  2905. ->where('yj_Yjno', $sourceWorkOrder['行号'])
  2906. ->find();
  2907. if (empty($printingData)) {
  2908. throw new \Exception('未找到源工单印件资料');
  2909. }
  2910. // 构建新的印件资料
  2911. $newPrintingData = $this->buildCopyData(
  2912. $printingData,
  2913. $excludeFields,
  2914. [
  2915. 'Yj_Gdbh' => $targetWorkOrder['Gd_gdbh'],
  2916. 'yj_Yjno' => $targetWorkOrder['行号'],
  2917. 'yj_成品数量' => $targetWorkOrder['订单数量'],
  2918. 'yj_平张投料' => $targetWorkOrder['实际投料'],
  2919. '印件完工日期' => null,
  2920. 'Sys_id' => $sysId,
  2921. 'Sys_rq' => date('Y-m-d H:i:s'),
  2922. 'Mod_rq' => null
  2923. ]
  2924. );
  2925. \db($tableName)
  2926. ->where('Yj_Gdbh',$newPrintingData['Yj_Gdbh'])
  2927. ->where('yj_Yjno',$newPrintingData['yj_Yjno'])
  2928. ->delete();
  2929. // 执行插入操作(保留fetchSql和query兼容中文字段)
  2930. $sql = \db($tableName)->fetchSql(true)->insert($newPrintingData);
  2931. $result = \db()->query($sql);
  2932. if ($result === false) {
  2933. throw new \Exception("印件资料复制失败,SQL: {$sql}");
  2934. }
  2935. }
  2936. /**
  2937. * 复制工艺资料
  2938. * @param array $sourceWorkOrder 源工单信息
  2939. * @param array $targetWorkOrder 目标工单信息
  2940. * @param string $sysId 系统ID
  2941. * @throws \Exception
  2942. */
  2943. private function copyProcessData(array $sourceWorkOrder, array $targetWorkOrder, string $sysId): void
  2944. {
  2945. // 常量定义
  2946. $tableName = '工单_工艺资料';
  2947. $excludeFields = ['UniqId', 'Gy0_gdbh', 'Gy0_yjno', 'Gy0_sbbh', 'Gy0_计划接货数', 'Gy0_最早开工时间', 'Gy0_sj1', 'Gy0_sj2', 'PD_WG', 'Sys_id', 'Sys_rq', 'Mod_rq'];
  2948. $defaultDate = '1900-01-01 00:00:00';
  2949. $currentTime = date('Y-m-d H:i:s');
  2950. // 查询源工艺资料列表
  2951. $processList = \db($tableName)
  2952. ->where('Gy0_gdbh', $sourceWorkOrder['Gd_gdbh'])
  2953. ->where('Gy0_yjno', $sourceWorkOrder['行号'])
  2954. ->select();
  2955. if (empty($processList)) {
  2956. throw new \Exception('未找到源工单工艺资料');
  2957. }
  2958. // 构建新的工艺资料列表
  2959. $newProcessData = [];
  2960. foreach ($processList as $item) {
  2961. $newProcessData[] = $this->buildCopyData(
  2962. $item,
  2963. $excludeFields,
  2964. [
  2965. 'Gy0_gdbh' => $targetWorkOrder['Gd_gdbh'],
  2966. 'Gy0_yjno' => $targetWorkOrder['行号'],
  2967. 'Gy0_sbbh' => '',
  2968. 'Gy0_计划接货数' => $targetWorkOrder['实际投料'],
  2969. 'Gy0_最早开工时间' => $defaultDate,
  2970. 'Gy0_sj1' => $defaultDate,
  2971. 'Gy0_sj2' => $defaultDate,
  2972. 'PD_WG' => $defaultDate,
  2973. 'Sys_id' => $sysId,
  2974. 'Sys_rq' => $currentTime,
  2975. 'Mod_rq' => null
  2976. ]
  2977. );
  2978. }
  2979. \db($tableName)
  2980. ->where('Gy0_gdbh', $targetWorkOrder['Gd_gdbh'])
  2981. ->where('Gy0_yjno', $targetWorkOrder['行号'])
  2982. ->delete();
  2983. // 执行批量插入(保留fetchSql和query兼容中文字段)
  2984. if (!empty($newProcessData)) {
  2985. $sql = \db($tableName)->fetchSql(true)->insertAll($newProcessData);
  2986. $result = \db()->query($sql);
  2987. if ($result === false) {
  2988. throw new \Exception("工艺资料复制失败,SQL: {$sql}");
  2989. }
  2990. }
  2991. }
  2992. /**
  2993. * 构建复制的数据
  2994. * @param array $sourceData 源数据
  2995. * @param array $excludeFields 需要排除的字段
  2996. * @param array $overrideData 需要覆盖的字段和值
  2997. * @return array 构建后的新数据
  2998. */
  2999. private function buildCopyData(array $sourceData, array $excludeFields, array $overrideData): array
  3000. {
  3001. $newData = [];
  3002. // 复制源数据中不需要排除的字段
  3003. foreach ($sourceData as $key => $value) {
  3004. if (!in_array($key, $excludeFields)) {
  3005. $newData[$key] = $value;
  3006. }
  3007. }
  3008. // 覆盖需要替换的字段
  3009. return array_merge($newData, $overrideData);
  3010. }
  3011. /**
  3012. * 糊盒标准工单左侧菜单栏
  3013. * @return void
  3014. * @throws \think\db\exception\DataNotFoundException
  3015. * @throws \think\db\exception\ModelNotFoundException
  3016. * @throws \think\exception\DbException
  3017. */
  3018. public function HuheDataList()
  3019. {
  3020. if ($this->request->isGet() === false){
  3021. $this->error('请求错误');
  3022. }
  3023. $list = \db('产品_基本资料')
  3024. ->where('客户编号','<>','')
  3025. ->field('rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称')
  3026. ->group('客户编号,客户名称')
  3027. ->order('客户编号')
  3028. ->select();
  3029. if (empty($list)){
  3030. $this->success('',[]);
  3031. }
  3032. $data['糊盒工单'] = [];
  3033. foreach ($list as $key=>$value){
  3034. $work_order_count = \db('工单_基本资料')
  3035. ->where('行号','1')
  3036. ->where('Gd_cpdh|成品代号','LIKE',rtrim($value['客户编号']).'%')
  3037. ->where('Gd_lx','糊盒标准工单')
  3038. ->count();
  3039. if (!empty($value['客户名称']) && $work_order_count !== 0){
  3040. $name = $value['客户编号'].rtrim($value['客户名称']);
  3041. if (strpos($value['客户编号'],'J') !== false ){
  3042. array_push($data['糊盒工单'],$name);
  3043. }
  3044. }
  3045. }
  3046. $this->success('成功',$data);
  3047. }
  3048. /**
  3049. * 糊盒标准工单列表
  3050. * @return void
  3051. * @throws \think\Exception
  3052. * @throws \think\db\exception\DataNotFoundException
  3053. * @throws \think\db\exception\ModelNotFoundException
  3054. * @throws \think\exception\DbException
  3055. */
  3056. public function HuheWorkList()
  3057. {
  3058. if ($this->request->isGet() === false){
  3059. $this->error('请求错误');
  3060. }
  3061. $search = input('search');
  3062. $clientNumber = input('Gd_khdh');
  3063. $startTime = input('start');
  3064. $endTime = input('end');
  3065. $page = input('page');
  3066. $limit = input('limit');
  3067. $param = $this->request->param();
  3068. $where = [];
  3069. if (!empty($clientNumber)){
  3070. if (substr($clientNumber,0,1) !== 'Y' && substr($clientNumber,0,1) !== 'J')
  3071. {
  3072. $clientNumber = substr($clientNumber,0,4);
  3073. }
  3074. if ($clientNumber === 'Y1401'){
  3075. $where['Gd_cpdh'] = ['like',$clientNumber.'%'];
  3076. }else{
  3077. $where['成品代号'] = ['like',$clientNumber.'%'];
  3078. }
  3079. }
  3080. if (!empty($workOrder)){
  3081. $where['Gd_gdbh'] = $workOrder;
  3082. }
  3083. if (!empty($productCode)){
  3084. $where['Gd_cpdh'] = $productCode;
  3085. }
  3086. if (!empty($search)){
  3087. $where['Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$search.'%'];
  3088. }
  3089. if (!empty($startTime) && !empty($endTime)){
  3090. $where['接单日期'] = ['between',[$startTime,$endTime]];
  3091. }
  3092. $where['Gd_lx'] = '糊盒标准工单';
  3093. $total = \db('工单_基本资料')->where($where)->distinct(true)->field('Gd_gdbh')->count();
  3094. $list = \db('工单_基本资料')
  3095. ->where($where)
  3096. ->order('Gd_statu desc')
  3097. ->limit(($page-1)*$limit,$limit)
  3098. ->group('Gd_gdbh')
  3099. ->select();
  3100. //工单基本资料数据整理
  3101. $data = [];
  3102. foreach ($list as $key=>$value){
  3103. $data[$key] = [
  3104. '工单编号' => rtrim($value['Gd_gdbh']),
  3105. '生产分类' => rtrim($value['Gd_生产分类']),
  3106. '销售订单号' => rtrim($value['销售订单号']),
  3107. '产品代号' => rtrim($value['成品代号']),
  3108. '产品名称' => rtrim($value['成品名称']),
  3109. '订单数量' => floatval($value['订单数量']),
  3110. '单位' => rtrim($value['计量单位']),
  3111. '折合大箱' => rtrim((int)$value['投料大箱']),
  3112. '投料率' => rtrim($value['投料率']),
  3113. '平均合格率' => '',
  3114. '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
  3115. '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
  3116. '工单类型' => rtrim($value['Gd_lx']),
  3117. '工单状态' => rtrim($value['gd_statu']),
  3118. '当前生产工序' => '',
  3119. '产量提交时间' => '',
  3120. '建档用户' => rtrim($value['Sys_id']),
  3121. '建档时间' => rtrim($value['Sys_rq']),
  3122. '更新时间' => rtrim($value['Mod_rq']),
  3123. 'Uniqid' => rtrim($value['Uniqid'])
  3124. ];
  3125. $number = \db('工单_工艺资料')->where('Gy0_gdbh',$data[$key]['工单编号'])->count();
  3126. if ($number === 0){
  3127. $data[$key]['status'] = '*';
  3128. }else{
  3129. $data[$key]['status'] = '';
  3130. }
  3131. }
  3132. $this->success('成功',['data'=>$data,'total'=>$total]);
  3133. }
  3134. }