WorkOrder.php 80 KB

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