WorkOrder.php 69 KB

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