WorkOrder.php 100 KB

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