WorkOrder.php 86 KB

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