WorkOrder.php 73 KB

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