WorkOrder.php 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336
  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. $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,
  856. rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
  857. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
  858. $list = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
  859. if (empty($list)){
  860. $this->success('未找到该工单工艺资料');
  861. }
  862. foreach ($list as $key=>$value){
  863. if ($value['yjno']<10){
  864. $value['yjno'] = '0'.$value['yjno'];
  865. }
  866. if ($value['gxh']<10){
  867. $value['gxh'] = '0'.$value['gxh'];
  868. }
  869. $list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
  870. unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
  871. }
  872. $this->success('成功',$list);
  873. }
  874. /**
  875. * 修正工单核算参数->参数修改
  876. * @ApiMethod (POST)
  877. * @param void
  878. * @return void
  879. * @throws \think\Exception
  880. * @throws \think\db\exception\DataNotFoundException
  881. * @throws \think\db\exception\ModelNotFoundException
  882. * @throws \think\exception\DbException
  883. * @throws \think\exception\PDOException
  884. */
  885. public function AccountingParameterEdit()
  886. {
  887. if (Request::instance()->isPost() === false){
  888. $this->error('请求错误');
  889. }
  890. $param = Request::instance()->post();
  891. if (empty($param) || isset($param[0]['Uniqid']) === false){
  892. $this->error('参数错误');
  893. }
  894. $i = 0;
  895. foreach ($param as $key=>$value){
  896. if (!empty($value['loss'])){
  897. $data = \db('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  898. }
  899. $row = [
  900. '工价系数' => $value['difficulty']?:'',
  901. 'Gy0_shdh' => $value['loss']?:'',
  902. '印刷方式' => $value['printMode']?:'',
  903. '版距' => $value['plate']?:'',
  904. 'Gy0_ms' => $value['chromatic']?:'',
  905. '损耗系数' => $value['wastage']?:'',
  906. 'Gy0_Rate0' => $data['rate0'],
  907. 'Gy0_Rate1' => $data['rate1']
  908. ];
  909. $sql = \db('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
  910. $res = Db::query($sql);
  911. if ($res !== false){
  912. $i++;
  913. }
  914. }
  915. if ($i !== 0){
  916. $this->success('成功');
  917. }else{
  918. $this->error('失败');
  919. }
  920. }
  921. /**
  922. * 印件资料修改
  923. * @ApiMethod (POST)
  924. * @param void
  925. * @return void
  926. * @throws \think\Exception
  927. * @throws \think\exception\PDOException
  928. */
  929. public function PrintedEdit()
  930. {
  931. if (Request::instance()->isPost() === false){
  932. $this->error('请求错误');
  933. }
  934. $param = Request::instance()->post();
  935. if (empty($param) || isset($param['Uniqid']) === false){
  936. $this->error('参数错误');
  937. }
  938. $data = [
  939. 'yj_Yjno' => isset($param['yjno'])?$param['yjno']:'',
  940. 'yj_Yjdh' => isset($param['yjdh'])?$param['yjdh']:'',
  941. 'yj_yjmc' => isset($param['yjmc'])?$param['yjmc']:'',
  942. 'yj_zzdh' => isset($param['zzdh'])?$param['zzdh']:'',
  943. 'yj_zzdh1' => isset($param['zzdh1'])?$param['zzdh1']:'',
  944. 'yj_zzdh2' => isset($param['zzdh2'])?$param['zzdh2']:'',
  945. 'yj_zzdh3' => isset($param['zzdh3'])?$param['zzdh3']:'',
  946. 'yj_zzdh4' => isset($param['zzdh4'])?$param['zzdh4']:'',
  947. 'yj_zzmc' => isset($param['zzmc'])?$param['zzmc']:'',
  948. 'yj_zzmc1' => isset($param['zzmc1'])?$param['zzmc1']:'',
  949. 'yj_zzmc2' => isset($param['zzmc2'])?$param['zzmc2']:'',
  950. 'yj_zzmc3' => isset($param['zzmc3'])?$param['zzmc3']:'',
  951. 'yj_zzmc4' => isset($param['zzmc4'])?$param['zzmc4']:'',
  952. 'yj_成品数量' => isset($param['cpsl'])?$param['cpsl']:'',
  953. 'yj_实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  954. 'yj_平张投料' => isset($param['pztl'])?$param['pztl']:'',
  955. 'yj_tlgg' => isset($param['tlgg'])?$param['tlgg']:'',
  956. 'yj_klgg' => isset($param['klgg'])?$param['klgg']:'',
  957. 'Yj_核算规格' => isset($param['hsgg'])?$param['hsgg']:'',
  958. 'yj_ks' => isset($param['ks'])?$param['ks']:'',
  959. 'yj_ls' => isset($param['ls'])?$param['ls']:'',
  960. 'yj_desc' => isset($param['desc'])?$param['desc']:'',
  961. ];
  962. //获取工单编号
  963. $workOrder = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->field('Yj_Gdbh,yj_Yjno')->find();
  964. if (empty($workOrder)){
  965. $this->success('未找到该工单印件资料');
  966. }
  967. //重新分配工序计划产量
  968. $result = $this->PlannedProcessYield($workOrder['Yj_Gdbh'],$workOrder['yj_Yjno'],0,$param['pztl']);
  969. if ($result === false){
  970. $this->success('修改工序产量失败');
  971. }
  972. $sql = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($data);
  973. $res = Db::query($sql);
  974. if ($res !== false){
  975. $this->success('成功');
  976. }else{
  977. $this->error('失败');
  978. }
  979. }
  980. /**
  981. * 工艺资料修改
  982. * @ApiMethod (POST)
  983. * @param void
  984. * @return void
  985. * @throws \think\Exception
  986. * @throws \think\db\exception\DataNotFoundException
  987. * @throws \think\db\exception\ModelNotFoundException
  988. * @throws \think\exception\DbException
  989. * @throws \think\exception\PDOException
  990. */
  991. public function ProcessDetailEdit()
  992. {
  993. if (Request::instance()->isPost() === false){
  994. $this->error('请求错误');
  995. }
  996. $param = Request::instance()->post();
  997. if (empty($param) || isset($param['UniqId']) === false){
  998. $this->error('参数错误');
  999. }
  1000. if (empty($param['shdh'])){
  1001. $rate['rate0'] = 0;
  1002. $rate['rate1'] = 0;
  1003. }else{
  1004. $rate = \db('dic_lzsh')->where('sys_bh',$param['shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  1005. }
  1006. $data = [
  1007. '重点工序' => isset($param['zdgx'])?$param['zdgx']:'',
  1008. '备选工序' => isset($param['bxgx'])?$param['bxgx']:'',
  1009. 'Gy0_sbbh' => isset($param['sbbh'])?$param['sbbh']:'',
  1010. 'Gy0_Rate0' => isset($rate['rate0'])?$rate['rate0']:0,
  1011. 'Gy0_Rate1' => isset($rate['rate1'])?$rate['rate1']:0,
  1012. 'Gy0_shdh' => isset($param['shdh'])?$param['shdh']:'',
  1013. '损耗系数' => isset($param['shxs'])?$param['shxs']:'',
  1014. '工价系数' => isset($param['ndxs'])?$param['ndxs']:'',
  1015. 'Gy0_小时产能' => $param['xscn'],
  1016. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  1017. ];
  1018. //修改工艺资料
  1019. $sql = \db('工单_工艺资料')->where('UniqId',$param['UniqId'])->fetchSql(true)->update($data);
  1020. $res = Db::query($sql);
  1021. //修改工单状态
  1022. $status = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field('rtrim(gd_statu) as status')->find();
  1023. if ($status['status'] !== '2-生产中'){
  1024. $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  1025. Db::query($statusSql);
  1026. }
  1027. if ($res !== false){
  1028. $this->success('成功');
  1029. }else{
  1030. $this->error('失败');
  1031. }
  1032. }
  1033. /**
  1034. * 工艺资料编辑->机台列表获取
  1035. * @return void
  1036. * @throws \think\db\exception\DataNotFoundException
  1037. * @throws \think\db\exception\ModelNotFoundException
  1038. * @throws \think\exception\DbException
  1039. */
  1040. public function MachineList()
  1041. {
  1042. if ($this->request->isGet() === false){
  1043. $this->error('请求错误');
  1044. }
  1045. $param = $this->request->param();
  1046. if (empty($param)){
  1047. $this->error('参数错误');
  1048. }
  1049. $list = \db('设备_基本资料')
  1050. ->where('存放地点',$param['address'])
  1051. ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
  1052. ->select();
  1053. if (empty($list)){
  1054. $this->success('未找到该车间机台');
  1055. }
  1056. $data = [];
  1057. foreach ($list as $key=>$value){
  1058. $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
  1059. }
  1060. $this->success('成功',$data);
  1061. }
  1062. /**
  1063. * 打印作业通知单->工单印件和工序获取
  1064. * @ApiMethod (GET)
  1065. * @return void
  1066. * @throws \think\db\exception\DataNotFoundException
  1067. * @throws \think\db\exception\ModelNotFoundException
  1068. * @throws \think\exception\DbException
  1069. */
  1070. public function PrintCodeList()
  1071. {
  1072. if ($this->request->isGet() === false){
  1073. $this->error('请求错误');
  1074. }
  1075. $param = $this->request->param();
  1076. if (empty($param)){
  1077. $this->error('参数错误');
  1078. }
  1079. $list = \db('工单_印件资料')
  1080. ->field([
  1081. 'rtrim(yj_Yjno)' => '印件号',
  1082. 'rtrim(yj_yjmc)' => '印件名称'
  1083. ])
  1084. ->where('Yj_Gdbh',$param['workOrder'])
  1085. ->select();
  1086. $this->success('成功',$list);
  1087. }
  1088. /**
  1089. * 打印作业通知单->工艺编号获取
  1090. * @ApiMethod (GET)
  1091. * @return void
  1092. * @throws \think\db\exception\DataNotFoundException
  1093. * @throws \think\db\exception\ModelNotFoundException
  1094. * @throws \think\exception\DbException
  1095. */
  1096. public function ProcessCodeList()
  1097. {
  1098. if ($this->request->isGet() === false){
  1099. $this->error('请求错误');
  1100. }
  1101. $param = $this->request->param();
  1102. if (empty($param)){
  1103. $this->error('参数错误');
  1104. }
  1105. $list = \db('工单_工艺资料')
  1106. ->field('rtrim(Gy0_gxh) as 工序号')
  1107. ->where([
  1108. 'Gy0_gdbh' => $param['workOrder'],
  1109. 'Gy0_yjno' => $param['yjno']
  1110. ])
  1111. ->select();
  1112. $this->success('成功',$list);
  1113. }
  1114. /**
  1115. * 打印作业通知单
  1116. * @ApiMethod (POST)
  1117. * @param void
  1118. * @return void
  1119. * @throws \think\db\exception\DataNotFoundException
  1120. * @throws \think\db\exception\ModelNotFoundException
  1121. * @throws \think\exception\DbException
  1122. */
  1123. public function PrintJobOrder()
  1124. {
  1125. if ($this->request->isGet() === false) {
  1126. $this->error('请求错误');
  1127. }
  1128. $param = $this->request->param();
  1129. if (empty($param)){
  1130. $this->error('参数错误');
  1131. }
  1132. $data = $this->workOrderDetailGet($param['workOrder'],$param['yjno']);
  1133. if (empty($data)){
  1134. $this->success('未找到工单信息');
  1135. }
  1136. $materiel = $this->MaterielDetailGet($param['workOrder']);
  1137. $printDetail = $this->PrintDetailGet($param['workOrder'],$param['yjno'],$param['gxh']);
  1138. if (empty($printDetail)){
  1139. $this->success('未找到工艺信息');
  1140. }
  1141. $number = 0;
  1142. foreach ($printDetail as $key=>$value){
  1143. $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
  1144. $number = $number+$value['允损比例'];
  1145. }
  1146. $data['制单'] = $param['PrepareDocument'];
  1147. $data['审核'] = $param['examine'];
  1148. $data['目标合格率'] = 100-$number.'%';
  1149. $data['materiel'] = $materiel;
  1150. $data['printDetail'] = $printDetail;
  1151. $this->success('成功',$data);
  1152. }
  1153. /**
  1154. * 打印作业通知单->工单及印件资料获取
  1155. * @param $workOrder
  1156. * @return mixed
  1157. */
  1158. public function workOrderDetailGet($workOrder,$yjno)
  1159. {
  1160. $sql = "SELECT
  1161. RTRIM( a.Gd_lx) AS 工单类型,
  1162. RTRIM( a.Gd_gdbh ) AS 生产批次号,
  1163. RTRIM( a.销售订单号 ) AS 销售订单号,
  1164. RTRIM( a.Gd_客户代号 ) AS 客户代号,
  1165. RTRIM( a.Gd_客户名称 ) AS 客户名称,
  1166. RTRIM( a.成品代号 ) AS 产品代码,
  1167. RTRIM( a.成品名称 ) AS 产品名称,
  1168. RTRIM( a.产品版本号 ) AS 版本号,
  1169. RTRIM( a.警语版面 ) AS 警语版面,
  1170. RTRIM( a.码源数量 ) AS 码源数量,
  1171. RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
  1172. RTRIM( a.接单日期 ) AS 开单日期,
  1173. RTRIM( a.交货日期 ) AS 交货日期,
  1174. RTRIM( a.Gd_desc ) AS 工单说明,
  1175. RTRIM( a.投料率 ) AS 投料率,
  1176. RTRIM( a.平均合格率 ) AS 平均合格率,
  1177. RTRIM( a.投料大箱 ) AS 订货数量,
  1178. RTRIM( a.排产时库存 ) AS 排产时库存,
  1179. RTRIM( b.yj_Yjno ) AS 印件,
  1180. RTRIM( b.yj_Yjdh ) AS 印件代号,
  1181. RTRIM( b.yj_yjmc ) AS 印件名称,
  1182. RTRIM( b.yj_平张投料 ) AS 平张投料量,
  1183. RTRIM( b.yj_zzmc ) AS 纸张名称,
  1184. RTRIM( b.yj_tlgg ) AS 投料规格,
  1185. RTRIM( b.yj_ks ) AS 开数,
  1186. RTRIM( b.yj_ls ) AS 联数,
  1187. RTRIM( b.yj_desc ) AS 印件备注
  1188. FROM
  1189. `工单_基本资料` AS a
  1190. JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh
  1191. WHERE
  1192. a.Gd_gdbh = '{$workOrder}' AND a.行号 = 1 AND b.yj_Yjno = '{$yjno}'";
  1193. $list = Db::query($sql);
  1194. if (empty($list)){
  1195. $this->success('未找到订单数据');
  1196. }
  1197. $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
  1198. $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
  1199. $list[0]['订货数量'] = (int)$list[0]['订货数量'];
  1200. $list[0]['联数'] = (int)$list[0]['联数'];
  1201. $list[0]['印件代号及名称'] = $list[0]['印件代号'].' '.$list[0]['印件名称'];
  1202. $list[0]['投料数量'] = $list[0]['订货数量'];
  1203. unset($list[0]['印件代号'],$list[0]['印件名称']);
  1204. return($list[0]);
  1205. }
  1206. /**打印作业流程单->物料资料获取
  1207. * @param $workOrder
  1208. * @return bool|\PDOStatement|string|\think\Collection
  1209. * @throws \think\db\exception\DataNotFoundException
  1210. * @throws \think\db\exception\ModelNotFoundException
  1211. * @throws \think\exception\DbException
  1212. */
  1213. public function MaterielDetailGet($workOrder)
  1214. {
  1215. $where = [
  1216. 'BOM_工单编号' => $workOrder,
  1217. ];
  1218. $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
  1219. $list = \db('工单_bom资料')->where($where)->field($filed)->select();
  1220. if (!empty($list)){
  1221. foreach ($list as $key=>$value){
  1222. $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
  1223. $list[$key]['计划用量'] = (float)$value['计划用量'];
  1224. unset($list[$key]['物料编码'],$list[$key]['物料名称']);
  1225. }
  1226. }
  1227. return $list;
  1228. }
  1229. /**
  1230. * 打印作业流程单->工艺资料获取
  1231. * @param $workOrder
  1232. * @return bool|\PDOStatement|string|\think\Collection
  1233. * @throws \think\db\exception\DataNotFoundException
  1234. * @throws \think\db\exception\ModelNotFoundException
  1235. * @throws \think\exception\DbException
  1236. */
  1237. public function PrintDetailGet($workOrder,$yjno,$gxh)
  1238. {
  1239. $where = [
  1240. 'Gy0_gdbh' => $workOrder,
  1241. 'Gy0_yjno' => $yjno,
  1242. 'Gy0_gxh' => ['<=',$gxh]
  1243. ];
  1244. $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  1245. rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
  1246. rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
  1247. $list = \db('工单_工艺资料')
  1248. ->where($where)
  1249. ->field($filed)
  1250. ->select();
  1251. if (empty($list)){
  1252. $this->success('工单工艺为空');
  1253. }
  1254. foreach ($list as $key=>$value){
  1255. if ($value['yjno']<10){
  1256. $value['yjno'] = '0'.$value['yjno'];
  1257. }
  1258. if ($value['gxh']<10){
  1259. $value['gxh'] = '0'.$value['gxh'];
  1260. }
  1261. if ($value['add_gxmc'] !== null){
  1262. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  1263. }else{
  1264. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  1265. }
  1266. $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
  1267. $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
  1268. if ((int)$value['计划接货数'] === 0){
  1269. $list[$key]['允损比例'] = 0;
  1270. }else{
  1271. $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
  1272. }
  1273. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
  1274. }
  1275. return $list;
  1276. }
  1277. /**
  1278. * 获取小时产能
  1279. * @ApiMethod (GET)
  1280. * @param void
  1281. * @return void
  1282. * @throws \think\db\exception\DataNotFoundException
  1283. * @throws \think\db\exception\ModelNotFoundException
  1284. * @throws \think\exception\DbException
  1285. */
  1286. public function capacityList()
  1287. {
  1288. if ($this->request->isGet() === false){
  1289. $this->error('请求错误');
  1290. }
  1291. $param = $this->request->param();
  1292. if (empty($param)){
  1293. $this->error('参数错误');
  1294. }
  1295. $machine = explode(' ',$param['machine'])[0];
  1296. $number = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(排单小时定额) as 小时产能')->find();
  1297. if (empty($number)){
  1298. $this->error('未找到小时产能');
  1299. }
  1300. $this->success('成功',$number['小时产能']);
  1301. }
  1302. /**
  1303. * 新增工单->添加工单
  1304. * @ApiMethod (POST)
  1305. * @param
  1306. * @return void
  1307. * @throws \think\Exception
  1308. * @throws \think\db\exception\BindParamException
  1309. * @throws \think\db\exception\DataNotFoundException
  1310. * @throws \think\db\exception\ModelNotFoundException
  1311. * @throws \think\exception\DbException
  1312. * @throws \think\exception\PDOException
  1313. */
  1314. public function WorkOrderAdd()
  1315. {
  1316. if (Request::instance()->isPost() === false){
  1317. $this->error('请求错误');
  1318. }
  1319. $param = Request::instance()->post();
  1320. if (empty($param)){
  1321. $this->error('参数错误');
  1322. }
  1323. $num = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->count();
  1324. //插入产品资料
  1325. $productData = \db('产品_基本资料')
  1326. ->where('产品编号',$param['cpdh'])
  1327. ->count();
  1328. if ($productData === 0) {
  1329. $clientCode = substr($param['cpdh'], 0, 5);
  1330. $product = [
  1331. '客户编号' => $clientCode,
  1332. '客户名称' => $param['khmc'],
  1333. '产品编号' => $param['cpdh'],
  1334. '产品名称' => $param['cpmc'],
  1335. '计量单位' => '万张',
  1336. '状态' => '',
  1337. 'Mod_rq' => date('Y-m-d H:i:s', time()),
  1338. 'UniqID' => \db('产品_基本资料')->order('UniqID desc')->value('UniqID') + 1,
  1339. ];
  1340. if (strpos($product['产品名称'], '小盒') === false) {
  1341. $product['产品类别'] = '条盒';
  1342. } else {
  1343. $product['产品类别'] = '小盒';
  1344. }
  1345. $productSql = \db('产品_基本资料')->fetchSql(true)->insert($product);
  1346. \db()->query($productSql);
  1347. }
  1348. //添加工单
  1349. $productDetail = \db('产品_基本资料')->where('产品编号',$param['cpdh'])->find();
  1350. if (empty($productDetail)){
  1351. $productDetail['客户料号'] = '';
  1352. }
  1353. $lastId = \db('工单_基本资料')->order('Uniqid desc')->value('Uniqid');
  1354. if ($lastId<1000000000){
  1355. $lastId = 1000000000;
  1356. }
  1357. $data = [
  1358. 'Gd_lx' =>$param['zdgd'],
  1359. 'Gd_生产分类' =>$param['sclx'],
  1360. '成本处理类别' =>'',
  1361. 'Gd_gdbh' =>$param['gdbh'],
  1362. '行号' =>$num+1 ,
  1363. 'Gd_客户代号' =>$param['khdh'],
  1364. 'Gd_客户名称' =>$param['khmc'],
  1365. 'Gd_khdh' =>$param['khdh'],
  1366. 'Gd_khmc' =>$param['khmc'],
  1367. '客户料号' =>rtrim($productDetail['客户料号']),
  1368. '客户ERP编码' =>$param['erp'],
  1369. 'Gd_cpdh' =>$param['cpdh'],
  1370. 'Gd_cpmc' =>$param['cpmc'],
  1371. '成品代号' =>$param['cpdh'],
  1372. '成品名称' =>$param['cpmc'],
  1373. '产品版本号' =>$param['bbh'],
  1374. '销售订单号' =>$param['xsddh'],
  1375. '警语版面' =>$param['jybm'],
  1376. '码源数量' =>$param['mysl'],
  1377. '排产时库存' =>$param['kcdx'],
  1378. '投料大箱' =>$param['tldx'],
  1379. '投料率' =>$param['tll'],
  1380. '平均合格率' =>$param['hgl'],
  1381. '进程备注' =>$param['jcbz'],
  1382. 'Gd_desc' =>$param['remark'],
  1383. '开单日期' =>date('Y-m-d H:i:s',time()),
  1384. '接单日期' =>$param['start'],
  1385. '交货日期' =>$param['end'],
  1386. '订单数量' =>$param['number'],
  1387. '计量单位' =>$param['tldw'],
  1388. '计划投料' =>$param['pztl'],
  1389. '实际投料' =>$param['wxz'],
  1390. '产品单价' =>0,
  1391. '入仓日期' =>'1900-01-01 00:00:00',
  1392. '工单入仓数量' =>0,
  1393. '工单制程废品' => 0,
  1394. '工单质检废品' => 0,
  1395. '工单无形损' => 0,
  1396. '工单计划损耗' => 0,
  1397. '工单完工日期' => $param['end'],
  1398. '投料确认' => '',
  1399. 'gd_statu' => '3-计划中',
  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. '加工费单价' => 0,
  1420. '成本考核_胶印' => 1,
  1421. '成本考核_凹印' => 1,
  1422. '成本考核_丝印' => 1,
  1423. '成本考核_模切' => 1,
  1424. '成本考核_检验' => 1,
  1425. '印版费' => 0,
  1426. 'V23制造成本' => 0,
  1427. 'Prt_rq' => date('Y-m-d H:i:s',time()),
  1428. 'Sys_id' => $param['Sys_id'],
  1429. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  1430. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  1431. 'U8UID' => '',
  1432. 'Uniqid' => $lastId+1,
  1433. '工序加工费' => 0,
  1434. ];
  1435. $sql= \db('工单_基本资料')->fetchSql(true)->insert($data);
  1436. $res = \db()->query($sql);
  1437. if ($res !== false){
  1438. $this->success('成功');
  1439. }else{
  1440. $this->error('失败');
  1441. }
  1442. }
  1443. /**
  1444. * 新增工单->客户代号列表获取
  1445. * @return void
  1446. * @throws \think\db\exception\BindParamException
  1447. * @throws \think\exception\PDOException
  1448. */
  1449. public function ClientList()
  1450. {
  1451. if ($this->request->isGet() === false){
  1452. $this->error('请求错误');
  1453. }
  1454. $param = $this->request->param();
  1455. if (isset($param['search'])){
  1456. $where = $param['search'].'%';
  1457. $sql = "SELECT DISTINCT
  1458. (客户编号),rtrim(客户名称 ) as 客户名称
  1459. FROM
  1460. `产品_基本资料`
  1461. WHERE
  1462. 客户编号 LIKE "."'".$where."'"."
  1463. OR
  1464. 客户名称 LIKE "."'".$where."'"."
  1465. GROUP BY
  1466. 客户编号
  1467. order by
  1468. 客户编号";
  1469. }else{
  1470. $sql = "SELECT DISTINCT
  1471. (客户编号),rtrim(客户名称 ) as 客户名称
  1472. FROM
  1473. `产品_基本资料`
  1474. GROUP BY
  1475. 客户编号
  1476. order by
  1477. 客户编号";
  1478. }
  1479. $list = \db()->query($sql);
  1480. if (empty($list)){
  1481. $this->success('未找到客户列表');
  1482. }
  1483. foreach ($list as $key=>$value){
  1484. if (empty($value['客户编号'])){
  1485. unset($list[$key]);
  1486. }else{
  1487. $list[$key]['客户编号'] = rtrim($value['客户编号']);
  1488. $list[$key]['name'] = rtrim($value['客户编号']).'【'.$value['客户名称'].'】';
  1489. if ($value['客户编号'] == '1098'){
  1490. $list[$key]['客户名称'] = '打样专用';
  1491. }
  1492. }
  1493. }
  1494. $list = array_values($list);
  1495. $this->success('成功',$list);
  1496. }
  1497. /**
  1498. * 新增工单->产品代号获取
  1499. * @ApiMethod (GET)
  1500. * @param void
  1501. * @return void
  1502. * @throws \think\db\exception\DataNotFoundException
  1503. * @throws \think\db\exception\ModelNotFoundException
  1504. * @throws \think\exception\DbException
  1505. */
  1506. public function ProductCodeList()
  1507. {
  1508. if ($this->request->isGet() === false){
  1509. $this->error('请求错误');
  1510. }
  1511. $param = $this->request->param();
  1512. if (isset($param['cilent']) === false){
  1513. $this->error('参数错误');
  1514. }
  1515. $where = ['产品编号'=>['like',$param['cilent'].'%']];
  1516. $list = \db('产品_基本资料')
  1517. ->where($where)
  1518. ->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
  1519. ->select();
  1520. if (empty($list)){
  1521. $this->success('未获取到产品数据');
  1522. }
  1523. foreach ($list as $key=>$value){
  1524. $list[$key]['name'] = $value['产品编号'].'【'.$value['产品名称'].'】';
  1525. }
  1526. $this->success('成功',$list);
  1527. }
  1528. /**
  1529. * 新增印件资料->印件资料添加
  1530. * @return void
  1531. * @throws \think\db\exception\BindParamException
  1532. * @throws \think\exception\PDOException
  1533. */
  1534. public function PrintDetailAdd()
  1535. {
  1536. if (Request::instance()->isPost() === false){
  1537. $this->error('请求错误');
  1538. }
  1539. $param = Request::instance()->post();
  1540. if (empty($param)){
  1541. $this->error('参数错误');
  1542. }
  1543. $lastId = \db('工单_印件资料')->order('Uniqid desc')->value('Uniqid');
  1544. if (empty($lastId)){
  1545. $lastId = 0;
  1546. }else{
  1547. $lastId = $lastId + 1;
  1548. }
  1549. $param['Uniqid'] = $lastId;
  1550. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1551. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  1552. $sql = \db('工单_印件资料')->fetchSql(true)->insert($param);
  1553. $res = \db()->query($sql);
  1554. if ($res !== false){
  1555. $this->success('成功');
  1556. }else{
  1557. $this->error('失败');
  1558. }
  1559. }
  1560. /**
  1561. * 新增工艺资料->工艺资料添加
  1562. * @return void
  1563. * @throws \think\db\exception\BindParamException
  1564. * @throws \think\exception\PDOException
  1565. */
  1566. public function ProcessDetailAdd()
  1567. {
  1568. if (Request::instance()->isPost() === false){
  1569. $this->error('请求错误');
  1570. }
  1571. $param = Request::instance()->post();
  1572. if (empty($param)){
  1573. $this->error('参数错误');
  1574. }
  1575. $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  1576. if (empty($lastId)){
  1577. $lastId = 0;
  1578. }else{
  1579. $lastId = $lastId + 1;
  1580. }
  1581. if (empty($param['Gy0_shdh'])){
  1582. $param['Gy0_Rate0'] = 0;
  1583. $param['Gy0_Rate1'] = 0;
  1584. }else{
  1585. $detail = \db('dic_lzsh')->field('sys_rate0,sys_rate1')->where('sys_bh',$param['Gy0_shdh'])->find();
  1586. $param['Gy0_Rate0'] = $detail['sys_rate0'];
  1587. $param['Gy0_Rate1'] = $detail['sys_rate1'];
  1588. }
  1589. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1590. $param['Mod_rq'] = '1900-01-01 00:00:00';
  1591. $param['Gy0_sj1'] = '1900-01-01 00:00:00';
  1592. $param['Gy0_sj2'] = '1900-01-01 00:00:00';
  1593. $param['PD_WG'] = '1900-01-01 00:00:00';
  1594. $param['UniqId'] = $lastId;
  1595. $sql = \db('工单_工艺资料')
  1596. ->fetchSql(true)
  1597. ->insert($param);
  1598. $res = \db()->query($sql);
  1599. //获取平张投料
  1600. $number = \db('工单_印件资料')
  1601. ->where('Yj_Gdbh',$param['Gy0_gdbh'])
  1602. ->where('yj_Yjno',$param['Gy0_yjno'])
  1603. ->value('rtrim(yj_平张投料)');
  1604. //分配工艺计划产量
  1605. $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],$param['Gy0_gxh'],$number);
  1606. if ($res !== false){
  1607. $this->success('成功');
  1608. }else{
  1609. $this->error('失败');
  1610. }
  1611. }
  1612. /**
  1613. * 新增工艺资料->印件编号获取
  1614. * @return void
  1615. * @throws \think\db\exception\DataNotFoundException
  1616. * @throws \think\db\exception\ModelNotFoundException
  1617. * @throws \think\exception\DbException
  1618. */
  1619. public function PrintDetailList()
  1620. {
  1621. if ($this->request->isGet() === false){
  1622. $this->error('请求错误');
  1623. }
  1624. $param = $this->request->param();
  1625. if (empty($param)){
  1626. $this->error('参数错误');
  1627. }
  1628. $printList = \db('工单_印件资料')
  1629. ->where('Yj_Gdbh',$param['workOrder'])
  1630. ->order('yj_Yjno')
  1631. ->select();
  1632. if (empty($printList)){
  1633. $this->success('未找到该工单印件资料');
  1634. }
  1635. $list = [];
  1636. foreach ($printList as $key=>$value){
  1637. $list[$key]['name'] = rtrim($value['yj_Yjno']).'-->'.rtrim($value['yj_yjmc']);
  1638. $list[$key]['no'] = rtrim($value['yj_Yjno']);
  1639. }
  1640. $this->success('成功',$list);
  1641. }
  1642. /**
  1643. * 工单资料管理->印件资料删除
  1644. * @return void
  1645. * @throws \think\Exception
  1646. * @throws \think\exception\PDOException
  1647. */
  1648. public function PrintDetailDel()
  1649. {
  1650. if ($this->request->isGet() === false){
  1651. $this->error('请求错误');
  1652. }
  1653. $param = $this->request->param();
  1654. if (isset($param['UniqId']) === false){
  1655. $this->error('参数错误');
  1656. }
  1657. $printId = explode(',',$param['UniqId']);
  1658. $i = 0;
  1659. foreach ($printId as $value){
  1660. $res = \db('工单_印件资料')
  1661. ->where('Uniqid',$value)
  1662. ->delete();
  1663. if ($res === false){
  1664. $i++;
  1665. }
  1666. }
  1667. if ($i === 0){
  1668. $this->success('删除成功');
  1669. }else{
  1670. $this->error('删除失败');
  1671. }
  1672. }
  1673. /**
  1674. * 工单资料管理->工艺资料删除
  1675. * @return void
  1676. * @throws \think\Exception
  1677. * @throws \think\exception\PDOException
  1678. */
  1679. public function ProcessDetailDel()
  1680. {
  1681. if ($this->request->isGet() === false){
  1682. $this->error('请求错误');
  1683. }
  1684. $param = $this->request->param();
  1685. if (isset($param['UniqId']) === false){
  1686. $this->error('参数错误');
  1687. }
  1688. $printId = explode(',',$param['UniqId']);
  1689. $i = 0;
  1690. //获取工单编号、印件号
  1691. $codeList = \db('工单_工艺资料')
  1692. ->where('UniqId',$printId[0])
  1693. ->field('rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_yjno) as 印件号')
  1694. ->find();
  1695. //获取平张投料数量
  1696. $number = \db('工单_印件资料')
  1697. ->where([
  1698. 'Yj_Gdbh' => $codeList['工单编号'],
  1699. 'yj_Yjno' => $codeList['印件号']
  1700. ])
  1701. ->value('rtrim(yj_平张投料)');
  1702. //循环删除工艺资料
  1703. foreach ($printId as $value){
  1704. $res = \db('工单_工艺资料')
  1705. ->where('UniqId',$value)
  1706. ->delete();
  1707. if ($res === false){
  1708. $i++;
  1709. }
  1710. }
  1711. //重新分配工艺计划产量
  1712. $this->PlannedProcessYield($codeList['工单编号'],$codeList['印件号'],0,$number);
  1713. if ($i === 0){
  1714. $this->success('删除成功');
  1715. }else{
  1716. $this->error('删除失败');
  1717. }
  1718. }
  1719. /**
  1720. * 工艺资料添加->工序损耗代码
  1721. * @return void
  1722. * @throws \think\db\exception\DataNotFoundException
  1723. * @throws \think\db\exception\ModelNotFoundException
  1724. * @throws \think\exception\DbException
  1725. */
  1726. public function WastageList()
  1727. {
  1728. if ($this->request->isGet() === false){
  1729. $this->error('请求错误');
  1730. }
  1731. $param = $this->request->param();
  1732. if (empty($param['process'])){
  1733. $this->error('参数错误');
  1734. }
  1735. $order = \db('dic_lzsh')
  1736. ->where('sys_mc','like',$param['process'].'%')
  1737. ->value('rtrim(sys_bh) as 编号');
  1738. $this->success('成功',$order);
  1739. }
  1740. /**
  1741. * 获取产品附件列表
  1742. */
  1743. public function getAnnexTable(){
  1744. if(!$this->request->isGet()){
  1745. $this->error('请求方式错误');
  1746. }
  1747. $req = $this->request->param();
  1748. if (isset($req['cpdh']) && !empty($req['cpdh'])){
  1749. $where['关联产品'] = ['LIKE','%'.$req['cpdh'].'%'];
  1750. }else{
  1751. $this->error('参数错误');
  1752. }
  1753. $rows = db('产品_技术附件')
  1754. ->where($where)
  1755. ->select();
  1756. foreach ($rows as $key=>&$value){
  1757. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  1758. $value['附件内容'] = '';
  1759. }
  1760. }
  1761. $this->success('成功',$rows);
  1762. }
  1763. /**
  1764. * 产品附件新增
  1765. */
  1766. public function annexAdd(){
  1767. if(!$this->request->isPost()){
  1768. $this->error('请求方式错误');
  1769. }
  1770. $req = $this->request->param();
  1771. $arr = [
  1772. 'sys_id',
  1773. '序号',
  1774. '附件备注',
  1775. '附件内容',
  1776. '附件类型',
  1777. '适用工序',
  1778. '关联产品'
  1779. ];
  1780. $data = [];
  1781. foreach ($arr as $key => $value){
  1782. if (!isset($req[$value])){
  1783. $this->error('参数错误',$value,$key+1);
  1784. }
  1785. $data[$value] = $req[$value];
  1786. }
  1787. $data['sys_rq'] = date('Y-m-d H:i:s');
  1788. //查询UniqId
  1789. $UniqId = db('产品_技术附件')->max('UniqId');
  1790. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  1791. //开启事务
  1792. db()->startTrans();
  1793. try{
  1794. $sql = db('产品_技术附件')->fetchSql(true)->insert($data);
  1795. $bool = db()->query($sql);
  1796. // 提交事务
  1797. db()->commit();
  1798. } catch (\Exception $e) {
  1799. // 回滚事务
  1800. db()->rollback();
  1801. $this->error($e->getMessage());
  1802. }
  1803. if($bool===false) $this->error('失败');
  1804. $this->success('成功');
  1805. }
  1806. /**
  1807. * 产品附件修改
  1808. * @ApiMethod (GET)
  1809. * @param string 'UniqId'
  1810. */
  1811. public function annexDel()
  1812. {
  1813. if(!$this->request->isGet()){
  1814. $this->error('请求方式错误');
  1815. }
  1816. $req = $this->request->param();
  1817. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  1818. $this->error('参数错误','UniqId',100);
  1819. }
  1820. //开启事务
  1821. db()->startTrans();
  1822. try{
  1823. $bool = db('产品_技术附件')->where('UniqId',$req['UniqId'])->delete();
  1824. // 提交事务
  1825. db()->commit();
  1826. } catch (\Exception $e) {
  1827. // 回滚事务
  1828. db()->rollback();
  1829. $this->error($e->getMessage());
  1830. }
  1831. if($bool===false) $this->error('失败');
  1832. $this->success('成功');
  1833. }
  1834. /**
  1835. * 获取产品附件列表
  1836. */
  1837. public function getGdAnnexTable(){
  1838. if(!$this->request->isGet()){
  1839. $this->error('请求方式错误');
  1840. }
  1841. $req = $this->request->param();
  1842. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  1843. $where['关联编号'] = ['LIKE','%'.$req['gdbh'].'%'];
  1844. }else{
  1845. $this->error('参数错误');
  1846. }
  1847. $rows = db('工单_相关附件')
  1848. ->where($where)
  1849. ->select();
  1850. foreach ($rows as $key=>&$value){
  1851. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  1852. $value['附件内容'] = '';
  1853. }
  1854. }
  1855. $this->success('成功',$rows);
  1856. }
  1857. /**
  1858. * 产品附件新增
  1859. */
  1860. public function gdAnnexAdd(){
  1861. if(!$this->request->isPost()){
  1862. $this->error('请求方式错误');
  1863. }
  1864. $req = $this->request->param();
  1865. $arr = [
  1866. 'sys_id',
  1867. '附件备注',
  1868. '附件内容',
  1869. '附件类型',
  1870. '关联编号'
  1871. ];
  1872. $data = [];
  1873. foreach ($arr as $key => $value){
  1874. if (!isset($req[$value])){
  1875. $this->error('参数错误',$value,$key+1);
  1876. }
  1877. $data[$value] = $req[$value];
  1878. }
  1879. $data['sys_rq'] = date('Y-m-d H:i:s');
  1880. //查询UniqId
  1881. $UniqId = db('工单_相关附件')->max('UniqId');
  1882. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  1883. //开启事务
  1884. db()->startTrans();
  1885. try{
  1886. $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  1887. $bool = db()->query($sql);
  1888. // 提交事务
  1889. db()->commit();
  1890. } catch (\Exception $e) {
  1891. // 回滚事务
  1892. db()->rollback();
  1893. $this->error($e->getMessage());
  1894. }
  1895. if($bool===false) $this->error('失败');
  1896. $this->success('成功');
  1897. }
  1898. /**
  1899. * 产品附件修改
  1900. * @ApiMethod (GET)
  1901. * @param string 'UniqId'
  1902. */
  1903. public function gdAnnexDel()
  1904. {
  1905. if(!$this->request->isGet()){
  1906. $this->error('请求方式错误');
  1907. }
  1908. $req = $this->request->param();
  1909. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  1910. $this->error('参数错误','UniqId',100);
  1911. }
  1912. //开启事务
  1913. db()->startTrans();
  1914. try{
  1915. $bool = db('工单_相关附件')->where('UniqId',$req['UniqId'])->delete();
  1916. // 提交事务
  1917. db()->commit();
  1918. } catch (\Exception $e) {
  1919. // 回滚事务
  1920. db()->rollback();
  1921. $this->error($e->getMessage());
  1922. }
  1923. if($bool===false) $this->error('失败');
  1924. $this->success('成功');
  1925. }
  1926. /**
  1927. * 引用工单资料数据查询
  1928. * @return void
  1929. * @throws \think\db\exception\DataNotFoundException
  1930. * @throws \think\db\exception\ModelNotFoundException
  1931. * @throws \think\exception\DbException
  1932. */
  1933. public function WorkOrderDetailCope()
  1934. {
  1935. if ($this->request->isGet() === false){
  1936. $this->error('请求错误');
  1937. }
  1938. $param = $this->request->param();
  1939. if (empty($param['search'])){
  1940. $this->error('参数错误');
  1941. }
  1942. $list = \Db('工单_基本资料')
  1943. ->alias('a')
  1944. ->field([
  1945. 'rtrim(a.Gd_gdbh)' => '工单编号',
  1946. 'rtrim(b.客户编号)' => '客户编号',
  1947. 'rtrim(b.客户名称)' => '客户名称',
  1948. 'rtrim(b.产品编号)' => '产品编号',
  1949. 'rtrim(b.产品名称)' => '产品名称'
  1950. ])
  1951. ->join('产品_基本资料 b', 'a.成品代号 = b.产品编号')
  1952. ->join('产品_工艺资料 c', 'a.成品代号 = c.Gy0_cpdh')
  1953. ->join('产品_印件资料 d', 'a.成品代号 = d.yj_cpdh')
  1954. ->where(function($query) use ($param) {
  1955. $query->where('a.Gd_gdbh', 'like', '%'.$param['search'].'%')
  1956. ->whereOr('a.成品名称', 'like', '%'.$param['search'].'%');
  1957. })
  1958. ->where(function($query) {
  1959. $query->where('c.Gy0_cpdh', '<>', '')
  1960. ->where('d.yj_cpdh', '<>', '')
  1961. ->where('b.状态', 'not like', '%停用%')
  1962. ->where('b.产品名称', 'not like', '%停用%');
  1963. })
  1964. ->group('a.Gd_gdbh')
  1965. ->order('a.Uniqid desc')
  1966. ->select();
  1967. if (empty($list)){
  1968. $this->success('未找到工单资料');
  1969. }else{
  1970. $this->success('成功',$list);
  1971. }
  1972. }
  1973. /**
  1974. * 引用产品印件、工艺资料
  1975. * @return void
  1976. * @throws \think\db\exception\BindParamException
  1977. * @throws \think\db\exception\DataNotFoundException
  1978. * @throws \think\db\exception\ModelNotFoundException
  1979. * @throws \think\exception\DbException
  1980. * @throws \think\exception\PDOException
  1981. */
  1982. public function WorkOrderDetailListCope()
  1983. {
  1984. if (Request::instance()->isPost() === false){
  1985. $this->error('请求错误');
  1986. }
  1987. $param = Request::instance()->post();
  1988. if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
  1989. $this->error('参数错误');
  1990. }
  1991. //引用工艺资料
  1992. $processWhere = [
  1993. 'Gy0_方案' => $param['option'],
  1994. 'Gy0_cpdh' => $param['productCode']
  1995. ];
  1996. $ProcessList = \db('产品_工艺资料')
  1997. ->where($processWhere)
  1998. ->select();
  1999. if (empty($ProcessList)){
  2000. $this->error('未找到产品工艺资料');
  2001. }
  2002. $ProcesslastId = \db('工单_工艺资料')->order('UniqId desc')->value('rtrim(UniqId)');
  2003. foreach ($ProcessList as $key=>$value){
  2004. $ProcessList[$key]['Gy0_gdbh'] = $param['workorder'];
  2005. $ProcessList[$key]['Gy0_gxmc'] = $value['gy0_gxmc'];
  2006. $ProcessList[$key]['Gy0_SITE'] = $value['Gy0_site'];
  2007. $ProcessList[$key]['Gy0_ks'] = $value['Gy0_Ks'];
  2008. $ProcessList[$key]['Gy0_ms'] = $value['Gy0_Ms'];
  2009. $ProcessList[$key]['Gy0_oil'] = $value['Gy0_Oil'];
  2010. $ProcessList[$key]['Gy0_计划接货数'] = 0;
  2011. $ProcessList[$key]['Gy0_计划损耗'] = 0;
  2012. $ProcessList[$key]['无形损承担比例'] = 0;
  2013. $ProcessList[$key]['超节损承担比例'] = 0;
  2014. $ProcessList[$key]['超节损核算单价'] = 0;
  2015. $ProcessList[$key]['Gy0_sj1'] = '1900-01-01 00:00:00';
  2016. $ProcessList[$key]['Gy0_sj2'] = '1900-01-01 00:00:00';
  2017. $ProcessList[$key]['UniqId'] = $ProcesslastId + $key + 1;
  2018. $ProcessList[$key]['PD_WG'] = '1900-01-01 00:00:00';
  2019. $ProcessList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  2020. $ProcessList[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  2021. 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']);
  2022. }
  2023. //引用印件资料
  2024. $PrintList = \db('产品_印件资料')
  2025. ->where('yj_cpdh',$param['productCode'])
  2026. ->select();
  2027. if (empty($PrintList)){
  2028. $this->error('未找到印件资料');
  2029. }
  2030. $PrintLastId = \db('工单_印件资料')->order('Uniqid desc')->value('rtrim(Uniqid)');
  2031. $number = \db('工单_基本资料')
  2032. ->where('Gd_gdbh',$param['workorder'])
  2033. ->where('成品代号',$param['productCode'])
  2034. ->value('rtrim(计划投料)');
  2035. foreach ($PrintList as $key => $value){
  2036. $PrintList[$key]['Yj_Gdbh'] = $param['workorder'];
  2037. $PrintList[$key]['yj_Yjno'] = $value['yj_yjno'];
  2038. $PrintList[$key]['yj_Yjdh'] = $value['yj_yjdh'];
  2039. $PrintList[$key]['yj_平张投料'] = $number;
  2040. $PrintList[$key]['Sys_id'] = $value['sys_id'];
  2041. $PrintList[$key]['Uniqid'] = $PrintLastId + $key + 1;
  2042. $PrintList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  2043. $PrintList[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  2044. 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']);
  2045. }
  2046. //插入数据
  2047. $processSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($ProcessList);
  2048. $processRes = \db()->query($processSql);
  2049. if ($processRes === false){
  2050. $this->error('插入工艺资料失败');
  2051. }
  2052. $printSql = \db('工单_印件资料')->fetchSql(true)->insertAll($PrintList);
  2053. $printRes = \db()->query($printSql);
  2054. if ($printRes === false){
  2055. $this->error('插入印件资料失败');
  2056. }
  2057. //计算工序计划生产数量
  2058. if ($number !== 0){
  2059. foreach ($PrintList as $value){
  2060. $this->PlannedProcessYield($param['workorder'],$value['yj_Yjno'],0,$number);
  2061. }
  2062. }
  2063. $this->success('成功');
  2064. }
  2065. /**
  2066. * 引用产品印件、工艺资料->信息获取
  2067. * @return void
  2068. * @throws \think\db\exception\DataNotFoundException
  2069. * @throws \think\db\exception\ModelNotFoundException
  2070. * @throws \think\exception\DbException
  2071. */
  2072. public function ProductCopeDetail()
  2073. {
  2074. if ($this->request->isGet() === false){
  2075. $this->error('请求错误');
  2076. }
  2077. $param = $this->request->param();
  2078. if (empty($param['workorder'])){
  2079. $this->error('参数错误');
  2080. }
  2081. $list = \db('工单_基本资料')
  2082. ->alias('a')
  2083. ->field([
  2084. 'rtrim(a.Gd_gdbh)' => '工单编号',
  2085. 'rtrim(b.客户编号)' => '客户编号',
  2086. 'rtrim(b.客户名称)' => '客户名称',
  2087. 'rtrim(b.产品编号)' => '产品编号',
  2088. 'rtrim(b.产品名称)' => '产品名称'
  2089. ])
  2090. ->join('产品_基本资料 b','a.成品代号 = b.产品编号')
  2091. ->where('a.Gd_gdbh',$param['workorder'])
  2092. ->find();
  2093. if (empty($list)){
  2094. $this->error('未找到工单信息');
  2095. }
  2096. $option = \db('产品_工艺资料')
  2097. ->field('rtrim(Gy0_方案) as 方案')
  2098. ->where('Gy0_cpdh',$list['产品编号'])
  2099. ->group('Gy0_方案')
  2100. ->select();
  2101. $list['方案'] = $option;
  2102. $this->success('成功',$list);
  2103. }
  2104. /**
  2105. * 工艺资料计划产量重新分配
  2106. * @param string $workOrder 工单
  2107. * @param int $yjno 印件号
  2108. * @param int $gxh 工序号
  2109. * @param int $feed 平张投料
  2110. * @return bool
  2111. * @throws \think\Exception
  2112. * @throws \think\db\exception\BindParamException
  2113. * @throws \think\db\exception\DataNotFoundException
  2114. * @throws \think\db\exception\ModelNotFoundException
  2115. * @throws \think\exception\DbException
  2116. * @throws \think\exception\PDOException
  2117. */
  2118. public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
  2119. {
  2120. if ($gxh === 0){
  2121. $where = [
  2122. 'Gy0_gdbh'=>$workOrder,
  2123. 'Gy0_yjno'=>$yjno,
  2124. ];
  2125. }else{
  2126. $where = [
  2127. 'Gy0_gdbh'=>$workOrder,
  2128. 'Gy0_yjno'=>$yjno,
  2129. 'Gy0_gxh'=>['>=',$gxh]
  2130. ];
  2131. }
  2132. //获取工艺资料
  2133. $processList = \db('工单_工艺资料')
  2134. ->where($where)
  2135. ->field('Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
  2136. ->select();
  2137. if (empty($processList)){
  2138. $this->success('未找到该工单工序资料');
  2139. }
  2140. //计算损耗定额和计划产量
  2141. $production = [];
  2142. $i = 0;
  2143. foreach ($processList as $key=>$value){
  2144. if ($key === 0){
  2145. array_push($production,$feed);
  2146. }
  2147. $wastage = 0;
  2148. if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
  2149. $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
  2150. }
  2151. if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
  2152. $wastage = round($wastage * $value['Gy0_ms']);
  2153. }
  2154. if ((int)$value['Gy0_ls'] === 1 && $key>=1){
  2155. $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
  2156. }else{
  2157. $number = $production[$key];
  2158. }
  2159. array_push($production,ceil($number-$wastage));
  2160. $processSql = \db('工单_工艺资料')
  2161. ->where('UniqId',$value['UniqId'])
  2162. ->fetchSql(true)
  2163. ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
  2164. $res = \db()->query($processSql);
  2165. if ($res === false){
  2166. $i++;
  2167. }
  2168. }
  2169. if ($i===0){
  2170. return true;
  2171. }else{
  2172. return false;
  2173. }
  2174. }
  2175. /**
  2176. * 工单资料删除
  2177. * @return void
  2178. * @throws \think\exception\PDOException
  2179. */
  2180. public function WorkOrderDel()
  2181. {
  2182. if ($this->request->isGet() === false){
  2183. $this->error('请求错误');
  2184. }
  2185. $param = $this->request->param();
  2186. if (isset($param['UniqId']) === false){
  2187. $this->error('参数错误');
  2188. }
  2189. $WorkOrderId = explode(',',$param['UniqId']);
  2190. $i = 0;
  2191. foreach ($WorkOrderId as $key=>$value){
  2192. //获取工单编号
  2193. $workorder = \db('工单_基本资料')
  2194. ->where('Uniqid',$value)
  2195. ->value('rtrim(Gd_gdbh)');
  2196. //删除工单资料、工艺资料、印件资料
  2197. \db()->startTrans();
  2198. try {
  2199. \db('工单_基本资料')->where('Uniqid',$value)->delete();
  2200. if (!empty(\db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->find())){
  2201. \db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->delete();
  2202. }
  2203. if (!empty(\db('工单_印件资料')->where('Yj_Gdbh',$workorder)->find())){
  2204. \db('工单_印件资料')->where('Yj_Gdbh',$workorder)->delete();
  2205. }
  2206. \db()->commit();
  2207. }catch (\Exception $e){
  2208. \db()->rollback();
  2209. $i++;
  2210. }
  2211. }
  2212. if ($i === 0){
  2213. $this->success('删除成功');
  2214. }else{
  2215. $this->error('删除失败');
  2216. }
  2217. }
  2218. /**
  2219. * 修正核算参数-》工单产品信息获取
  2220. * @return void
  2221. * @throws \think\db\exception\DataNotFoundException
  2222. * @throws \think\db\exception\ModelNotFoundException
  2223. * @throws \think\exception\DbException
  2224. */
  2225. public function ProductNameData()
  2226. {
  2227. if ($this->request->isGet() === false){
  2228. $this->error('请求错误');
  2229. }
  2230. $workOrder = input('workOrder');
  2231. if (empty($workOrder)){
  2232. $this->error('参数错误');
  2233. }
  2234. $orderList = \db('工单_基本资料')
  2235. ->field('rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称')
  2236. ->where('Gd_gdbh',$workOrder)
  2237. ->find();
  2238. $this->success('成功',$orderList);
  2239. }
  2240. }