WorkOrder.php 83 KB

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