WorkOrder.php 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913
  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. $param = $this->request->param();
  29. // if (isset($param['sort'])){
  30. // $where['工单分类'] = 2;
  31. // }else{
  32. // $where['工单分类'] = ['in',[1,3]];
  33. // }
  34. $where['行号'] = ['in',['1','10']];
  35. //获取总计划中数量和总生产中数量
  36. $productingAll = \db('工单_基本资料')->where($where)->where('成品代号','<>','')->where('行号','1')->where('gd_statu','2-生产中')->cache(true)->count();
  37. $progressAll = \db('工单_基本资料')->where($where)->where('成品代号','<>','')->where('行号','1')->where('gd_statu','3-计划中')->cache(true)->count();
  38. $data = [
  39. 'productingAll' => $productingAll,
  40. 'progressAll' => $progressAll,
  41. // '客户编号' => []
  42. ];
  43. $list = \db('产品_基本资料')
  44. ->where('客户编号','<>','')
  45. ->field('客户编号,客户名称')
  46. ->group('客户编号,客户名称')
  47. ->order('客户编号')
  48. ->select();
  49. if (empty($list)){
  50. $this->success('',[]);
  51. }
  52. $data['翌星工单']=$data['MN工单']=[];
  53. foreach ($list as $key=>$value){
  54. $value['客户编号'] = rtrim($value['客户编号']);
  55. //这条sql查出来的数据可能不对,试一下以下sql
  56. $productIng = \db('工单_基本资料')->where($where)->where('Gd_cpdh|成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','2-生产中')->count();
  57. $proGress = \db('工单_基本资料')->where($where)->where('Gd_cpdh|成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','3-计划中')->count();
  58. $string = '';
  59. if ($productIng != 0){
  60. $string = $string."生产中:".$productIng;
  61. }
  62. if ($proGress != 0){
  63. $string = $string."计划中:".$proGress;
  64. }
  65. if ($string !== ''){
  66. $name = $value['客户编号'].'【'.$string.'】'.rtrim($value['客户名称']);
  67. if (strpos($value['客户编号'],'J') !== false || strpos($value['客户编号'],'Y') !== false){
  68. array_push($data['翌星工单'],$name);
  69. }else{
  70. array_push($data['MN工单'],$name);
  71. }
  72. // array_push($data['客户编号'],$name);
  73. }
  74. // else{
  75. // $name = $value['客户编号'].$value['客户名称'];
  76. // if (strpos($value['客户编号'],'J') !== false){
  77. // array_push($data['糊盒工单'],$name);
  78. // }else{
  79. // array_push($data['印刷工单'],$name);
  80. // }
  81. // }
  82. }
  83. $this->success('成功',$data);
  84. }
  85. /**
  86. * 工单基本资料列表
  87. * @ApiMethod (GET)
  88. * @param string $limit 查询长度
  89. * @param string $Gd_khdh 客户代号
  90. * @param string $startTime 接单日期开始时间
  91. * @param string $endTime 接单日期结束时间
  92. * @return \think\response\Json
  93. * @throws \think\exception\DbException
  94. */
  95. public function WorkList()
  96. {
  97. if ($this->request->isGet() === false){
  98. $this->error('请求错误');
  99. }
  100. $search = input('search');
  101. $clientNumber = input('Gd_khdh');
  102. $startTime = input('start');
  103. $endTime = input('end');
  104. $page = input('page');
  105. $limit = input('limit');
  106. $param = $this->request->param();
  107. if (isset($param['sort'])){
  108. $sort = 2;
  109. }else{
  110. $sort = 1;
  111. }
  112. $where = [];
  113. if (!empty($clientNumber)){
  114. if (substr($clientNumber,0,1) !== 'Y' && substr($clientNumber,0,1) !== 'J')
  115. {
  116. $clientNumber = substr($clientNumber,0,4);
  117. }
  118. if ($clientNumber === 'Y1401'){
  119. $where['Gd_cpdh'] = ['like',$clientNumber.'%'];
  120. }else{
  121. $where['成品代号'] = ['like',$clientNumber.'%'];
  122. }
  123. }
  124. // if (substr($clientNumber,0,1) === 'Y'){
  125. // $where['工单分类'] = 1;
  126. // }elseif (substr($clientNumber,0,1) === 'J'){
  127. // $where['工单分类'] = 2;
  128. // }
  129. if (!empty($workOrder)){
  130. $where['Gd_gdbh'] = $workOrder;
  131. }
  132. if (!empty($productCode)){
  133. $where['Gd_cpdh'] = $productCode;
  134. }
  135. if (!empty($search)){
  136. $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$search.'%'];
  137. }
  138. if (!empty($startTime) && !empty($endTime)){
  139. $where['接单日期'] = ['between',[$startTime,$endTime]];
  140. }
  141. // $where['工单分类'] = $sort;
  142. // $where['行号'] = ['in',['1','10']];
  143. $total = \db('工单_基本资料')->where($where)->distinct(true)->field('Gd_gdbh')->count();
  144. $list = \db('工单_基本资料')
  145. ->where($where)
  146. ->order('Gd_statu desc')
  147. ->limit(($page-1)*$limit,$limit)
  148. ->group('Gd_gdbh')
  149. ->select();
  150. //工单基本资料数据整理
  151. $data = [];
  152. foreach ($list as $key=>$value){
  153. $data[$key] = [
  154. '工单编号' => rtrim($value['Gd_gdbh']),
  155. '生产分类' => rtrim($value['Gd_生产分类']),
  156. '销售订单号' => rtrim($value['销售订单号']),
  157. '产品代号' => rtrim($value['成品代号']),
  158. '产品名称' => rtrim($value['成品名称']),
  159. '订单数量' => floatval($value['订单数量']),
  160. '单位' => rtrim($value['计量单位']),
  161. '折合大箱' => rtrim((int)$value['投料大箱']),
  162. '投料率' => rtrim($value['投料率']),
  163. '平均合格率' => '',
  164. '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
  165. '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
  166. '工单类型' => rtrim($value['Gd_lx']),
  167. '工单状态' => rtrim($value['gd_statu']),
  168. '当前生产工序' => '',
  169. '产量提交时间' => '',
  170. '建档用户' => rtrim($value['Sys_id']),
  171. '建档时间' => rtrim($value['Sys_rq']),
  172. '更新时间' => rtrim($value['Mod_rq']),
  173. 'Uniqid' => rtrim($value['Uniqid'])
  174. ];
  175. $number = \db('工单_工艺资料')->where('Gy0_gdbh',$data[$key]['工单编号'])->count();
  176. if ($number === 0){
  177. $data[$key]['status'] = '*';
  178. }else{
  179. $data[$key]['status'] = '';
  180. }
  181. }
  182. $this->success('成功',['data'=>$data,'total'=>$total]);
  183. }
  184. /**
  185. * 工单详情
  186. * @ApiMethod (GET)
  187. * @param void
  188. * @return void
  189. * @throws \think\db\exception\DataNotFoundException
  190. * @throws \think\db\exception\ModelNotFoundException
  191. * @throws \think\exception\DbException
  192. */
  193. public function workOrderListDetail()
  194. {
  195. if ($this->request->isGet() === false){
  196. $this->error('请求错误');
  197. }
  198. $Gd_gdbh = input('Gd_gdbh');
  199. $param = $this->request->param();
  200. if (empty($Gd_gdbh)){
  201. $this->error('参数错误');
  202. }
  203. if (isset($param['sort'])){
  204. $where['yj_Yjno'] = ['>=','10'];
  205. }else{
  206. $where['yj_Yjno'] = ['<','10'];
  207. }
  208. $data = [];
  209. //印件资料
  210. $printList = \db('工单_印件资料')
  211. ->where('Yj_Gdbh',$Gd_gdbh)
  212. ->where($where)
  213. ->select();
  214. if (!empty($printList)){
  215. foreach ($printList as $key=>$value){
  216. $data['printList'][$key] = [
  217. '印件号' => rtrim($value['yj_Yjno']),
  218. '印件代号' => rtrim($value['yj_Yjdh']),
  219. '印件名称' => rtrim($value['yj_yjmc']),
  220. '纸张代号' => rtrim($value['yj_zzdh']),
  221. '纸张名称' => rtrim($value['yj_zzmc']),
  222. '投料规格' => rtrim($value['yj_tlgg']),
  223. '平张投料' => rtrim($value['yj_平张投料']),
  224. '开料规格' => rtrim($value['yj_klgg']),
  225. '开数*联数' => rtrim($value['yj_ks']).'*'.rtrim($value['yj_ls']),
  226. '建档用户' => rtrim($value['Sys_id']),
  227. '建档时间' => rtrim($value['Sys_rq']),
  228. '更新时间' => rtrim($value['Mod_rq']),
  229. 'zzdh1' => rtrim($value['yj_zzdh1']),
  230. 'zzdh2' => rtrim($value['yj_zzdh2']),
  231. 'zzdh3' => rtrim($value['yj_zzdh3']),
  232. 'zzdh4' => rtrim($value['yj_zzdh4']),
  233. 'zzmc1' => rtrim($value['yj_zzmc1']),
  234. 'zzmc2' => rtrim($value['yj_zzmc2']),
  235. 'zzmc3' => rtrim($value['yj_zzmc3']),
  236. 'zzmc4' => rtrim($value['yj_zzmc4']),
  237. '订单数量' => rtrim($value['yj_成品数量']),
  238. '万小张' => rtrim($value['yj_实际投料']),
  239. '开数' => rtrim($value['yj_ks']),
  240. '联数' => rtrim($value['yj_ls']),
  241. '核算规格' => rtrim($value['Yj_核算规格']),
  242. '备注' => rtrim($value['yj_desc']),
  243. 'Uniqid' => rtrim($value['Uniqid'])
  244. ];
  245. }
  246. }else{
  247. $data['printList'] = [];
  248. }
  249. //工艺资料
  250. if (isset($param['sort'])){
  251. $Prowhere['Gy0_yjno'] = ['>=','10'];
  252. }else{
  253. $Prowhere['Gy0_yjno'] = ['<','10'];
  254. }
  255. $processList = \db('工单_工艺资料')
  256. ->where('Gy0_gdbh',$Gd_gdbh)
  257. ->where($Prowhere)
  258. ->order('Gy0_yjno,Gy0_gxh')
  259. ->select();
  260. if (!empty($processList)){
  261. foreach ($processList as $key=>$value){
  262. if ($value['Gy0_yjno']<10){
  263. $value['Gy0_yjno'] = '0'.$value['Gy0_yjno'];
  264. }
  265. if ($value['Gy0_gxh']<10){
  266. $value['Gy0_gxh'] = '0'.$value['Gy0_gxh'];
  267. }
  268. if (rtrim($value['Gy0_shdh']) == '' || $value['Gy0_计划接货数'] == 0){
  269. $number = 0;
  270. }else{
  271. $number = round(((int)$value['Gy0_计划损耗']/(int)($value['Gy0_计划接货数']))*100,2).'%';
  272. }
  273. if ($value['PD_WG'] !== '1900-01-01 00:00:00'){
  274. $status = '已完工';
  275. }else{
  276. $status = '未完工';
  277. }
  278. $data['processList'][$key] = [
  279. '重点工序' => rtrim($value['重点工序']),
  280. '印件-工序' => rtrim($value['Gy0_yjno']).'-'.rtrim($value['Gy0_gxh']),
  281. '备选工序' => rtrim($value['备选工序']),
  282. '工序名称' => rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】',
  283. '印件号' => rtrim($value['Gy0_yjno']),
  284. '工序号' => rtrim($value['Gy0_gxh']),
  285. '工艺名称' => rtrim($value['Gy0_gxmc']),
  286. 'gxmc' => rtrim($value['Add_gxmc']),
  287. '计划产量' => $value['Gy0_计划接货数'],
  288. '基础损耗' => rtrim($value['Gy0_Rate0']),
  289. '损耗率' => rtrim($value['Gy0_Rate1']),
  290. '机台编号' => rtrim($value['Gy0_sbbh']),
  291. '报废定额' => rtrim($value['Gy0_计划损耗']),
  292. '计损色数' => rtrim($value['Gy0_ms']),
  293. '允损比例' => $number,
  294. '难度系数' => isset($value['工价系数'])?rtrim($value['工价系数']):'',
  295. '损耗系数' => isset($value['损耗系数'])?rtrim($value['损耗系数']):'',
  296. '人工检_次品板' => (int)$value['人工检_次品板']=0?'':$value['人工检_次品板'],
  297. '人工检_废检' => (int)$value['人工检_废检']=0?'':$value['人工检_废检'],
  298. '机检_正品板' => (int)$value['机检_正品板']=0?'':$value['机检_正品板'],
  299. '机检_次品板' => (int)$value['机检_次品板']=0?'':$value['机检_次品板'],
  300. '机检_废检' => (int)$value['机检_废检']=0?'':$value['机检_废检'],
  301. '开数*联数' => rtrim($value['Gy0_ks']).'*'.rtrim($value['Gy0_ls']),
  302. '备注' => isset($value['工序备注'])?rtrim($value['工序备注']):'',
  303. '印刷方式' => isset($value['印刷方式'])?rtrim($value['印刷方式']):'',
  304. '版距' => isset($value['版距'])?rtrim($value['版距']):'',
  305. '建档用户' => rtrim($value['Sys_id']),
  306. '建档日期' => isset($value['Sys_rq'])?rtrim($value['Sys_rq']):'',
  307. '更新时间' => isset($value['Mod_rq'])?rtrim($value['Mod_rq']):'',
  308. '车间名称' => rtrim($value['Gy0_SITE']),
  309. '质量要求' => rtrim($value['质量要求']),
  310. '质量隐患' => rtrim($value['质量隐患']),
  311. '开数' => rtrim($value['Gy0_ks']),
  312. '联数' => rtrim($value['Gy0_ls']),
  313. 'UniqId' => rtrim($value['UniqId']),
  314. 'shdh' => rtrim($value['Gy0_shdh']),
  315. '辅助工时' => rtrim($value['Gy0_辅助工时']),
  316. '小时产能' => rtrim($value['Gy0_小时产能']),
  317. 'status' => $status
  318. ];
  319. }
  320. }else{
  321. $data['processList'] = [];
  322. }
  323. //BOM资料
  324. $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
  325. BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
  326. $bomList = \db('工单_bom资料')
  327. ->where('BOM_工单编号',$Gd_gdbh)
  328. ->field($field)
  329. ->select();
  330. if (!empty($bomList)){
  331. foreach ($bomList as $key=>$value){
  332. $bomList[$key]['消耗定量'] = rtrim($value['BOM_投入数']).rtrim($value['BOM_投料单位']).'/'.rtrim($value['BOM_产出数']).rtrim($value['BOM_产出单位']);
  333. unset($bomList[$key]['BOM_投料单位'],$bomList[$key]['BOM_投入数'],$bomList[$key]['BOM_产出数'],$bomList[$key]['BOM_产出单位']);
  334. $bomList[$key]['计划用量'] = rtrim((float)$value['计划用量']);
  335. }
  336. $data['BOM'] = $bomList;
  337. }else{
  338. $data['BOM'] = [];
  339. }
  340. //工单附件资料
  341. $jsRes = db('工单_相关附件')
  342. ->where('关联编号','like','%'.$Gd_gdbh.'%')
  343. ->select();
  344. if (!empty($jsRes)){
  345. foreach ($jsRes as $key=>&$value){
  346. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  347. $value['附件内容'] = '';
  348. }
  349. }
  350. $data['jsData'] = $jsRes;
  351. }else{
  352. $data['jsData'] = [];
  353. }
  354. $this->success('成功',$data);
  355. }
  356. /**
  357. * 编辑页面展示
  358. * @ApiMethod (GET)
  359. * @param string $workOrder 工单编号
  360. * @return void
  361. * @throws \think\db\exception\DataNotFoundException
  362. * @throws \think\db\exception\ModelNotFoundException
  363. * @throws \think\exception\DbException
  364. */
  365. public function DataCorrection()
  366. {
  367. if ($this->request->isGet() === false){
  368. $this->error('请求错误');
  369. }
  370. $workOrder = input('Gd_gdbh');
  371. if (empty($workOrder)){
  372. $this->error('参数错误');
  373. }
  374. $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  375. rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称,rtrim(接单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
  376. rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
  377. rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid,rtrim(计划投料) as 平张投料';
  378. $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  379. if (empty($list)){
  380. $this->error('未找到该工单信息');
  381. }
  382. $printData = \db('工单_印件资料')
  383. ->where('Yj_Gdbh',$workOrder)
  384. ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(Uniqid) as id')
  385. ->cache(true,84600)
  386. ->find();
  387. if (empty($printData)){
  388. $list['印件名称'] = '';
  389. $list['印件代号'] = '';
  390. $list['印件ID'] = '';
  391. }else{
  392. $list['印件名称'] = $printData['印件名称'];
  393. $list['印件代号'] = $printData['印件代号'];
  394. $list['印件ID'] = $printData['id'];
  395. }
  396. $this->success('成功',$list);
  397. }
  398. /**
  399. * 工单资料修改
  400. * @ApiMethod (POST)
  401. * @param void
  402. * @return void
  403. * @throws \think\Exception
  404. * @throws \think\exception\PDOException
  405. */
  406. public function WorkOrderEdit()
  407. {
  408. if (Request::instance()->isPost() === false){
  409. $this->error('请求错误');
  410. }
  411. $param = Request::instance()->post();
  412. if (empty($param) || isset($param['Uniqid']) === false){
  413. $this->error('参数错误');
  414. }
  415. // 先查询原始数据用于日志对比
  416. $oldData = \db('工单_基本资料')
  417. ->where('Uniqid', $param['Uniqid'])
  418. ->find();
  419. //配置修改数据
  420. $row = [
  421. 'Gd_lx' => isset($param['lx'])?$param['lx']:'',
  422. '开单日期' => isset($param['kdrq'])?$param['kdrq']:'',
  423. 'Gd_gdbh' => isset($param['gdbh'])?$param['gdbh']:'',
  424. 'Gd_生产分类' => isset($param['scfl'])?$param['scfl']:'',
  425. 'Gd_客户代号' => isset($param['khdh'])?$param['khdh']:'',
  426. 'Gd_客户名称' => isset($param['khmc'])?$param['khmc']:'',
  427. '成品代号' => isset($param['cpdh'])?$param['cpdh']:'',
  428. '成品名称' => isset($param['cpmc'])?$param['cpmc']:'',
  429. '订单数量' => isset($param['ddsl'])?$param['ddsl']:'',
  430. '交货日期' => isset($param['jhrq'])?$param['jhrq']:'',
  431. '投料率' => isset($param['tll'])?$param['tll']:'',
  432. '计划投料' => isset($param['jhtl'])?$param['jhtl']:'',
  433. '实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  434. '计量单位' => isset($param['jldw'])?$param['jldw']:'',
  435. '投料大箱' => isset($param['tldx'])?$param['tldx']:'',
  436. '销售订单号' => isset($param['xsddh'])?$param['xsddh']:'',
  437. '警语版面' => isset($param['jymb'])?$param['jymb']:'',
  438. '产品版本号' => isset($param['bbh'])?$param['bbh']:'',
  439. '客户ERP编码' => isset($param['erp'])?$param['erp']:'',
  440. '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
  441. '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
  442. 'Gd_desc' => isset($param['desc'])?$param['desc']:'',
  443. '排产时库存' => isset($param['kc'])?$param['kc']:'',
  444. '平均合格率' => isset($param['avg'])?$param['avg']:'',
  445. ];
  446. // 修改工单主信息时记录变更
  447. $changes = [];
  448. foreach ($row as $field => $newValue) {
  449. $oldValue = $oldData[$field] ?? null;
  450. if ($oldValue != $newValue) {
  451. $changes[] = [
  452. 'field' => $field,
  453. 'old' => $oldValue,
  454. 'new' => $newValue
  455. ];
  456. }
  457. }
  458. //获取印件资料
  459. $printCode = \db('工单_印件资料')
  460. ->where('Uniqid',$param['printID'])
  461. ->value('yj_Yjno');
  462. if (!empty($printCode)){
  463. if ((int)$param['jhtl'] >0){
  464. //修改工单工艺计划产量
  465. $result = $this->PlannedProcessYield($param['gdbh'],$printCode,0,$param['jhtl']);
  466. if ($result === false){
  467. $this->success('分配工序计划产量失败');
  468. }
  469. }
  470. //修改印件信息
  471. $printSql = \db('工单_印件资料')
  472. ->where('Uniqid',$param['printID'])
  473. ->fetchSql(true)
  474. ->update(['Yj_Gdbh'=>$param['gdbh'],'yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
  475. $printRes = Db::query($printSql);
  476. }
  477. //修改工单信息
  478. $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
  479. $res = Db::query($sql);
  480. // 记录修改日志(仅当有字段变更时)
  481. if (!empty($changes)) {
  482. $logData = [];
  483. foreach ($changes as $change) {
  484. $logData[] = [
  485. 'Gd_gdbh' => $oldData['Gd_gdbh'], // 使用原始工单编号
  486. 'ModifyUser' => $param['sys_id'],
  487. 'ModifyTime' => date('Y-m-d H:i:s'),
  488. 'FieldName' => $change['field'],
  489. 'OldValue' => $change['old'],
  490. 'NewValue' => $change['new'],
  491. 'ModifySource' => '工单编辑'
  492. ];
  493. }
  494. $logSql = \db('系统操作日志表')->fetchSql(true)->insertAll($logData);
  495. $result = \db()->query($logSql);
  496. }
  497. //修改订单数量该工单下的订单数量
  498. //1. 查询该id下的工单编号, 防止其手动修改工单编号导致条件错误
  499. $gdbh = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->value('Gd_gdbh');
  500. // 获取修改前的订单数量
  501. $oldQuantity = \db('工单_基本资料')
  502. ->where('Gd_gdbh', $gdbh)
  503. ->value('订单数量');
  504. //2. 根据查出的工单编号修改订单数量
  505. $sql = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->fetchSql(true)->update(['订单数量'=>$row['订单数量']]);
  506. $res1 = Db::query($sql);
  507. // 记录订单数量单独变更
  508. if ($res1 && $oldQuantity != $row['订单数量']) {
  509. $logSql = \db('系统操作日志表')->fetchSql(true)->insert([
  510. 'Gd_gdbh' => $gdbh,
  511. 'ModifyUser' => $param['sys_id'],
  512. 'ModifyTime' => date('Y-m-d H:i:s'),
  513. 'FieldName' => '订单数量',
  514. 'OldValue' => $oldQuantity,
  515. 'NewValue' => $row['订单数量'],
  516. 'ModifySource' => '数量修正'
  517. ]);
  518. $result = \db()->query($logSql);
  519. }
  520. if ($res !== false && $res1 !== false){
  521. $this->success('成功');
  522. }else{
  523. $this->error('失败');
  524. }
  525. }
  526. /**
  527. * U8投料试算
  528. * @ApiMethod (GET)
  529. * @param string $processCode 产品编号
  530. * @return void
  531. * @throws \think\db\exception\DataNotFoundException
  532. * @throws \think\db\exception\ModelNotFoundException
  533. * @throws \think\exception\DbException
  534. */
  535. public function U8Trial()
  536. {
  537. if ($this->request->isGet() === false)
  538. {
  539. $this->error('请求错误');
  540. }
  541. $productCode = input('productCode');
  542. if (empty($productCode)){
  543. $this->error('参数错误');
  544. }
  545. $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  546. rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
  547. $list = \db('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
  548. if (empty($list)){
  549. $this->success('未找到该产品工序');
  550. }
  551. foreach ($list as $key=>$value){
  552. $data = \db('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
  553. $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
  554. $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
  555. if ($value['add_gxmc'] !== ''){
  556. $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
  557. }else{
  558. $list[$key]['工序名称'] = $value['gxmc'];
  559. }
  560. unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
  561. }
  562. $this->success('成功',$list);
  563. }
  564. /**
  565. * 引用产品资料->获取产品资料
  566. * @ApiMethod (GET)
  567. * @param string $workOrder 工单编号
  568. * @return void
  569. * @throws \think\db\exception\DataNotFoundException
  570. * @throws \think\db\exception\ModelNotFoundException
  571. * @throws \think\exception\DbException
  572. */
  573. public function ProductInformation()
  574. {
  575. if ($this->request->isGet() === false)
  576. {
  577. $this->error('请求错误');
  578. }
  579. $workOrder = input('workOrder');
  580. if (empty($workOrder)){
  581. $this->error('参数错误');
  582. }
  583. $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_客户名称) as 客户名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称';
  584. $Detail = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  585. if (empty($Detail)){
  586. $this->success('未找到工单信息');
  587. }
  588. $Detail['客户代号'] = substr($Detail['产品代号'],0,4);
  589. $this->success('成功',$Detail);
  590. }
  591. /**
  592. * 引用产品资料->复制产品工艺资料
  593. * @ApiMethod (POST)
  594. * @param string $oldWorkOrder 被复制工单编号
  595. * @param string $newWorkOrder 复制工单编号
  596. * @return void
  597. * @throws \think\Exception
  598. * @throws \think\db\exception\DataNotFoundException
  599. * @throws \think\db\exception\ModelNotFoundException
  600. * @throws \think\exception\DbException
  601. * @throws \think\exception\PDOException
  602. */
  603. public function ProductInformationEdit()
  604. {
  605. if (Request::instance()->isPost() === false)
  606. {
  607. $this->error('请求错误');
  608. }
  609. $oldWorkOrder = input('oldWorkOrder');
  610. $newWorkOrder = input('newWorkOrder');
  611. if (empty($oldWorkOrder) || empty($newWorkOrder))
  612. {
  613. $this->error('参数错误');
  614. }
  615. $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  616. if ($lastId<10000000){
  617. $lastId = 10000000;
  618. }else{
  619. $lastId = $lastId + 1;
  620. }
  621. //获取原工单工艺资料
  622. $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->select();
  623. $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  624. foreach ($oldProcessData as $k=>$v){
  625. $oldProcessData[$k]['Gy0_gdbh'] = $oldWorkOrder;
  626. $oldProcessData[$k]['Sys_id'] = '';
  627. $oldProcessData[$k]['Gy0_sj1'] = '1900-01-01 00:00:00';
  628. $oldProcessData[$k]['Gy0_sj2'] = '1900-01-01 00:00:00';
  629. $oldProcessData[$k]['UniqId'] = $lastId + $k;
  630. $oldProcessData[$k]['PD_WG'] = '1900-01-01 00:00:00';
  631. }
  632. if (\db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->find()){
  633. \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->delete();
  634. }
  635. //获取原工单印件资料
  636. $lastUniqId = \db('工单_印件资料')->order('UniqId desc')->value('UniqId');
  637. if ($lastUniqId<1000000){
  638. $lastUniqId = 1000000;
  639. }else{
  640. $lastUniqId = $lastUniqId + 1;
  641. }
  642. $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->select();
  643. $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
  644. foreach ($oldPrintData as $k=>$v){
  645. $oldPrintData[$k]['Yj_Gdbh'] = $oldWorkOrder;
  646. $oldPrintData[$k]['Sys_id'] = '';
  647. $oldPrintData[$k]['Uniqid'] = $lastUniqId +$k +1;
  648. $oldPrintData[$k]['质量考核'] = 1;
  649. }
  650. if (\db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->find()){
  651. \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->delete();
  652. }
  653. //复制印件、工艺资料
  654. $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  655. $ProcessRes = Db::query($ProcessSQL);
  656. $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
  657. $PrintRes = Db::query($PrintSQL);
  658. if ($ProcessRes !== false && $PrintRes !== false){
  659. $this->success('成功');
  660. }else{
  661. $this->error('失败');
  662. }
  663. }
  664. /**
  665. * 工艺流程调成->获取当前工单工艺资料
  666. * @ApiMethod (GET)
  667. * @param string $workorder 当前工单编号
  668. * @return void
  669. * @throws \think\db\exception\DataNotFoundException
  670. * @throws \think\db\exception\ModelNotFoundException
  671. * @throws \think\exception\DbException
  672. */
  673. public function ProcessFlow()
  674. {
  675. if ($this->request->isGet() === false){
  676. $this->error('请求错误');
  677. }
  678. $workOrder = input('workOrder');
  679. if (empty($workOrder)){
  680. $this->error('参数错误');
  681. }
  682. $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
  683. if (empty($list)){
  684. $this->success('未找到工单信息');
  685. }
  686. $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  687. rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
  688. rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间,rtrim(UniqId) as UniqId';
  689. $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->cache(true,84600)->field($filed)->select();
  690. if (empty($process)){
  691. $this->error('未找到该工单工艺资料');
  692. }
  693. foreach ($process as $key=>$value){
  694. if (isset($value['add_gxmc'])){
  695. $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
  696. }else{
  697. $process[$key]['工序名称'] = $value['gxmc'];
  698. }
  699. $process[$key]['工价系数'] = (float)$value['工价系数'];
  700. $process[$key]['损耗系数'] = (float)$value['损耗系数'];
  701. $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
  702. }
  703. $list['process'] = $process;
  704. $this->success('成功',$list);
  705. }
  706. /**
  707. * 参照工单列表获取
  708. * @ApiMethod (GET)
  709. * @param string $workOrder 工单编号
  710. * @param string $productCode 产品代号
  711. * @return void
  712. */
  713. public function ReferenceWorkOrder()
  714. {
  715. if ($this->request->isGet() === false){
  716. $this->error('请求错误');
  717. }
  718. $productCode = input('productCode');
  719. $workOrder = input('workOrder');
  720. if (empty($productCode) || empty($workOrder)){
  721. $this->error('参数错误');
  722. }
  723. $list = \db('工单_基本资料')->where('成品代号',$productCode)->distinct(true)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
  724. if (empty($list)){
  725. $this->success('未获取该产品其他工单信息');
  726. }
  727. $this->success('成功',$list);
  728. }
  729. /**
  730. * 工艺资料复制
  731. * @ApiMethod (POST)
  732. * @param string $oldWorkOrder 被复制工单编号
  733. * @param string $newWorkOrder 复制工单编号
  734. * @return void
  735. * @throws \think\Exception
  736. * @throws \think\db\exception\DataNotFoundException
  737. * @throws \think\db\exception\ModelNotFoundException
  738. * @throws \think\exception\DbException
  739. * @throws \think\exception\PDOException
  740. *
  741. */
  742. public function ProcessCopy()
  743. {
  744. if (Request::instance()->isPost() === false){
  745. $this->error('请求错误');
  746. }
  747. $param = Request::instance()->post();
  748. if (empty($param)){
  749. $this->error('参数错误');
  750. }
  751. $i = 0;
  752. foreach ($param as $key => $value){
  753. $sql = \db('工单_工艺资料')
  754. ->where('UniqId',$value['UniqId'])
  755. ->fetchSql(true)
  756. ->update(['Gy0_gxh'=>$value['gxh']]);
  757. $res = \db()->query($sql);
  758. if ($res === false){
  759. $i++;
  760. }
  761. }
  762. if ($i === 0){
  763. $this->success('成功');
  764. }else{
  765. $this->error('失败');
  766. }
  767. // $UniqId = [];
  768. // $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
  769. // if ($lastId['id']>10000000){
  770. // $lastUniqId = $lastId['id'];
  771. // }else{
  772. // $lastUniqId = 10000000;
  773. // }
  774. // foreach ($param as $key=>$value){
  775. // $UniqId[$key] = $value['UniqId'];
  776. // }
  777. // $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
  778. // if (empty($processList)){
  779. // $this->success('未找到工艺资料');
  780. // }
  781. // halt($processList);
  782. // $data = [];
  783. // foreach ($param as $key=>$value){
  784. // foreach ($processList as $k=>$v){
  785. // if ($value['UniqId'] = $v['UniqId']){
  786. // $data[$key] = $v;
  787. // $data[$key]['Gy0_gxh'] = $value['gxh'];
  788. // $data[$key]['Gy0_gdbh'] = $value['workOrder'];
  789. // $data[$key]['UniqId'] = $lastUniqId + $key + 1;
  790. // }
  791. // }
  792. // }
  793. // $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
  794. // if ($res !== false){
  795. // $result = \db('工单_工艺资料')->insertAll($data);
  796. // if ($result !== false){
  797. // $this->success('成功');
  798. // }else{
  799. // $this->error('失败');
  800. // }
  801. // }else{
  802. // $this->error('失败');
  803. // }
  804. }
  805. /**
  806. * U8工单列表
  807. * @ApiMethod (GET)
  808. * @param void
  809. * @return void
  810. * @throws \think\db\exception\DataNotFoundException
  811. * @throws \think\db\exception\ModelNotFoundException
  812. * @throws \think\exception\DbException
  813. */
  814. public function U8workOrder()
  815. {
  816. if ($this->request->isGet() === false){
  817. $this->error('请求错误');
  818. }
  819. $param = $this->request->param();
  820. if (empty($param)){
  821. $this->error('参数错误');
  822. }
  823. $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  824. rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
  825. $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
  826. if (empty($list)){
  827. $this->success('未找到工单');
  828. }
  829. $this->success('成功',$list);
  830. }
  831. /**
  832. * U8工单资料删除
  833. * @param string $workOrder 工单编号
  834. * @return void
  835. * @throws \think\Exception
  836. * @throws \think\exception\PDOException
  837. */
  838. public function U8DataCorrection()
  839. {
  840. if($this->request->isGet() === false){
  841. $this->error('请求错误');
  842. }
  843. $workOrder = input('Uniqid');
  844. if (empty($workOrder)){
  845. $this->error('参数错误');
  846. }
  847. $data = [];
  848. if (strpos($workOrder,',')){
  849. $data = explode(',',$workOrder);
  850. }else{
  851. $data[0] = $workOrder;
  852. }
  853. $res = \db('工单_基本资料')->where('Uniqid','in',$data)->delete();
  854. if ($res !== false){
  855. $this->success('成功');
  856. }else{
  857. $this->error('失败');
  858. }
  859. }
  860. /**
  861. * 产品废检系数调整->质检工艺数据获取
  862. * @ApiMethod (GET)
  863. * @param string $workOrder 工单编号
  864. * @return void
  865. * @throws \think\db\exception\DataNotFoundException
  866. * @throws \think\db\exception\ModelNotFoundException
  867. * @throws \think\exception\DbException
  868. */
  869. public function TestCoefficient()
  870. {
  871. if ($this->request->isGet() === false){
  872. $this->error('请求错误');
  873. }
  874. $workOrder = input('workOrder');
  875. if (empty($workOrder)){
  876. $this->error('参数错误');
  877. }
  878. $where = [
  879. 'Gy0_gdbh' => $workOrder,
  880. 'Gy0_gxmc' => ['like','%检%']
  881. ];
  882. $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
  883. rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
  884. rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
  885. $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
  886. if (empty($list)){
  887. $this->success('未找到该工单工艺');
  888. }
  889. $name = \db('工单_基本资料')
  890. ->where('Gd_gdbh',$workOrder)
  891. ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
  892. ->find();
  893. if (empty($name)){
  894. $this->success('未找到该工单');
  895. }
  896. foreach ($list as $key=>$value){
  897. if ($value['yjno']<10){
  898. $value['yjno'] = '0'.$value['yjno'];
  899. }
  900. if ($value['gxh']<10){
  901. $value['gxh'] = '0'.$value['gxh'];
  902. }
  903. $list[$key]['印件工序及工艺'] = $value['gdbh'].'-'.$value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  904. unset($list[$key]['gdbh'],$list[$key]['yjno'],$list[$key]['gxmc']);
  905. $list[$key]['产品编号'] = $name['产品代号'];
  906. $list[$key]['产品名称'] = $name['产品名称'];
  907. $list[$key]['客户名称'] = $name['客户名称'];
  908. }
  909. $this->success('成功',$list);
  910. }
  911. /**
  912. * 产品质检系数调整->系数修改
  913. * @ApiMethod (GET)
  914. * @param string $workorder 工单编号
  915. * @param string $processCode 工序号
  916. * @param float $code1 人工正品板
  917. * @param float $code2 人工次品板
  918. * @param float $code3 人工废检
  919. * @param float $code4 机检正品板
  920. * @param float $code5 机检次品板
  921. * @param float $code6 机检废检
  922. * @return void
  923. * @throws \think\Exception
  924. * @throws \think\exception\PDOException
  925. */
  926. public function TestCoefficientEdit()
  927. {
  928. if (Request::instance()->isPost() === false){
  929. $this->error('请求错误');
  930. }
  931. $workOrder = input('workOrder');
  932. $processCode = input('processCode');
  933. $row = [
  934. '人工检_正品板' => input('code1'),
  935. '人工检_次品板' => input('code2'),
  936. '人工检_废检' => input('code3'),
  937. '机检_正品板' => input('code4'),
  938. '机检_次品板' => input('code5'),
  939. '机检_废检' => input('code6'),
  940. ];
  941. if (empty($workOrder) || empty($processCode)){
  942. $this->error('参数错误');
  943. }
  944. $where = [
  945. 'Gy0_gdbh' => $workOrder,
  946. 'Gy0_gxh' => $processCode
  947. ];
  948. $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
  949. $res = Db::query($sql);
  950. if ($res !== false){
  951. $this->success('成功');
  952. }else{
  953. $this->error('失败');
  954. }
  955. }
  956. /**
  957. * 修正工单核算参数->数据获取
  958. * @ApiMethod (GET)
  959. * @param string $workOrder 工单编号
  960. * @return void
  961. * @throws \think\db\exception\DataNotFoundException
  962. * @throws \think\db\exception\ModelNotFoundException
  963. * @throws \think\exception\DbException
  964. */
  965. public function AccountingParameter()
  966. {
  967. if ($this->request->isGet() === false){
  968. $this->error('请求错误');
  969. }
  970. $workOrder = input('workOrder');
  971. if (empty($workOrder)){
  972. $this->error('参数错误');
  973. }
  974. $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,
  975. rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
  976. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
  977. $list = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
  978. if (empty($list)){
  979. $this->success('未找到该工单工艺资料');
  980. }
  981. foreach ($list as $key=>$value){
  982. if ($value['yjno']<10){
  983. $value['yjno'] = '0'.$value['yjno'];
  984. }
  985. if ($value['gxh']<10){
  986. $value['gxh'] = '0'.$value['gxh'];
  987. }
  988. $list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
  989. }
  990. $this->success('成功',$list);
  991. }
  992. /**
  993. * 修正工单核算参数->参数修改
  994. * @ApiMethod (POST)
  995. * @param void
  996. * @return void
  997. * @throws \think\Exception
  998. * @throws \think\db\exception\DataNotFoundException
  999. * @throws \think\db\exception\ModelNotFoundException
  1000. * @throws \think\exception\DbException
  1001. * @throws \think\exception\PDOException
  1002. */
  1003. public function AccountingParameterEdit()
  1004. {
  1005. if (Request::instance()->isPost() === false){
  1006. $this->error('请求错误');
  1007. }
  1008. $param = Request::instance()->post();
  1009. if (empty($param) || isset($param[0]['Uniqid']) === false){
  1010. $this->error('参数错误');
  1011. }
  1012. $i = 0;
  1013. foreach ($param as $key=>$value){
  1014. $data['rate0'] = 0;
  1015. $data['rate1'] = 0;
  1016. $rate = \db('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  1017. if (!empty($rate)){
  1018. $data['rate0'] = $rate['rate0'];
  1019. $data['rate1'] = $rate['rate1'];
  1020. }
  1021. $row = [
  1022. '工价系数' => $value['difficulty']?:'',
  1023. 'Gy0_shdh' => $value['loss']?:'',
  1024. '印刷方式' => $value['printMode']?:'',
  1025. '版距' => $value['plate']?:'',
  1026. 'Gy0_ms' => $value['chromatic']?:'',
  1027. '损耗系数' => $value['wastage']?:'',
  1028. 'Gy0_Rate0' => $data['rate0'],
  1029. 'Gy0_Rate1' => $data['rate1']
  1030. ];
  1031. $sql = \db('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
  1032. $res = Db::query($sql);
  1033. if ($res !== false){
  1034. $i++;
  1035. }
  1036. }
  1037. if ($i !== 0){
  1038. $this->success('成功');
  1039. }else{
  1040. $this->error('失败');
  1041. }
  1042. }
  1043. /**
  1044. * 印件资料修改
  1045. * @ApiMethod (POST)
  1046. * @param void
  1047. * @return void
  1048. * @throws \think\Exception
  1049. * @throws \think\exception\PDOException
  1050. */
  1051. public function PrintedEdit()
  1052. {
  1053. if (Request::instance()->isPost() === false){
  1054. $this->error('请求错误');
  1055. }
  1056. $param = Request::instance()->post();
  1057. if (empty($param) || isset($param['Uniqid']) === false){
  1058. $this->error('参数错误');
  1059. }
  1060. $param['Yj_Gdbh'] = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->value('Yj_Gdbh');
  1061. $data = [
  1062. 'Yj_Gdbh' =>$param['Yj_Gdbh'],
  1063. 'yj_Yjno' =>$param['yjno'],
  1064. 'yj_Yjdh' =>$param['yjdh'],
  1065. 'yj_yjmc' =>$param['yjmc'],
  1066. 'yj_zzdh' =>$param['zzdh'],
  1067. 'yj_zzdh1' =>$param['zzdh1'],
  1068. 'yj_zzdh2' =>$param['zzdh2'],
  1069. 'yj_zzdh3' =>$param['zzdh3'],
  1070. 'yj_zzdh4' =>$param['zzdh4'],
  1071. 'yj_zzmc' =>$param['zzmc'],
  1072. 'yj_zzmc1' =>$param['zzmc1'],
  1073. 'yj_zzmc2' =>$param['zzmc2'],
  1074. 'yj_zzmc3' =>$param['zzmc3'],
  1075. 'yj_zzmc4' =>$param['zzmc4'],
  1076. 'yj_tlgg' =>$param['tlgg'],
  1077. 'yj_klgg' =>$param['klgg'],
  1078. 'Yj_核算规格' =>$param['hsgg'],
  1079. 'yj_成品数量' =>$param['cpsl'],
  1080. 'yj_平张投料' =>$param['pztl'],
  1081. 'yj_ks' =>$param['ks'],
  1082. 'yj_ls' =>$param['ls'],
  1083. 'yj_desc' =>$param['desc'],
  1084. ];
  1085. $UniqId = $param['Uniqid'];
  1086. $sql = \db('工单_印件资料')->where('Uniqid',$UniqId)->fetchSql(true)->update($data);
  1087. $res = Db::query($sql);
  1088. $process = \db('工单_工艺资料')
  1089. ->where('Gy0_gdbh',$data['Yj_Gdbh'])
  1090. ->where('Gy0_yjno',$data['yj_Yjno'])
  1091. ->select();
  1092. if ((int)$data['yj_平张投料'] > 0 && !empty($process)){
  1093. //重新分配工序计划产量
  1094. $result = $this->PlannedProcessYield($data['Yj_Gdbh'],$data['yj_Yjno'],0,$data['yj_平张投料']);
  1095. if ($result === false){
  1096. $this->success('修改工序产量失败');
  1097. }
  1098. }
  1099. if ($res !== false){
  1100. $this->success('成功');
  1101. }else{
  1102. $this->error('失败');
  1103. }
  1104. }
  1105. /**
  1106. * 工艺资料修改
  1107. * @ApiMethod (POST)
  1108. * @param void
  1109. * @return void
  1110. * @throws \think\Exception
  1111. * @throws \think\db\exception\DataNotFoundException
  1112. * @throws \think\db\exception\ModelNotFoundException
  1113. * @throws \think\exception\DbException
  1114. * @throws \think\exception\PDOException
  1115. */
  1116. // public function ProcessDetailEdit()
  1117. // {
  1118. // if (Request::instance()->isPost() === false){
  1119. // $this->error('请求错误');
  1120. // }
  1121. // $param = Request::instance()->post();
  1122. // if (empty($param) || isset($param['UniqId']) === false){
  1123. // $this->error('参数错误');
  1124. // }
  1125. // // 获取修改前原始数据
  1126. // $oldData = \db('工单_工艺资料')
  1127. // ->where('UniqId', $param['UniqId'])
  1128. // ->find();
  1129. // //获取工单损耗代号数据
  1130. // if (empty($param['Gy0_shdh'])){
  1131. // $rate['rate0'] = 0;
  1132. // $rate['rate1'] = 0;
  1133. // }else{
  1134. // $rate = \db('dic_lzsh')->where('sys_bh',$param['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  1135. // }
  1136. // if ($param['备选工序'] == ''){
  1137. // $param['备选工序'] = null;
  1138. // }
  1139. // $param['Gy0_Rate0']= isset($rate['rate0'])?$rate['rate0']:0;
  1140. // $param['Gy0_Rate1'] = isset($rate['rate1'])?$rate['rate1']:0;
  1141. // $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  1142. // $UniqId = $param['UniqId'];
  1143. // unset($param['UniqId']);
  1144. // //获取工单第一道工艺编号
  1145. // $minGxh = \db('工单_工艺资料')->where('Gy0_gdbh',$param['Gy0_gdbh'])->column('min(Gy0_gxh) as gxh');
  1146. // //修改工艺资料
  1147. // $sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
  1148. // $res = \db()->query($sql);
  1149. // //获取工艺资料数据
  1150. // $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
  1151. // //如果是第一道工序需从印件资料中获取计划产量
  1152. // $list['计划接货数'] = \db('工单_印件资料')->where('Yj_Gdbh',$param['Gy0_gdbh'])->where('yj_Yjno',$param['Gy0_yjno'])->column('yj_平张投料')[0];
  1153. // //修改工单状态
  1154. // $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
  1155. // if ($status['status'] !== '2-生产中'){
  1156. // $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  1157. // Db::query($statusSql);
  1158. // }
  1159. // //重新分配工序计划产量
  1160. // if ((int)$list['计划接货数'] > 0){
  1161. // $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],0,$list['计划接货数']);
  1162. // }
  1163. // // 记录变更日志
  1164. // if ($res) {
  1165. // $newData = array_merge($oldData, $param); // 合并新旧数据
  1166. // $changes = [];
  1167. //
  1168. // // 动态对比所有参数字段(排除系统字段)
  1169. // $excludeFields = ['UniqId', 'Mod_rq'];
  1170. // foreach ($param as $field => $newValue) {
  1171. // if (in_array($field, $excludeFields)) continue;
  1172. //
  1173. // $oldValue = $oldData[$field] ?? 'NULL';
  1174. // if ($oldValue != $newValue) {
  1175. // $changes[] = [
  1176. // 'field' => $field,
  1177. // 'old' => $oldValue,
  1178. // 'new' => $newValue
  1179. // ];
  1180. // }
  1181. // }
  1182. //
  1183. // // 批量插入日志
  1184. // if (!empty($changes)) {
  1185. // $logData = [];
  1186. // foreach ($changes as $change) {
  1187. // $logData[] = [
  1188. // 'Gd_gdbh' => $oldData['Gy0_gdbh'],
  1189. // 'yjno' => $oldData['Gy0_yjno'],
  1190. // 'gxh' => $oldData['Gy0_gxh'],
  1191. // 'ModifyUser' => $param['Sys_id'],
  1192. // 'ModifyTime' => date('Y-m-d H:i:s'),
  1193. // 'FieldName' => $change['field'],
  1194. // 'OldValue' => $change['old'],
  1195. // 'NewValue' => $change['new'],
  1196. // 'ModifySource' => '工艺调整'
  1197. // ];
  1198. // }
  1199. // $logSql = \db('系统操作日志表')->fetchSql(true)->insertAll($logData);
  1200. // \db()->query($logSql);
  1201. // }
  1202. // }
  1203. // if ($res !== false){
  1204. // $this->success('成功');
  1205. // }else{
  1206. // $this->error('失败');
  1207. // }
  1208. // }
  1209. public function ProcessDetailEdit()
  1210. {
  1211. Db::startTrans();
  1212. try {
  1213. // 请求验证
  1214. if (!Request::instance()->isPost()) {
  1215. throw new Exception('非法请求方法');
  1216. }
  1217. $param = Request::instance()->post();
  1218. if (empty($param) || !isset($param['UniqId'])) {
  1219. throw new Exception('缺少必要参数');
  1220. }
  1221. $UniqId = $param['UniqId'];
  1222. // 获取原始数据(全字段)
  1223. $oldData = Db::name('工单_工艺资料')
  1224. ->where('UniqId', $UniqId)
  1225. ->find();
  1226. if (!$oldData) {
  1227. throw new Exception('目标数据不存在');
  1228. }
  1229. // 动态构建更新数据 --------------------------------------------------------
  1230. $updateData = [];
  1231. $logsData = [];
  1232. $systemFields = array('UniqId', 'Mod_rq'); // 显式声明数组
  1233. // 合并所有有效字段(PHP7.2兼容写法)
  1234. foreach ($param as $key => $value) {
  1235. if (!in_array($key, $systemFields)) {
  1236. $updateData[$key] = $value;
  1237. $logsData[$key] = $value;
  1238. }
  1239. }
  1240. // 处理业务逻辑字段
  1241. if (empty($param['Gy0_shdh'])) {
  1242. $updateData['Gy0_Rate0'] = 0;
  1243. $updateData['Gy0_Rate1'] = 0;
  1244. } else {
  1245. $rate = Db::name('dic_lzsh')
  1246. ->where('sys_bh', $param['Gy0_shdh'])
  1247. ->field('rtrim(sys_rate0) as rate0, rtrim(sys_rate1) as rate1')
  1248. ->find();
  1249. $rate = $rate ? $rate : array('rate0' => 0, 'rate1' => 0);
  1250. $updateData['Gy0_Rate0'] = $rate['rate0'];
  1251. $updateData['Gy0_Rate1'] = $rate['rate1'];
  1252. }
  1253. // 添加系统字段
  1254. $updateData['Mod_rq'] = date('Y-m-d H:i:s');
  1255. // 执行全字段更新(PHP7.2兼容的回调函数)-----------------------------------
  1256. $rawSql = Db::name('工单_工艺资料')
  1257. ->where('UniqId', $UniqId)
  1258. ->fetchSql(true)
  1259. ->update($updateData);
  1260. // 中文字段安全处理(传统匿名函数写法)
  1261. $safeSql = preg_replace_callback(
  1262. '/`([\x{4e00}-\x{9fa5}]+)`/u',
  1263. function($matches) {
  1264. return '`' . addslashes($matches[1]) . '`';
  1265. },
  1266. $rawSql
  1267. );
  1268. // 执行并验证
  1269. $affected = Db::execute($safeSql);
  1270. if ($affected < 0) {
  1271. throw new Exception('数据库执行失败');
  1272. }
  1273. // 记录全字段变更日志 -----------------------------------------------------
  1274. $changes = array();
  1275. foreach ($logsData as $field => $newValue) {
  1276. $oldValue = isset($oldData[$field]) ? $oldData[$field] : 'NULL';
  1277. // 严格值比较(PHP7.2兼容的类型转换)
  1278. if ((string)$oldValue !== (string)$newValue) {
  1279. $changes[] = array(
  1280. 'field' => $field,
  1281. 'old' => $oldValue,
  1282. 'new' => $newValue
  1283. );
  1284. }
  1285. }
  1286. if (!empty($changes)) {
  1287. $logs = array();
  1288. foreach ($changes as $change) {
  1289. $logs[] = array(
  1290. 'Gd_gdbh' => $oldData['Gy0_gdbh'],
  1291. 'yjno' => $oldData['Gy0_yjno'],
  1292. 'gxh' => $oldData['Gy0_gxh'],
  1293. 'ModifyUser' => $param['Sys_id'],
  1294. 'ModifyTime' => date('Y-m-d H:i:s'),
  1295. 'FieldName' => $change['field'],
  1296. 'OldValue' => $change['old'],
  1297. 'NewValue' => $change['new'],
  1298. 'ModifySource' => '工艺调整'
  1299. );
  1300. }
  1301. Db::name('系统操作日志表')->insertAll($logs);
  1302. }
  1303. //获取工单第一道工艺编号
  1304. $minGxh = \db('工单_工艺资料')->where('Gy0_gdbh',$param['Gy0_gdbh'])->column('min(Gy0_gxh) as gxh');
  1305. //获取工艺资料数据
  1306. $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
  1307. //如果是第一道工序需从印件资料中获取计划产量
  1308. $list['计划接货数'] = \db('工单_印件资料')->where('Yj_Gdbh',$param['Gy0_gdbh'])->where('yj_Yjno',$param['Gy0_yjno'])->column('yj_平张投料')[0];
  1309. //修改工单状态
  1310. $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
  1311. if ($status['status'] !== '2-生产中'){
  1312. $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  1313. Db::query($statusSql);
  1314. }
  1315. //重新分配工序计划产量
  1316. if ((int)$list['计划接货数'] > 0){
  1317. $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],0,$list['计划接货数']);
  1318. }
  1319. Db::commit();
  1320. $this->success('操作成功');
  1321. } catch (Exception $e) {
  1322. Db::rollback();
  1323. $this->error($e->getMessage());
  1324. }
  1325. }
  1326. /**
  1327. * 工艺资料编辑->机台列表获取
  1328. * @return void
  1329. * @throws \think\db\exception\DataNotFoundException
  1330. * @throws \think\db\exception\ModelNotFoundException
  1331. * @throws \think\exception\DbException
  1332. */
  1333. public function MachineList()
  1334. {
  1335. if ($this->request->isGet() === false){
  1336. $this->error('请求错误');
  1337. }
  1338. $param = $this->request->param();
  1339. if (empty($param)){
  1340. $this->error('参数错误');
  1341. }
  1342. $list = \db('设备_基本资料')
  1343. ->where('使用部门',$param['address'])
  1344. ->where('sys_sbID','<>','')
  1345. ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
  1346. ->order('设备编组,设备编号')
  1347. ->select();
  1348. if (empty($list)){
  1349. $this->success('未找到该车间机台');
  1350. }
  1351. $data = [];
  1352. foreach ($list as $key=>$value){
  1353. $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
  1354. }
  1355. $this->success('成功',$data);
  1356. }
  1357. /**
  1358. * 打印作业通知单->工单印件和工序获取
  1359. * @ApiMethod (GET)
  1360. * @return void
  1361. * @throws \think\db\exception\DataNotFoundException
  1362. * @throws \think\db\exception\ModelNotFoundException
  1363. * @throws \think\exception\DbException
  1364. */
  1365. public function PrintCodeList()
  1366. {
  1367. if ($this->request->isGet() === false){
  1368. $this->error('请求错误');
  1369. }
  1370. $param = $this->request->param();
  1371. if (empty($param)){
  1372. $this->error('参数错误');
  1373. }
  1374. $list = \db('工单_印件资料')
  1375. ->field([
  1376. 'rtrim(yj_Yjno)' => '印件号',
  1377. 'rtrim(yj_yjmc)' => '印件名称'
  1378. ])
  1379. ->where('Yj_Gdbh',$param['workOrder'])
  1380. ->select();
  1381. $this->success('成功',$list);
  1382. }
  1383. /**
  1384. * 打印作业通知单->工艺编号获取
  1385. * @ApiMethod (GET)
  1386. * @return void
  1387. * @throws \think\db\exception\DataNotFoundException
  1388. * @throws \think\db\exception\ModelNotFoundException
  1389. * @throws \think\exception\DbException
  1390. */
  1391. public function ProcessCodeList()
  1392. {
  1393. if ($this->request->isGet() === false){
  1394. $this->error('请求错误');
  1395. }
  1396. $param = $this->request->param();
  1397. if (empty($param)){
  1398. $this->error('参数错误');
  1399. }
  1400. $list = \db('工单_工艺资料')
  1401. ->field('rtrim(Gy0_gxh) as 工序号')
  1402. ->where([
  1403. 'Gy0_gdbh' => $param['workOrder'],
  1404. 'Gy0_yjno' => $param['yjno']
  1405. ])
  1406. ->select();
  1407. $this->success('成功',$list);
  1408. }
  1409. /**
  1410. * 打印作业通知单
  1411. * @ApiMethod (POST)
  1412. * @param void
  1413. * @return void
  1414. * @throws \think\db\exception\DataNotFoundException
  1415. * @throws \think\db\exception\ModelNotFoundException
  1416. * @throws \think\exception\DbException
  1417. */
  1418. public function PrintJobOrder()
  1419. {
  1420. if ($this->request->isGet() === false) {
  1421. $this->error('请求错误');
  1422. }
  1423. $param = $this->request->param();
  1424. if (empty($param)){
  1425. $this->error('参数错误');
  1426. }
  1427. $data = $this->workOrderDetailGet($param['workOrder'],$param['yjno']);
  1428. if (empty($data)){
  1429. $this->success('未找到工单信息');
  1430. }
  1431. $materiel = $this->MaterielDetailGet($param['workOrder']);
  1432. $printDetail = $this->PrintDetailGet($param['workOrder'],$param['yjno'],$param['gxh']);
  1433. if (empty($printDetail)){
  1434. $this->success('未找到工艺信息');
  1435. }
  1436. $number = 0;
  1437. foreach ($printDetail as $key=>$value){
  1438. $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
  1439. $number = $number+$value['允损比例'];
  1440. }
  1441. $data['制单'] = $param['PrepareDocument'];
  1442. $data['审核'] = $param['examine'];
  1443. $data['目标合格率'] = 100-$number.'%';
  1444. $data['materiel'] = $materiel;
  1445. $data['printDetail'] = $printDetail;
  1446. $this->success('成功',$data);
  1447. }
  1448. /**
  1449. * 打印作业通知单->工单及印件资料获取
  1450. * @param $workOrder
  1451. * @return mixed
  1452. */
  1453. public function workOrderDetailGet($workOrder,$yjno)
  1454. {
  1455. $sql = "SELECT
  1456. RTRIM( a.Gd_lx) AS 工单类型,
  1457. RTRIM( a.Gd_gdbh ) AS 生产批次号,
  1458. RTRIM( a.销售订单号 ) AS 销售订单号,
  1459. RTRIM( a.Gd_客户代号 ) AS 客户代号,
  1460. RTRIM( a.Gd_客户名称 ) AS 客户名称,
  1461. RTRIM( a.成品代号 ) AS 产品代码,
  1462. RTRIM( a.成品名称 ) AS 产品名称,
  1463. RTRIM( a.产品版本号 ) AS 版本号,
  1464. RTRIM( a.警语版面 ) AS 警语版面,
  1465. RTRIM( a.码源数量 ) AS 码源数量,
  1466. RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
  1467. RTRIM( a.接单日期 ) AS 开单日期,
  1468. RTRIM( a.交货日期 ) AS 交货日期,
  1469. RTRIM( a.Gd_desc ) AS 工单说明,
  1470. RTRIM( a.投料率 ) AS 投料率,
  1471. RTRIM( a.订单数量 ) AS 订单数量,
  1472. RTRIM( a.平均合格率 ) AS 平均合格率,
  1473. RTRIM( a.投料大箱 ) AS 订货数量,
  1474. RTRIM( a.排产时库存 ) AS 排产时库存,
  1475. RTRIM( b.yj_Yjno ) AS 印件,
  1476. RTRIM( b.yj_Yjdh ) AS 印件代号,
  1477. RTRIM( b.yj_yjmc ) AS 印件名称,
  1478. RTRIM( b.yj_平张投料 ) AS 平张投料量,
  1479. RTRIM( b.yj_zzmc ) AS 纸张名称,
  1480. RTRIM( b.yj_tlgg ) AS 投料规格,
  1481. RTRIM( b.yj_ks ) AS 开数,
  1482. RTRIM( b.yj_ls ) AS 联数,
  1483. RTRIM( b.yj_desc ) AS 印件备注
  1484. FROM
  1485. `工单_基本资料` AS a
  1486. JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh
  1487. WHERE
  1488. a.Gd_gdbh = '{$workOrder}' AND b.yj_Yjno = '{$yjno}'";
  1489. $list = Db::query($sql);
  1490. if (empty($list)){
  1491. $this->success('未找到订单数据');
  1492. }
  1493. $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
  1494. $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
  1495. if (strpos($list[0]['产品名称'],'条') !== false){
  1496. $list[0]['订货数量'] = (int)$list[0]['订单数量']*40;
  1497. $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/250);
  1498. }else{
  1499. $list[0]['订货数量'] = (int)$list[0]['订单数量']*4;
  1500. $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/2500);
  1501. }
  1502. $list[0]['联数'] = (int)$list[0]['联数'];
  1503. $list[0]['印件代号及名称'] = $list[0]['印件代号'].' '.$list[0]['印件名称'];
  1504. // $list[0]['投料数量'] = $list[0]['订货数量'];
  1505. unset($list[0]['印件代号'],$list[0]['印件名称']);
  1506. return($list[0]);
  1507. }
  1508. /**打印作业流程单->物料资料获取
  1509. * @param $workOrder
  1510. * @return bool|\PDOStatement|string|\think\Collection
  1511. * @throws \think\db\exception\DataNotFoundException
  1512. * @throws \think\db\exception\ModelNotFoundException
  1513. * @throws \think\exception\DbException
  1514. */
  1515. public function MaterielDetailGet($workOrder)
  1516. {
  1517. $where = [
  1518. 'BOM_工单编号' => $workOrder,
  1519. ];
  1520. $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
  1521. $list = \db('工单_bom资料')->where($where)->field($filed)->select();
  1522. if (!empty($list)){
  1523. foreach ($list as $key=>$value){
  1524. $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
  1525. $list[$key]['计划用量'] = (float)$value['计划用量'];
  1526. unset($list[$key]['物料编码'],$list[$key]['物料名称']);
  1527. }
  1528. }
  1529. return $list;
  1530. }
  1531. /**
  1532. * 打印作业流程单->工艺资料获取
  1533. * @param $workOrder
  1534. * @return bool|\PDOStatement|string|\think\Collection
  1535. * @throws \think\db\exception\DataNotFoundException
  1536. * @throws \think\db\exception\ModelNotFoundException
  1537. * @throws \think\exception\DbException
  1538. */
  1539. public function PrintDetailGet($workOrder,$yjno,$gxh)
  1540. {
  1541. $where = [
  1542. 'Gy0_gdbh' => $workOrder,
  1543. 'Gy0_yjno' => $yjno,
  1544. 'Gy0_gxh' => ['<=',$gxh]
  1545. ];
  1546. $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  1547. rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
  1548. rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
  1549. $list = \db('工单_工艺资料')
  1550. ->where($where)
  1551. ->field($filed)
  1552. ->select();
  1553. if (empty($list)){
  1554. $this->success('工单工艺为空');
  1555. }
  1556. foreach ($list as $key=>$value){
  1557. if ($value['yjno']<10){
  1558. $value['yjno'] = '0'.$value['yjno'];
  1559. }
  1560. if ($value['gxh']<10){
  1561. $value['gxh'] = '0'.$value['gxh'];
  1562. }
  1563. if ($value['add_gxmc'] !== null){
  1564. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  1565. }else{
  1566. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  1567. }
  1568. $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
  1569. $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
  1570. if ((int)$value['计划接货数'] === 0){
  1571. $list[$key]['允损比例'] = 0;
  1572. }else{
  1573. $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
  1574. }
  1575. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
  1576. }
  1577. return $list;
  1578. }
  1579. /**
  1580. * 获取小时产能
  1581. * @ApiMethod (GET)
  1582. * @param void
  1583. * @return void
  1584. * @throws \think\db\exception\DataNotFoundException
  1585. * @throws \think\db\exception\ModelNotFoundException
  1586. * @throws \think\exception\DbException
  1587. */
  1588. public function capacityList()
  1589. {
  1590. if ($this->request->isGet() === false){
  1591. $this->error('请求错误');
  1592. }
  1593. $param = $this->request->param();
  1594. if (empty($param)){
  1595. $this->error('参数错误');
  1596. }
  1597. $machine = explode(' ',$param['machine'])[0];
  1598. $number = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(排单小时定额) as 小时产能')->find();
  1599. if (empty($number)){
  1600. $this->error('未找到小时产能');
  1601. }
  1602. $this->success('成功',$number['小时产能']);
  1603. }
  1604. /**
  1605. * 新增工单->添加工单
  1606. * @ApiMethod (POST)
  1607. * @param
  1608. * @return void
  1609. * @throws \think\Exception
  1610. * @throws \think\db\exception\BindParamException
  1611. * @throws \think\db\exception\DataNotFoundException
  1612. * @throws \think\db\exception\ModelNotFoundException
  1613. * @throws \think\exception\DbException
  1614. * @throws \think\exception\PDOException
  1615. */
  1616. public function WorkOrderAdd()
  1617. {
  1618. if (Request::instance()->isPost() === false){
  1619. $this->error('请求错误');
  1620. }
  1621. $param = Request::instance()->post();
  1622. if (empty($param)){
  1623. $this->error('参数错误');
  1624. }
  1625. if (isset($param['sort'])){
  1626. $sort = 2;
  1627. unset($param['sort']);
  1628. }else{
  1629. $sort = 1;
  1630. }
  1631. $num = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->count();
  1632. //插入产品资料
  1633. $productData = \db('产品_基本资料')
  1634. ->where('产品编号',$param['cpdh'])
  1635. ->count();
  1636. if ($productData === 0) {
  1637. $clientCode = substr($param['cpdh'], 0, 5);
  1638. $product = [
  1639. '客户编号' => $clientCode,
  1640. '客户名称' => $param['khmc'],
  1641. '产品编号' => $param['cpdh'],
  1642. '产品名称' => $param['cpmc'],
  1643. '计量单位' => '万张',
  1644. '状态' => '',
  1645. 'Mod_rq' => date('Y-m-d H:i:s', time()),
  1646. 'UniqID' => \db('产品_基本资料')->order('UniqID desc')->value('UniqID') + 1,
  1647. ];
  1648. if (strpos($product['产品名称'], '小盒') === false) {
  1649. $product['产品类别'] = '条盒';
  1650. } else {
  1651. $product['产品类别'] = '小盒';
  1652. }
  1653. $productSql = \db('产品_基本资料')->fetchSql(true)->insert($product);
  1654. \db()->query($productSql);
  1655. }
  1656. //添加工单
  1657. $productDetail = \db('产品_基本资料')->where('产品编号',$param['cpdh'])->find();
  1658. if (empty($productDetail)){
  1659. $productDetail['客户料号'] = '';
  1660. }
  1661. $lastId = \db('工单_基本资料')->order('Uniqid desc')->value('Uniqid');
  1662. $data = [
  1663. 'Gd_lx' =>$param['zdgd'],
  1664. 'Gd_生产分类' =>$param['sclx'],
  1665. '成本处理类别' =>'',
  1666. 'Gd_gdbh' =>$param['gdbh'],
  1667. '行号' =>$num+1 ,
  1668. 'Gd_客户代号' =>$param['khdh'],
  1669. 'Gd_客户名称' =>$param['khmc'],
  1670. 'Gd_khdh' =>$param['khdh'],
  1671. 'Gd_khmc' =>$param['khmc'],
  1672. '客户料号' =>rtrim($productDetail['客户料号']),
  1673. '客户ERP编码' =>$param['erp'],
  1674. 'Gd_cpdh' =>'',
  1675. 'Gd_cpmc' =>'',
  1676. '成品代号' =>$param['cpdh'],
  1677. '成品名称' =>$param['cpmc'],
  1678. '产品版本号' =>$param['bbh'],
  1679. '销售订单号' =>$param['xsddh'],
  1680. '警语版面' =>$param['jybm'],
  1681. '码源数量' =>$param['mysl'],
  1682. '排产时库存' =>$param['kcdx'],
  1683. '投料大箱' =>$param['tldx'],
  1684. '投料率' =>$param['tll'],
  1685. '平均合格率' =>$param['hgl'],
  1686. '进程备注' =>$param['jcbz'],
  1687. 'Gd_desc' =>$param['remark'],
  1688. '开单日期' =>date('Y-m-d H:i:s',time()),
  1689. '接单日期' =>$param['start'],
  1690. '交货日期' =>$param['end'],
  1691. '订单数量' =>$param['number'],
  1692. '计量单位' =>$param['tldw'],
  1693. '计划投料' =>$param['pztl'],
  1694. '实际投料' =>$param['wxz'],
  1695. '产品单价' =>0,
  1696. '入仓日期' =>'1900-01-01 00:00:00',
  1697. '工单入仓数量' =>0,
  1698. '工单制程废品' => 0,
  1699. '工单质检废品' => 0,
  1700. '工单无形损' => 0,
  1701. '工单计划损耗' => 0,
  1702. '工单完工日期' => $param['end'],
  1703. '投料确认' => '',
  1704. 'gd_statu' => '3-计划中',
  1705. '直接人工' => 0,
  1706. '分摊人工' => 0,
  1707. '直接材料' => 0,
  1708. '考核直接材料' => 0,
  1709. '分摊材料' => 0,
  1710. '考核分摊材料' => 0,
  1711. '直接折旧' => 0,
  1712. '水电气费' => 0,
  1713. '分摊空调' => 0,
  1714. '分摊锅炉' => 0,
  1715. '分摊废气处理' => 0,
  1716. '分摊空压机' => 0,
  1717. '分摊鼓风机' => 0,
  1718. '分摊其他' => 0,
  1719. '待摊人工' => 0,
  1720. '待摊折旧' => 0,
  1721. '待摊场地租金' => 0,
  1722. '待摊其他费用' => 0,
  1723. '加工费' => 0,
  1724. '加工费单价' => 0,
  1725. '成本考核_胶印' => 1,
  1726. '成本考核_凹印' => 1,
  1727. '成本考核_丝印' => 1,
  1728. '成本考核_模切' => 1,
  1729. '成本考核_检验' => 1,
  1730. '印版费' => 0,
  1731. 'V23制造成本' => 0,
  1732. 'Prt_rq' => date('Y-m-d H:i:s',time()),
  1733. 'Sys_id' => $param['Sys_id'],
  1734. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  1735. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  1736. 'U8UID' => '',
  1737. 'Uniqid' => $lastId+1,
  1738. '工序加工费' => 0,
  1739. '工单分类' => $sort,
  1740. ];
  1741. $sql= \db('工单_基本资料')->fetchSql(true)->insert($data);
  1742. $res = \db()->query($sql);
  1743. //创建日志数据
  1744. $logs = array(
  1745. 'Gd_gdbh' => $data['Gd_gdbh'],
  1746. 'ModifyUser' => $param['Sys_id'],
  1747. 'ModifyTime' => date('Y-m-d H:i:s'),
  1748. 'ModifySource' => '工单添加'
  1749. );
  1750. \db('系统操作日志表')->insert($logs);
  1751. if ($res !== false){
  1752. $this->success('成功');
  1753. }else{
  1754. $this->error('失败');
  1755. }
  1756. }
  1757. /**
  1758. * 新增工单->客户代号列表获取
  1759. * @return void
  1760. * @throws \think\db\exception\BindParamException
  1761. * @throws \think\exception\PDOException
  1762. */
  1763. public function ClientList()
  1764. {
  1765. if ($this->request->isGet() === false){
  1766. $this->error('请求错误');
  1767. }
  1768. $param = $this->request->param();
  1769. if (isset($param['search'])){
  1770. $where = $param['search'].'%';
  1771. $sql = "SELECT DISTINCT
  1772. (客户编号),rtrim(客户名称 ) as 客户名称
  1773. FROM
  1774. `产品_基本资料`
  1775. WHERE
  1776. 客户编号 LIKE "."'".$where."'"."
  1777. OR
  1778. 客户名称 LIKE "."'".$where."'"."
  1779. GROUP BY
  1780. 客户编号
  1781. order by
  1782. 客户编号";
  1783. }else{
  1784. $sql = "SELECT DISTINCT
  1785. (客户编号),rtrim(客户名称 ) as 客户名称
  1786. FROM
  1787. `产品_基本资料`
  1788. GROUP BY
  1789. 客户编号
  1790. order by
  1791. 客户编号";
  1792. }
  1793. $list = \db()->query($sql);
  1794. if (empty($list)){
  1795. $this->success('未找到客户列表');
  1796. }
  1797. foreach ($list as $key=>$value){
  1798. if (empty($value['客户编号'])){
  1799. unset($list[$key]);
  1800. }else{
  1801. $list[$key]['客户编号'] = rtrim($value['客户编号']);
  1802. $list[$key]['name'] = rtrim($value['客户编号']).'【'.$value['客户名称'].'】';
  1803. if ($value['客户编号'] == '1098'){
  1804. $list[$key]['客户名称'] = '打样专用';
  1805. }
  1806. }
  1807. }
  1808. $list = array_values($list);
  1809. $this->success('成功',$list);
  1810. }
  1811. /**
  1812. * 新增工单->产品代号获取
  1813. * @ApiMethod (GET)
  1814. * @param void
  1815. * @return void
  1816. * @throws \think\db\exception\DataNotFoundException
  1817. * @throws \think\db\exception\ModelNotFoundException
  1818. * @throws \think\exception\DbException
  1819. */
  1820. public function ProductCodeList()
  1821. {
  1822. if ($this->request->isGet() === false){
  1823. $this->error('请求错误');
  1824. }
  1825. $param = $this->request->param();
  1826. if (isset($param['cilent']) === false){
  1827. $this->error('参数错误');
  1828. }
  1829. $where = ['产品编号'=>['like',$param['cilent'].'%']];
  1830. $list = \db('产品_基本资料')
  1831. ->where($where)
  1832. ->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
  1833. ->limit(50)
  1834. ->select();
  1835. if (empty($list)){
  1836. $this->success('未获取到产品数据');
  1837. }
  1838. $res = db('产品_工艺资料')->where('Gy0_cpdh',$list[0]['产品编号'])->distinct(true)->column('rtrim(Gy0_方案) as gy_plan');
  1839. $list[0]['gy'] = $res;
  1840. foreach ($list as $key=>$value){
  1841. $list[$key]['name'] = $value['产品编号'].'【'.$value['产品名称'].'】';
  1842. $list[$key]['yj'] = db('产品_印件资料')->where('yj_cpdh',$value['产品编号'])->column('yj_yjno');
  1843. }
  1844. $this->success('成功',$list);
  1845. }
  1846. /**
  1847. * 新增印件资料->印件资料添加
  1848. * @return void
  1849. * @throws \think\db\exception\BindParamException
  1850. * @throws \think\exception\PDOException
  1851. */
  1852. public function PrintDetailAdd()
  1853. {
  1854. if (Request::instance()->isPost() === false){
  1855. $this->error('请求错误');
  1856. }
  1857. $param = Request::instance()->post();
  1858. if (empty($param)){
  1859. $this->error('参数错误');
  1860. }
  1861. $lastId = \db('工单_印件资料')->order('Uniqid desc')->value('Uniqid');
  1862. if (empty($lastId)){
  1863. $lastId = 0;
  1864. }else{
  1865. $lastId = $lastId + 1;
  1866. }
  1867. $param['Uniqid'] = $lastId;
  1868. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1869. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  1870. //判断印件号是否存在在工单基本资料表中,存在不增加行号,不存在增加行号
  1871. if (empty(\db('工单_基本资料')->where('Gd_gdbh',$param['Yj_Gdbh'])->where('行号',$param['yj_Yjno'])->find())){
  1872. $list = \db('工单_基本资料')->where('Gd_gdbh',$param['Yj_Gdbh'])->find();
  1873. $list['行号'] = $param['yj_Yjno'];
  1874. $list['Gd_cpdh'] = $param['yj_Yjdh'];
  1875. $list['Gd_cpmc'] = $param['yj_yjmc'];
  1876. $list['Sys_id'] = $param['Sys_id'];
  1877. $list['Sys_rq'] = $param['Sys_rq'];
  1878. $list['Mod_rq'] = $param['Mod_rq'];
  1879. unset($list['Uniqid']);
  1880. $workSql = \db('工单_基本资料')->fetchSql(true)->insert($list);
  1881. }else{
  1882. $data['Gd_cpdh'] = $param['yj_Yjdh'];
  1883. $data['Gd_cpmc'] = $param['yj_yjmc'];
  1884. $workSql = \db('工单_基本资料')
  1885. ->where('Gd_gdbh',$param['Yj_Gdbh'])
  1886. ->where('行号',$param['yj_Yjno'])
  1887. ->fetchSql(true)
  1888. ->update($data);
  1889. }
  1890. //开启事务
  1891. Db::startTrans();
  1892. try{
  1893. $sql = \db('工单_印件资料')->fetchSql(true)->insert($param);
  1894. $res = \db()->query($sql);
  1895. $workRes = \db()->query($workSql);
  1896. //提交事务
  1897. \db()->commit();
  1898. } catch (\Exception $e) {
  1899. // 回滚事务
  1900. \db()->rollback();
  1901. }
  1902. if ($res !== false && $workRes !== false){
  1903. $this->success('成功');
  1904. }else{
  1905. $this->error('失败');
  1906. }
  1907. }
  1908. /**
  1909. * 新增工艺资料->工艺资料添加
  1910. * @return void
  1911. * @throws \think\db\exception\BindParamException
  1912. * @throws \think\exception\PDOException
  1913. */
  1914. public function ProcessDetailAdd()
  1915. {
  1916. if (Request::instance()->isPost() === false){
  1917. $this->error('请求错误');
  1918. }
  1919. $param = Request::instance()->post();
  1920. if (empty($param)){
  1921. $this->error('参数错误');
  1922. }
  1923. $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  1924. if (empty($lastId)){
  1925. $lastId = 0;
  1926. }else{
  1927. $lastId = $lastId + 1;
  1928. }
  1929. if (empty($param['Gy0_shdh'])){
  1930. $param['Gy0_Rate0'] = 0;
  1931. $param['Gy0_Rate1'] = 0;
  1932. }else{
  1933. $detail = \db('dic_lzsh')->field('sys_rate0,sys_rate1')->where('sys_bh',$param['Gy0_shdh'])->find();
  1934. $param['Gy0_Rate0'] = $detail['sys_rate0'];
  1935. $param['Gy0_Rate1'] = $detail['sys_rate1'];
  1936. }
  1937. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1938. $param['Mod_rq'] = '1900-01-01 00:00:00';
  1939. $param['Gy0_sj1'] = '1900-01-01 00:00:00';
  1940. $param['Gy0_sj2'] = '1900-01-01 00:00:00';
  1941. $param['PD_WG'] = '1900-01-01 00:00:00';
  1942. $param['UniqId'] = $lastId;
  1943. //添加工序
  1944. $sql = \db('工单_工艺资料')
  1945. ->fetchSql(true)
  1946. ->insert($param);
  1947. $res = \db()->query($sql);
  1948. //获取平张投料
  1949. $number = \db('工单_印件资料')
  1950. ->where('Yj_Gdbh',$param['Gy0_gdbh'])
  1951. ->where('yj_Yjno',$param['Gy0_yjno'])
  1952. ->value('rtrim(yj_平张投料)');
  1953. //分配工艺计划产量
  1954. if ((int)$number >0){
  1955. $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],0,$number);
  1956. }
  1957. //操作日志数据
  1958. $logs = array(
  1959. 'Gd_gdbh' => $param['Gy0_gdbh'],
  1960. 'yjno' => $param['Gy0_yjno'],
  1961. 'gxh' => $param['Gy0_gxh'],
  1962. 'ModifyUser' => $param['Sys_id'],
  1963. 'ModifyTime' => date('Y-m-d H:i:s'),
  1964. 'ModifySource' => '工艺新增'
  1965. );
  1966. \db('系统操作日志表')->insert($logs);
  1967. if ($res !== false){
  1968. $this->success('成功');
  1969. }else{
  1970. $this->error('失败');
  1971. }
  1972. }
  1973. /**
  1974. * 新增工艺资料->印件编号获取
  1975. * @return void
  1976. * @throws \think\db\exception\DataNotFoundException
  1977. * @throws \think\db\exception\ModelNotFoundException
  1978. * @throws \think\exception\DbException
  1979. */
  1980. public function PrintDetailList()
  1981. {
  1982. if ($this->request->isGet() === false){
  1983. $this->error('请求错误');
  1984. }
  1985. $param = $this->request->param();
  1986. if (empty($param)){
  1987. $this->error('参数错误');
  1988. }
  1989. $printList = \db('工单_印件资料')
  1990. ->where('Yj_Gdbh',$param['workOrder'])
  1991. ->order('yj_Yjno')
  1992. ->select();
  1993. if (empty($printList)){
  1994. $this->success('未找到该工单印件资料');
  1995. }
  1996. $list = [];
  1997. foreach ($printList as $key=>$value){
  1998. $list[$key]['name'] = rtrim($value['yj_Yjno']).'-->'.rtrim($value['yj_yjmc']);
  1999. $list[$key]['no'] = rtrim($value['yj_Yjno']);
  2000. }
  2001. $this->success('成功',$list);
  2002. }
  2003. /**
  2004. * 工单资料管理->印件资料删除
  2005. * @return void
  2006. * @throws \think\Exception
  2007. * @throws \think\exception\PDOException
  2008. */
  2009. public function PrintDetailDel()
  2010. {
  2011. if ($this->request->isGet() === false){
  2012. $this->error('请求错误');
  2013. }
  2014. $param = $this->request->param();
  2015. if (isset($param['UniqId']) === false){
  2016. $this->error('参数错误');
  2017. }
  2018. $printId = explode(',',$param['UniqId']);
  2019. $i = 0;
  2020. foreach ($printId as $value){
  2021. $res = \db('工单_印件资料')
  2022. ->where('Uniqid',$value)
  2023. ->delete();
  2024. if ($res === false){
  2025. $i++;
  2026. }
  2027. }
  2028. if ($i === 0){
  2029. $this->success('删除成功');
  2030. }else{
  2031. $this->error('删除失败');
  2032. }
  2033. }
  2034. /**
  2035. * 工单资料管理->工艺资料删除
  2036. * @return void
  2037. * @throws \think\Exception
  2038. * @throws \think\exception\PDOException
  2039. */
  2040. public function ProcessDetailDel()
  2041. {
  2042. if ($this->request->isGet() === false){
  2043. $this->error('请求错误');
  2044. }
  2045. $param = $this->request->param();
  2046. if (isset($param['UniqId']) === false){
  2047. $this->error('参数错误');
  2048. }
  2049. $printId = explode(',',$param['UniqId']);
  2050. $i = 0;
  2051. //获取工单编号、印件号
  2052. $codeList = \db('工单_工艺资料')
  2053. ->where('UniqId',$printId[0])
  2054. ->field('rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_yjno) as 印件号')
  2055. ->find();
  2056. //获取平张投料数量
  2057. $number = \db('工单_印件资料')
  2058. ->where([
  2059. 'Yj_Gdbh' => $codeList['工单编号'],
  2060. 'yj_Yjno' => $codeList['印件号']
  2061. ])
  2062. ->value('rtrim(yj_平张投料)');
  2063. // 新增:批量获取要删除的工序号
  2064. $gxhList = \db('工单_工艺资料')
  2065. ->where('UniqId', 'in', $printId)
  2066. ->column('rtrim(Gy0_gxh) as gxh', 'UniqId');
  2067. //循环删除工艺资料
  2068. $deletedGxh = [];
  2069. foreach ($printId as $value){
  2070. $res = \db('工单_工艺资料')
  2071. ->where('UniqId',$value)
  2072. ->delete();
  2073. if ($res) {
  2074. // 记录成功删除的工序号
  2075. if (isset($gxhList[$value])) {
  2076. $deletedGxh[] = $gxhList[$value];
  2077. }
  2078. } else {
  2079. $i++;
  2080. }
  2081. }
  2082. //重新分配工艺计划产量
  2083. if ((int)$number>0){
  2084. $this->PlannedProcessYield($codeList['工单编号'],$codeList['印件号'],0,$number);
  2085. }
  2086. // 新增:写入操作日志
  2087. \db('系统操作日志表')->insert([
  2088. 'ModifyUser' => $param['sys_id'],
  2089. 'ModifyTime' => date('Y-m-d H:i:s',time()),
  2090. 'Gd_gdbh' => $codeList['工单编号'],
  2091. 'yjno' => $codeList['印件号'],
  2092. 'gxh' => implode(',', $deletedGxh),
  2093. 'ModifySource' => '工艺资料删除'
  2094. ]);
  2095. if ($i === 0){
  2096. $this->success('删除成功');
  2097. }else{
  2098. $this->error('删除失败');
  2099. }
  2100. }
  2101. /**
  2102. * 工艺资料添加->工序损耗代码
  2103. * @return void
  2104. * @throws \think\db\exception\DataNotFoundException
  2105. * @throws \think\db\exception\ModelNotFoundException
  2106. * @throws \think\exception\DbException
  2107. */
  2108. public function WastageList()
  2109. {
  2110. if ($this->request->isGet() === false){
  2111. $this->error('请求错误');
  2112. }
  2113. $param = $this->request->param();
  2114. if (empty($param['process'])){
  2115. $this->error('参数错误');
  2116. }
  2117. if (strlen($param['process'])>6){
  2118. $param['process'] = substr($param['process'],0,6);
  2119. }
  2120. $order = \db('dic_lzsh')
  2121. ->where('sys_mc','like',$param['process'].'%')
  2122. ->value('rtrim(sys_bh) as 编号');
  2123. $this->success('成功',$order);
  2124. }
  2125. /**
  2126. * 获取产品附件列表
  2127. */
  2128. public function getAnnexTable(){
  2129. if(!$this->request->isGet()){
  2130. $this->error('请求方式错误');
  2131. }
  2132. $req = $this->request->param();
  2133. if (isset($req['cpdh']) && !empty($req['cpdh'])){
  2134. $where['关联产品'] = ['LIKE','%'.$req['cpdh'].'%'];
  2135. }else{
  2136. $this->error('参数错误');
  2137. }
  2138. $rows = db('产品_技术附件')
  2139. ->where($where)
  2140. ->select();
  2141. foreach ($rows as $key=>&$value){
  2142. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  2143. $value['附件内容'] = '';
  2144. }
  2145. }
  2146. $this->success('成功',$rows);
  2147. }
  2148. /**
  2149. * 产品附件新增
  2150. */
  2151. public function annexAdd(){
  2152. if(!$this->request->isPost()){
  2153. $this->error('请求方式错误');
  2154. }
  2155. $req = $this->request->param();
  2156. $arr = [
  2157. 'sys_id',
  2158. '序号',
  2159. '附件备注',
  2160. '附件内容',
  2161. '附件类型',
  2162. '适用工序',
  2163. '关联产品'
  2164. ];
  2165. $data = [];
  2166. foreach ($arr as $key => $value){
  2167. if (!isset($req[$value])){
  2168. $this->error('参数错误',$value,$key+1);
  2169. }
  2170. $data[$value] = $req[$value];
  2171. }
  2172. $data['sys_rq'] = date('Y-m-d H:i:s');
  2173. //查询UniqId
  2174. $UniqId = db('产品_技术附件')->max('UniqId');
  2175. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  2176. //开启事务
  2177. db()->startTrans();
  2178. try{
  2179. $sql = db('产品_技术附件')->fetchSql(true)->insert($data);
  2180. $bool = db()->query($sql);
  2181. // 提交事务
  2182. db()->commit();
  2183. } catch (\Exception $e) {
  2184. // 回滚事务
  2185. db()->rollback();
  2186. $this->error($e->getMessage());
  2187. }
  2188. if($bool===false) $this->error('失败');
  2189. $this->success('成功');
  2190. }
  2191. /**
  2192. * 产品附件修改
  2193. * @ApiMethod (GET)
  2194. * @param string 'UniqId'
  2195. */
  2196. public function annexDel()
  2197. {
  2198. if(!$this->request->isGet()){
  2199. $this->error('请求方式错误');
  2200. }
  2201. $req = $this->request->param();
  2202. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  2203. $this->error('参数错误','UniqId',100);
  2204. }
  2205. //开启事务
  2206. db()->startTrans();
  2207. try{
  2208. $bool = db('产品_技术附件')->where('UniqId',$req['UniqId'])->delete();
  2209. // 提交事务
  2210. db()->commit();
  2211. } catch (\Exception $e) {
  2212. // 回滚事务
  2213. db()->rollback();
  2214. $this->error($e->getMessage());
  2215. }
  2216. if($bool===false) $this->error('失败');
  2217. $this->success('成功');
  2218. }
  2219. /**
  2220. * 获取产品附件列表
  2221. */
  2222. public function getGdAnnexTable(){
  2223. if(!$this->request->isGet()){
  2224. $this->error('请求方式错误');
  2225. }
  2226. $req = $this->request->param();
  2227. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  2228. $where['关联编号'] = ['LIKE','%'.$req['gdbh'].'%'];
  2229. }else{
  2230. $this->error('参数错误');
  2231. }
  2232. $rows = db('工单_相关附件')
  2233. ->where($where)
  2234. ->select();
  2235. foreach ($rows as $key=>&$value){
  2236. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  2237. $value['附件内容'] = '';
  2238. }
  2239. }
  2240. $this->success('成功',$rows);
  2241. }
  2242. /**
  2243. * 产品附件新增
  2244. */
  2245. public function gdAnnexAdd(){
  2246. if(!$this->request->isPost()){
  2247. $this->error('请求方式错误');
  2248. }
  2249. $req = $this->request->param();
  2250. $arr = [
  2251. 'sys_id',
  2252. '附件备注',
  2253. '附件内容',
  2254. '附件类型',
  2255. '关联编号'
  2256. ];
  2257. $data = [];
  2258. foreach ($arr as $key => $value){
  2259. if (!isset($req[$value])){
  2260. $this->error('参数错误',$value,$key+1);
  2261. }
  2262. $data[$value] = $req[$value];
  2263. }
  2264. $data['sys_rq'] = date('Y-m-d H:i:s');
  2265. //查询UniqId
  2266. $UniqId = db('工单_相关附件')->max('UniqId');
  2267. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  2268. //开启事务
  2269. db()->startTrans();
  2270. try{
  2271. $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  2272. $bool = db()->query($sql);
  2273. // 提交事务
  2274. db()->commit();
  2275. } catch (\Exception $e) {
  2276. // 回滚事务
  2277. db()->rollback();
  2278. $this->error($e->getMessage());
  2279. }
  2280. if($bool===false) $this->error('失败');
  2281. $this->success('成功');
  2282. }
  2283. /**
  2284. * 产品附件修改
  2285. * @ApiMethod (GET)
  2286. * @param string 'UniqId'
  2287. */
  2288. public function gdAnnexDel()
  2289. {
  2290. if(!$this->request->isGet()){
  2291. $this->error('请求方式错误');
  2292. }
  2293. $req = $this->request->param();
  2294. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  2295. $this->error('参数错误','UniqId',100);
  2296. }
  2297. //开启事务
  2298. db()->startTrans();
  2299. try{
  2300. $bool = db('工单_相关附件')->where('UniqId',$req['UniqId'])->delete();
  2301. // 提交事务
  2302. db()->commit();
  2303. } catch (\Exception $e) {
  2304. // 回滚事务
  2305. db()->rollback();
  2306. $this->error($e->getMessage());
  2307. }
  2308. if($bool===false) $this->error('失败');
  2309. $this->success('成功');
  2310. }
  2311. /**
  2312. * 引用工单资料数据查询
  2313. * @return void
  2314. * @throws \think\db\exception\DataNotFoundException
  2315. * @throws \think\db\exception\ModelNotFoundException
  2316. * @throws \think\exception\DbException
  2317. */
  2318. public function WorkOrderDetailCope()
  2319. {
  2320. if ($this->request->isGet() === false){
  2321. $this->error('请求错误');
  2322. }
  2323. $param = $this->request->param();
  2324. if (empty($param['search'])){
  2325. $this->error('参数错误');
  2326. }
  2327. $list = \Db('工单_基本资料')
  2328. ->alias('a')
  2329. ->field([
  2330. 'rtrim(a.Gd_gdbh)' => '工单编号',
  2331. 'rtrim(b.客户编号)' => '客户编号',
  2332. 'rtrim(b.客户名称)' => '客户名称',
  2333. 'rtrim(b.产品编号)' => '产品编号',
  2334. 'rtrim(b.产品名称)' => '产品名称'
  2335. ])
  2336. ->join('产品_基本资料 b', 'a.成品代号 = b.产品编号')
  2337. ->join('产品_工艺资料 c', 'a.成品代号 = c.Gy0_cpdh')
  2338. ->join('产品_印件资料 d', 'a.成品代号 = d.yj_cpdh')
  2339. ->where(function($query) use ($param) {
  2340. $query->where('a.Gd_gdbh', 'like', '%'.$param['search'].'%')
  2341. ->whereOr('a.成品名称', 'like', '%'.$param['search'].'%');
  2342. })
  2343. ->where(function($query) {
  2344. $query->where('c.Gy0_cpdh', '<>', '')
  2345. ->where('d.yj_cpdh', '<>', '')
  2346. ->where('b.状态', 'not like', '%停用%')
  2347. ->where('b.产品名称', 'not like', '%停用%');
  2348. })
  2349. ->group('a.Gd_gdbh')
  2350. ->order('a.Uniqid desc')
  2351. ->select();
  2352. if (empty($list)){
  2353. $this->success('未找到工单资料');
  2354. }else{
  2355. $this->success('成功',$list);
  2356. }
  2357. }
  2358. /**
  2359. * 引用产品印件、工艺资料
  2360. * @return void
  2361. * @throws \think\db\exception\BindParamException
  2362. * @throws \think\db\exception\DataNotFoundException
  2363. * @throws \think\db\exception\ModelNotFoundException
  2364. * @throws \think\exception\DbException
  2365. * @throws \think\exception\PDOException
  2366. */
  2367. public function WorkOrderDetailListCope()
  2368. {
  2369. if (Request::instance()->isPost() === false){
  2370. $this->error('请求错误');
  2371. }
  2372. $param = Request::instance()->post();
  2373. if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
  2374. $this->error('参数错误');
  2375. }
  2376. if (isset($param['sort'])){
  2377. $priWhere['yj_yjno'] = ['>=',10];
  2378. $proWhere['a.Gy0_yjno'] = ['>=',10];
  2379. }else{
  2380. $priWhere['yj_yjno'] = ['<',10];
  2381. $proWhere['a.Gy0_yjno'] = ['<',10];
  2382. }
  2383. $list = \db('工单_基本资料')
  2384. ->where('Gd_gdbh',$param['workorder'])
  2385. // ->where('成品代号',$param['productCode'])
  2386. ->field('行号,Gd_cpdh')
  2387. ->select();
  2388. $cpdhList = \db('工单_基本资料')
  2389. ->where('Gd_gdbh',$param['workorder'])
  2390. ->column('Gd_cpdh');
  2391. //引用印件资料
  2392. $PrintList = \db('产品_印件资料')
  2393. ->where('yj_cpdh',$param['productCode'])
  2394. ->whereIn('yj_yjdh',$cpdhList)
  2395. ->where($priWhere)
  2396. ->select();
  2397. if (empty($PrintList)){
  2398. $this->error('未找到印件资料');
  2399. }
  2400. $number = \db('工单_基本资料')
  2401. ->where('Gd_gdbh',$param['workorder'])
  2402. ->where('成品代号',$param['productCode'])
  2403. ->value('rtrim(计划投料)');
  2404. $arr = [];
  2405. foreach ($PrintList as $key => $value){
  2406. foreach ($list as $k=>$v){
  2407. if (rtrim($value['yj_yjdh']) === $v['Gd_cpdh']){
  2408. $PrintList[$key]['Yj_Gdbh'] = $param['workorder'];
  2409. $PrintList[$key]['yj_Yjno'] = $value['yj_yjno'];
  2410. $PrintList[$key]['yj_Yjdh'] = $value['yj_yjdh'];
  2411. $PrintList[$key]['yj_ks'] = $value['yj_ks'];
  2412. $PrintList[$key]['yj_ls'] = $value['yj_ls'];
  2413. $PrintList[$key]['yj_平张投料'] = $number;
  2414. $PrintList[$key]['Sys_id'] = $value['sys_id'];
  2415. // $PrintList[$key]['Uniqid'] = $PrintLastId + $key + 1;
  2416. $PrintList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  2417. $PrintList[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  2418. array_push($arr,[$value['yj_yjno'],$v['行号']]);
  2419. }
  2420. $sql = \db('工单_基本资料')
  2421. ->where('Gd_gdbh',$param['workorder'])
  2422. ->where('Gd_cpdh',$value['yj_yjdh'])
  2423. ->fetchSql(true)
  2424. ->update(['行号'=>$value['yj_yjno']]);
  2425. \db()->query($sql);
  2426. $bomSql = \db('工单_bom资料')
  2427. ->where('BOM_工单编号',$param['workorder'])
  2428. ->where('BOM_产品编号',$value['yj_yjdh'])
  2429. ->fetchSql(true)
  2430. ->update(['BOM_工单行号'=>$value['yj_yjno']]);
  2431. \db()->query($bomSql);
  2432. }
  2433. unset($PrintList[$key]['mod_rq'],$PrintList[$key]['sys_rq'],$PrintList[$key]['sys_id'],$PrintList[$key]['KgToPages'],$PrintList[$key]['yj_tll'],$PrintList[$key]['yj_yjdh'],$PrintList[$key]['yj_yjno'],$PrintList[$key]['UniqId']);
  2434. }
  2435. //引用工艺资料
  2436. $processWhere = [
  2437. 'a.Gy0_方案' => $param['option'],
  2438. 'a.Gy0_cpdh' => $param['productCode']
  2439. ];
  2440. $yjnolist = \db('工单_基本资料')
  2441. ->where('Gd_gdbh',$param['workorder'])
  2442. ->column('Gd_cpdh');
  2443. $ProcessList = \db('产品_工艺资料')
  2444. ->alias('a')
  2445. ->field('a.*')
  2446. ->join('产品_印件资料 b','a.Gy0_cpdh = b.yj_cpdh AND a.Gy0_yjno = yj_yjno')
  2447. ->where($processWhere)
  2448. ->where($proWhere)
  2449. ->whereIn('b.yj_yjdh',$yjnolist)
  2450. ->order('Gy0_yjno,Gy0_gxh')
  2451. ->select();
  2452. if (empty($ProcessList)){
  2453. $this->error('未找到产品工艺资料');
  2454. }
  2455. $ProcesslastId = \db('工单_工艺资料')->order('UniqId desc')->value('rtrim(UniqId)');
  2456. foreach ($ProcessList as $key=>$value){
  2457. if (empty(trim($value['Gy0_shdh']))){
  2458. $rate['rate0'] = 0;
  2459. $rate['rate1'] = 0;
  2460. }else{
  2461. $rate = \db('dic_lzsh')->where('sys_bh',$value['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  2462. if (empty($rate)){
  2463. $this->error('该产品印件号'.$value['Gy0_yjno'].'工序号为'.$value['gy0_gxmc'].'的损耗代号错误,请调整之后再引用');
  2464. }
  2465. }
  2466. //设置默认机台
  2467. $machineList = \db('设备_基本资料')
  2468. ->where('生产工序','like','%'.$value['gy0_gxmc'].'%')
  2469. ->where('使用部门','<>','研发中心')
  2470. ->where('设备编组','<>','')
  2471. ->where('sys_sbID','<>','')
  2472. ->order('设备编号')
  2473. ->value('设备编号');
  2474. $ProcessList[$key]['Gy0_sbbh'] = '';
  2475. if (!empty($machineList)){
  2476. $ProcessList[$key]['Gy0_sbbh'] = $machineList;
  2477. }
  2478. $ProcessList[$key]['Gy0_yjno'] = $value['Gy0_yjno'];
  2479. $ProcessList[$key]['Gy0_gdbh'] = $param['workorder'];
  2480. $ProcessList[$key]['Gy0_gxmc'] = $value['gy0_gxmc'];
  2481. $ProcessList[$key]['Gy0_SITE'] = $value['Gy0_site'];
  2482. $ProcessList[$key]['Gy0_shdh'] = $value['Gy0_shdh'];
  2483. $ProcessList[$key]['Gy0_Rate0'] = $rate['rate0'];
  2484. $ProcessList[$key]['Gy0_Rate1'] = $rate['rate1'];
  2485. $ProcessList[$key]['Gy0_ks'] = $value['Gy0_Ks'];
  2486. $ProcessList[$key]['Gy0_ms'] = $value['Gy0_Ms'];
  2487. $ProcessList[$key]['Gy0_oil'] = $value['Gy0_Oil'];
  2488. $ProcessList[$key]['Gy0_计划接货数'] = 0;
  2489. $ProcessList[$key]['Gy0_计划损耗'] = 0;
  2490. $ProcessList[$key]['无形损承担比例'] = 0;
  2491. $ProcessList[$key]['超节损承担比例'] = 1;
  2492. $ProcessList[$key]['超节损核算单价'] = 0;
  2493. $ProcessList[$key]['Gy0_sj1'] = '1900-01-01 00:00:00';
  2494. $ProcessList[$key]['Gy0_sj2'] = '1900-01-01 00:00:00';
  2495. // $ProcessList[$key]['UniqId'] = $ProcesslastId + $key + 1;
  2496. $ProcessList[$key]['PD_WG'] = '1900-01-01 00:00:00';
  2497. $ProcessList[$key]['Sys_rq'] = date('Y-m-d H:i:s', time());
  2498. unset($ProcessList[$key]['Gy0_Oil'],$ProcessList[$key]['Gy0_Ms'],$ProcessList[$key]['Gy0_Ks'],$ProcessList[$key]['UniqID'],$ProcessList[$key]['Gy0_cpdh'],$ProcessList[$key]['gy0_gxmc'],$ProcessList[$key]['Gy0_site']);
  2499. }
  2500. //插入数据
  2501. \db()->startTrans();
  2502. try {
  2503. \db('工单_工艺资料')->where('Gy0_gdbh',$param['workorder'])->delete();
  2504. $processSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($ProcessList);
  2505. \db()->query($processSql);
  2506. \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->delete();
  2507. $printSql = \db('工单_印件资料')->fetchSql(true)->insertAll($PrintList);
  2508. \db()->query($printSql);
  2509. \db()->commit();
  2510. }catch (\Exception $e){
  2511. \db()->rollback();
  2512. // echo $e->getMessage();
  2513. }
  2514. //计算工序计划生产数量
  2515. if ($number !== null){
  2516. $list = \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->field('yj_Yjno,yj_平张投料')->select();
  2517. foreach ($list as $value){
  2518. if ((int)$value['yj_平张投料'] >0){
  2519. $this->PlannedProcessYield($param['workorder'],$value['yj_Yjno'],0,$value['yj_平张投料']);
  2520. }
  2521. }
  2522. }
  2523. $this->success('成功');
  2524. }
  2525. /**
  2526. * 引用产品印件、工艺资料->信息获取
  2527. * @return void
  2528. * @throws \think\db\exception\DataNotFoundException
  2529. * @throws \think\db\exception\ModelNotFoundException
  2530. * @throws \think\exception\DbException
  2531. */
  2532. public function ProductCopeDetail()
  2533. {
  2534. if ($this->request->isGet() === false){
  2535. $this->error('请求错误');
  2536. }
  2537. $param = $this->request->param();
  2538. if (empty($param['workorder'])){
  2539. $this->error('参数错误');
  2540. }
  2541. $list = \db('工单_基本资料')
  2542. ->alias('a')
  2543. ->field([
  2544. 'rtrim(a.Gd_gdbh)' => '工单编号',
  2545. 'rtrim(b.客户编号)' => '客户编号',
  2546. 'rtrim(b.客户名称)' => '客户名称',
  2547. 'rtrim(b.产品编号)' => '产品编号',
  2548. 'rtrim(b.产品名称)' => '产品名称'
  2549. ])
  2550. ->join('产品_基本资料 b','a.成品代号 = b.产品编号')
  2551. ->where('a.Gd_gdbh',$param['workorder'])
  2552. ->find();
  2553. if (empty($list)){
  2554. $this->error('未找到工单信息');
  2555. }
  2556. $option = \db('产品_工艺资料')
  2557. ->field('rtrim(Gy0_方案) as 方案')
  2558. ->where('Gy0_cpdh',$list['产品编号'])
  2559. ->group('Gy0_方案')
  2560. ->select();
  2561. $list['方案'] = $option;
  2562. $this->success('成功',$list);
  2563. }
  2564. /**
  2565. * 工艺资料计划产量重新分配
  2566. * @param string $workOrder 工单
  2567. * @param int $yjno 印件号
  2568. * @param int $gxh 工序号
  2569. * @param int $feed 平张投料
  2570. * @return bool
  2571. * @throws \think\Exception
  2572. * @throws \think\db\exception\BindParamException
  2573. * @throws \think\db\exception\DataNotFoundException
  2574. * @throws \think\db\exception\ModelNotFoundException
  2575. * @throws \think\exception\DbException
  2576. * @throws \think\exception\PDOException
  2577. */
  2578. public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
  2579. {
  2580. $where = [
  2581. 'Gy0_gdbh'=>$workOrder,
  2582. 'Gy0_yjno'=>$yjno,
  2583. ];
  2584. //获取工艺资料
  2585. $processList = \db('工单_工艺资料')
  2586. ->where($where)
  2587. ->field('CONCAT(rtrim(Gy0_gxmc),"[",rtrim(Add_gxmc),"]") as 工序名称,Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
  2588. ->order('Gy0_gxh')
  2589. ->select();
  2590. if (empty($processList)){
  2591. $this->success('未找到该工单工序资料');
  2592. }
  2593. $processDetail = \db('工单_工艺资料')
  2594. ->where($where)
  2595. ->field('CONCAT(rtrim(Gy0_gxmc),"[",rtrim(Add_gxmc),"]") as 工序名称,Gy0_ls as 联数')
  2596. ->select();
  2597. $number1 = $number2 = 1;
  2598. foreach ($processDetail as $k => $v) {
  2599. if (strpos($v['工序名称'],'分切') !== false) {
  2600. $number1 = $v['联数'];
  2601. }
  2602. if (strpos($v['工序名称'],'分切') === false && $v['联数'] > 1) {
  2603. $number2 = $v['联数'];
  2604. }
  2605. }
  2606. $Multiple = $number1/$number2;
  2607. if (is_int($Multiple) === false) {
  2608. $Multiple = 1;
  2609. }
  2610. //计算损耗定额和计划产量
  2611. $production = [];
  2612. $i = $m = 0;
  2613. foreach ($processList as $key=>$value){
  2614. if (strpos($v['工序名称'],'分切') !== false) {
  2615. $m = $key;
  2616. }
  2617. if ($key === 0){
  2618. array_push($production,$feed);
  2619. }else{
  2620. if ($key === $m+1){
  2621. $production[$key] = $production[$key]/$value['Gy0_ls']/$Multiple;
  2622. }else{
  2623. $production[$key] = $production[$key]/$value['Gy0_ls'];
  2624. }
  2625. }
  2626. $wastage = 0;
  2627. if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
  2628. $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
  2629. }
  2630. if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
  2631. $wastage = round($wastage * $value['Gy0_ms']);
  2632. }
  2633. array_push($production,ceil($production[$key]-$wastage)*$value['Gy0_ls']);
  2634. $processSql = \db('工单_工艺资料')
  2635. ->where('UniqId',$value['UniqId'])
  2636. ->fetchSql(true)
  2637. ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
  2638. $res = \db()->query($processSql);
  2639. if ($res === false){
  2640. $i++;
  2641. }
  2642. }
  2643. if ($i===0){
  2644. return true;
  2645. }else{
  2646. return false;
  2647. }
  2648. }
  2649. /**
  2650. * 工单资料删除
  2651. * @return void
  2652. * @throws \think\exception\PDOException
  2653. */
  2654. public function WorkOrderDel()
  2655. {
  2656. if ($this->request->isGet() === false){
  2657. $this->error('请求错误');
  2658. }
  2659. $param = $this->request->param();
  2660. if (isset($param['UniqId']) === false){
  2661. $this->error('参数错误');
  2662. }
  2663. $WorkOrderId = explode(',',$param['UniqId']);
  2664. $i = 0;
  2665. foreach ($WorkOrderId as $key=>$value){
  2666. //获取工单编号
  2667. $workorder = \db('工单_基本资料')
  2668. ->where('Uniqid',$value)
  2669. ->value('rtrim(Gd_gdbh)');
  2670. $status = \db('设备_产量计酬')
  2671. ->where('sczl_gdbh',$workorder)
  2672. ->count();
  2673. if ($status === 0){
  2674. //删除工单资料、工艺资料、印件资料
  2675. \db()->startTrans();
  2676. try {
  2677. \db('工单_基本资料')->where('Gd_gdbh',$workorder)->delete();
  2678. if (!empty(\db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->find())){
  2679. \db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->delete();
  2680. }
  2681. if (!empty(\db('工单_印件资料')->where('Yj_Gdbh',$workorder)->find())){
  2682. \db('工单_印件资料')->where('Yj_Gdbh',$workorder)->delete();
  2683. }
  2684. if (!empty(\db('工单_bom资料')->where('BOM_工单编号',$workorder)->find())){
  2685. \db('工单_bom资料')->where('BOM_工单编号',$workorder)->delete();
  2686. }
  2687. \db()->commit();
  2688. // 成功删除后记录日志
  2689. $logSql = \db('系统操作日志表')->fetchSql(true)->insert([
  2690. 'Gd_gdbh' => $workorder,
  2691. 'ModifyUser' => $param['sys_id'],
  2692. 'ModifyTime' => date('Y-m-d H:i:s'),
  2693. 'FieldName' => '工单删除',
  2694. 'NewValue' => '已删除',
  2695. 'ModifySource' => '工单删除'
  2696. ]);
  2697. \db()->query($logSql);
  2698. }catch (\Exception $e){
  2699. \db()->rollback();
  2700. $i++;
  2701. }
  2702. }else{
  2703. $this->error('工单'.$workorder.'已上报数据无法删除,请重新确认');
  2704. }
  2705. }
  2706. if ($i === 0){
  2707. $this->success('删除成功');
  2708. }else{
  2709. $this->error('删除失败');
  2710. }
  2711. }
  2712. /**
  2713. * 修正核算参数-》工单产品信息获取
  2714. * @return void
  2715. * @throws \think\db\exception\DataNotFoundException
  2716. * @throws \think\db\exception\ModelNotFoundException
  2717. * @throws \think\exception\DbException
  2718. */
  2719. public function ProductNameData()
  2720. {
  2721. if ($this->request->isGet() === false){
  2722. $this->error('请求错误');
  2723. }
  2724. $workOrder = input('workOrder');
  2725. if (empty($workOrder)){
  2726. $this->error('参数错误');
  2727. }
  2728. $orderList = \db('工单_基本资料')
  2729. ->field('rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称')
  2730. ->where('Gd_gdbh',$workOrder)
  2731. ->find();
  2732. $this->success('成功',$orderList);
  2733. }
  2734. /**
  2735. * 获取联数
  2736. * @return void
  2737. * @throws \think\db\exception\DataNotFoundException
  2738. * @throws \think\db\exception\ModelNotFoundException
  2739. * @throws \think\exception\DbException
  2740. */
  2741. public function getCouplet()
  2742. {
  2743. if ($this->request->isGet() === false){
  2744. $this->error('请求错误');
  2745. }
  2746. $param = $this->request->param();
  2747. if (empty($param['gdbh']) || empty($param['yjno'])){
  2748. $this->error('参数错误');
  2749. }
  2750. $list = \db('工单_印件资料')
  2751. ->where('Yj_gdbh',$param['gdbh'])
  2752. ->where('yj_Yjno',$param['yjno'])
  2753. ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
  2754. ->find();
  2755. $process = \db('工单_工艺资料')
  2756. ->where('Gy0_gdbh',$param['gdbh'])
  2757. ->where('Gy0_yjno',$param['yjno'])
  2758. ->order('Gy0_gxh desc')
  2759. ->value('Gy0_gxh');
  2760. $list['工序号'] = $process + 1;
  2761. $this->success('成功',$list);
  2762. }
  2763. /**
  2764. * 糊盒工单配件完成度查询
  2765. * @return void
  2766. * @throws \think\db\exception\DataNotFoundException
  2767. * @throws \think\db\exception\ModelNotFoundException
  2768. * @throws \think\exception\DbException
  2769. */
  2770. public function Accessories()
  2771. {
  2772. if ($this->request->isGet() === false){
  2773. $this->error('请求错误');
  2774. }
  2775. $param = $this->request->param();
  2776. if (empty($param['batch'])){
  2777. $this->error('参数错误');
  2778. }
  2779. $list = \db('工单_基本资料')
  2780. ->alias('a')
  2781. ->join('工单_印件资料 b','a.Gd_gdbh=b.Yj_Gdbh')
  2782. ->join('成品入仓 c','a.Gd_gdbh=c.jjcp_gdbh and a.销售订单号 = c.订单编号 and b.yj_Yjno = c.jjcp_yjno','left')
  2783. ->where('a.销售订单号',$param['batch'])
  2784. ->field('a.Gd_gdbh as 工单编号,b.yj_Yjno as 印件号,b.yj_yjmc as 印件名称,b.yj_平张投料*b.yj_ls*b.yj_ks as 计划产量,SUM(c.jjcp_sl) as 入仓数量')
  2785. ->group('a.Gd_gdbh,b.yj_Yjno')
  2786. ->order('a.Gd_gdbh,b.yj_Yjno')
  2787. ->select();
  2788. if (empty($list)){
  2789. $this->error('未找到数据');
  2790. }else{
  2791. $this->success('成功',$list);
  2792. }
  2793. }
  2794. }