WorkOrder.php 89 KB

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