WorkOrder.php 114 KB

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