WorkOrder.php 94 KB

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