WorkOrder.php 72 KB

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