WorkOrder.php 89 KB

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