WorkOrder.php 90 KB

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