WorkOrder.php 93 KB

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