WorkOrder.php 73 KB

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