WorkOrder.php 96 KB

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