WorkOrder.php 127 KB

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