WorkOrder.php 90 KB

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