WorkOrder.php 67 KB

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