Facility.php 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Log;
  6. use think\Request;
  7. /**
  8. * 设备运行跟踪
  9. */
  10. class Facility extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * 左侧菜单栏
  16. * @ApiMethod (GET)
  17. * @return void
  18. * @throws \think\db\exception\DataNotFoundException
  19. * @throws \think\db\exception\ModelNotFoundException
  20. * @throws \think\exception\DbException
  21. */
  22. public function getTab()
  23. {
  24. if ($this->request->isGet() === false){
  25. $this->error('请求错误');
  26. }
  27. $param = $this->request->param();
  28. // if (isset($param['sort'])){
  29. // $where['使用部门'] = '智能车间';
  30. // }else{
  31. // $where['使用部门'] = ['<>','智能车间'];
  32. // }
  33. $data = [];
  34. $date = date('Y-m-d 00:00:00',time()-3888000);
  35. $department = \db('设备_基本资料')
  36. ->distinct(true)
  37. ->where('使用部门','<>','研发中心')
  38. ->where('设备编组','<>','')
  39. ->where('sys_sbID','<>','')
  40. // ->where($where)
  41. ->order('设备编组')
  42. ->column('rtrim(使用部门) as 使用部门');
  43. if (empty($department)){
  44. $this->success('为获取到机台数据');
  45. }
  46. $list = \db('设备_产量计酬')
  47. ->field([
  48. 'DISTINCT(sczl_rq)' => '时间',
  49. 'rtrim(sczl_jtbh)' => '机台编号'
  50. ])
  51. ->where('sczl_rq','>',$date)
  52. ->order('sczl_rq desc')
  53. ->select();
  54. if (empty($list)){
  55. $this->success('未找到机台生产记录');
  56. }
  57. foreach ($department as $value){
  58. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->order('设备编号')->select();
  59. foreach ($machine as $k=>$v){
  60. $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
  61. foreach ($list as $kk=>$vv){
  62. if ($v['设备编号'] === $vv['机台编号']){
  63. array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
  64. }
  65. }
  66. }
  67. }
  68. $this->success('成功',$data);
  69. }
  70. /**
  71. * 机台每日产量
  72. * @ApiMethod (GET)
  73. * @param string $machine 机台编号
  74. * @param string $date 日期
  75. * @return void
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. * @throws \think\exception\DbException
  79. */
  80. public function chanLiang()
  81. {
  82. if ($this->request->isGet() === false){
  83. $this->error('请求错误');
  84. }
  85. $machine = input('machine');
  86. $date = input('date');
  87. $where = [
  88. 'sczl_jtbh' => $machine,
  89. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  90. ];
  91. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,
  92. rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,
  93. rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,IF(sczl_zcfp = 0, "",sczl_zcfp) as 制程废品,
  94. IF(sczl_zccp = 0, "",sczl_zccp) as 制程次品,IF(sczl_前工序废 = 0, "",sczl_前工序废) as 前工序废,
  95. IF(sczl_来料少数 = 0, "",sczl_来料少数) as 来料异常,IF(sczl_装版总工时 = 0, "",sczl_装版总工时) as 装版总工时,
  96. IF(sczl_打样总工时 = 0, "",sczl_打样总工时) as 打样总工时,
  97. IF(sczl_装版工时 = 0, "",sczl_装版工时) as 装版工时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,
  98. IF(sczl_打样工时 = 0, "",sczl_打样工时) as 打样工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,
  99. IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
  100. IF(码开始行 = 0, "",码开始行) as 码开始行,IF(码结束行 = 0, "",码结束行) as 码结束行,
  101. IF(码包 = 0, "",码包) as 码包,IF(主电表 = 0, "",主电表) as 主电表,IF(辅电表 = 0, "",辅电表) as 辅电表,
  102. IF(sczl_ms = 0, "",sczl_ms) as 色度数,
  103. rtrim(sys_id) as 用户,rtrim(sys_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,
  104. IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  105. sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,
  106. sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
  107. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,
  108. rtrim(sczl_dedh) as 定额代号';
  109. //机台信息
  110. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  111. //组员信息
  112. $list = \db('设备_产量计酬')->where($where)->field($field)->select();
  113. $totalA = \db('设备_产量计酬')
  114. ->where($where)
  115. ->where('sczl_bzdh','like','A%')
  116. ->field('SUM(sczl_cl) as 产量, SUM(sczl_zcfp) as 制程废品, SUM(sczl_zccp) as 制程次品, SUM(sczl_来料少数) as 来料异常, SUM(sczl_装版工时) as 装版工时, SUM(sczl_保养工时) as 保养工时, SUM(sczl_打样工时) as 打样工时,SUM(sczl_异常停机工时) as 异常工时,SUM(sczl_异常工时1) as 异常补时工时,SUM(sczl_设备运行工时) as 通电工时,SUM(sczl_前工序废) as 前工序废')
  117. ->select();
  118. $totalB = \db('设备_产量计酬')
  119. ->where($where)
  120. ->where('sczl_bzdh','like','B%')
  121. ->field('SUM(sczl_cl) as 产量, SUM(sczl_zcfp) as 制程废品, SUM(sczl_zccp) as 制程次品, SUM(sczl_来料少数) as 来料异常, SUM(sczl_装版工时) as 装版工时, SUM(sczl_保养工时) as 保养工时, SUM(sczl_打样工时) as 打样工时,SUM(sczl_异常停机工时) as 异常工时,SUM(sczl_异常工时1) as 异常补时工时,SUM(sczl_设备运行工时) as 通电工时,SUM(sczl_前工序废) as 前工序废')
  122. ->select();
  123. if (empty($list)){
  124. $this->success('',[]);
  125. }
  126. foreach ($list as $key=>$value){
  127. //产品名称
  128. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  129. if (!empty($productName)){
  130. if (!empty($productName['成品名称'])){
  131. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
  132. $list[$key]['cpmc'] = $productName['成品名称'];
  133. }else{
  134. $list[$key]['产品名称'] = $value['工单编号'];
  135. $list[$key]['cpmc'] = '';
  136. }
  137. }else{
  138. $list[$key]['产品名称'] = $value['工单编号'];
  139. $list[$key]['cpmc'] = '';
  140. }
  141. $process = \db('工单_工艺资料')
  142. ->where('Gy0_gdbh',$value['工单编号'])
  143. ->where('Gy0_yjno',$value['yjno'])
  144. ->where('Gy0_gxh',$value['gxh'])
  145. ->field('rtrim(工价系数) as 工价系数,rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距')
  146. ->find();
  147. if (!empty($process)){
  148. if ($value['难度系数'] == 0){
  149. $list[$key]['难度系数'] = $process['工价系数'];
  150. }else{
  151. $list[$key]['难度系数'] = $process['工价系数'].'x'.$value['难度系数'];
  152. }
  153. $list[$key]['印刷方式'] = $process['印刷方式'].' '.$process['版距'];
  154. }else{
  155. $list[$key]['难度系数'] = '';
  156. $list[$key]['印刷方式'] = '';
  157. }
  158. if ($value['yjno']<10){
  159. $list[$key]['yjno'] = '0'.$value['yjno'];
  160. }
  161. if (empty($value['定额代号'])){
  162. $list[$key]['千件工价'] = '';
  163. $list[$key]['日定额'] = '';
  164. $list[$key]['补产标准'] = '';
  165. }else{
  166. $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
  167. $list[$key]['千件工价'] = $row['千件工价'];
  168. $list[$key]['日定额'] = $row['日定额'];
  169. $list[$key]['补产标准'] = $row['补产标准'];
  170. }
  171. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
  172. $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
  173. for ($i=1;$i<11;$i++){
  174. if (isset($value['sczl_bh'.$i])){
  175. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  176. if (isset($name['name'])){
  177. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  178. }
  179. }
  180. unset($list[$key]['sczl_bh'.$i],$list[$key]['sczl_rate'.$i]);
  181. }
  182. $list[$key]['换版类型'] = $list[$key]['换版联拼数'] = '';
  183. if (!empty($value['装版总工时']) && $value['装版总工时'] !== 0){
  184. $pridata = \db('设备_装版工时')
  185. ->field('换版联拼数,换版类型')
  186. ->where('yieldUid',$value['UniqId'])
  187. ->order('Uniqid desc')
  188. ->find();
  189. if (!empty($pridata)){
  190. $list[$key]['换版类型'] = $pridata['换版类型'];
  191. $list[$key]['换版联拼数'] = $pridata['换版联拼数'];
  192. }
  193. }
  194. }
  195. $list['totalA'] = $totalA[0]['产量'];
  196. $list['totalB'] = $totalB[0]['产量'];
  197. $list['制程废品A'] = $totalA[0]['制程废品'];
  198. $list['制程废品B'] = $totalB[0]['制程废品'];
  199. $list['制程次品A'] = $totalA[0]['制程次品'];
  200. $list['制程次品B'] = $totalB[0]['制程次品'];
  201. $list['来料异常A'] = $totalA[0]['来料异常'];
  202. $list['来料异常B'] = $totalB[0]['来料异常'];
  203. $list['装版工时A'] = $totalA[0]['装版工时'];
  204. $list['装版工时B'] = $totalB[0]['装版工时'];
  205. $list['保养工时A'] = $totalA[0]['保养工时'];
  206. $list['保养工时B'] = $totalB[0]['保养工时'];
  207. $list['打样工时A'] = $totalA[0]['打样工时'];
  208. $list['打样工时B'] = $totalB[0]['打样工时'];
  209. $list['异常工时A'] = $totalA[0]['异常工时'];
  210. $list['异常工时B'] = $totalB[0]['异常工时'];
  211. $list['异常补时工时A'] = $totalA[0]['异常补时工时'];
  212. $list['异常补时工时B'] = $totalB[0]['异常补时工时'];
  213. $list['通电工时A'] = $totalA[0]['通电工时'];
  214. $list['通电工时B'] = $totalB[0]['通电工时'];
  215. $list['前工序废A'] = $totalA[0]['前工序废'];
  216. $list['前工序废B'] = $totalB[0]['前工序废'];
  217. $this->success('成功',$list);
  218. }
  219. /**
  220. * 当日制程检验记录
  221. * @ApiMethod (GET)
  222. * @param string $machine 机台编号
  223. * @param string $date 日期
  224. * @return void
  225. * @throws \think\db\exception\DataNotFoundException
  226. * @throws \think\db\exception\ModelNotFoundException
  227. * @throws \think\exception\DbException
  228. */
  229. public function Inspect()
  230. {
  231. if ($this->request->isGet() === false){
  232. $this->error('请求错误');
  233. }
  234. $machine = input('machine');
  235. // $date = input('date');
  236. // 获取当前时间
  237. $current_time = time();
  238. // 设置时间范围
  239. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  240. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  241. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  242. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  243. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  244. // 判断当前时间属于哪个时间范围
  245. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  246. $startTime = date('Y-m-d') . ' 08:30:00';
  247. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  248. $startTime = date('Y-m-d') . ' 20:30:00';
  249. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  250. $startTime = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  251. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  252. $startTime = date('Y-m-d') . ' 20:30:00';
  253. }
  254. if (empty($machine)){
  255. $this->error('参数错误');
  256. }
  257. $where = [
  258. '设备编号' => $machine,
  259. '开工时间' => $startTime,
  260. '类别' => ['in',['IPQC检验','机台检验']],
  261. ];
  262. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,提交时间,rtrim(检验项目) as 检验项目';
  263. $list = \db('制程检验_记录')
  264. ->where($where)
  265. ->field($field)
  266. ->select();
  267. if (empty($list)){
  268. $this->success('未找到检验记录');
  269. }
  270. $data = [];
  271. foreach ($list as $key=>$value)
  272. {
  273. $data['item'][$key] = $value['检验项目'];
  274. $data['InspectionTime'][$key] = date('H:i',strtotime($value['提交时间']));
  275. $data['工单编号'][$key] = $value['工单编号'];
  276. }
  277. $data['item'] = array_unique($data['item']);
  278. $data['InspectionTime'] = array_values(array_unique($data['InspectionTime']));
  279. $data['工单编号'] = array_values(array_unique($data['工单编号']));
  280. foreach ($data['工单编号'] as $key => $value){
  281. foreach ($data['item'] as $k=>$v){
  282. $time = '';
  283. foreach ($list as $kk=>$vv){
  284. if ($vv['工单编号'] === $value && $vv['检验项目'] === $v){
  285. $time = $time.date('H:i',strtotime($vv['提交时间'])).',';
  286. $data['row'][$key][$k] = [
  287. '工单编号' => $value,
  288. '印件号' => $vv['印件号'],
  289. '工序名称' => $vv['工序名称'],
  290. '检验项目' => $v,
  291. 'time' => substr($time,0,-1),
  292. ];
  293. }
  294. }
  295. }
  296. $data['row'][$key] = array_values($data['row'][$key]);
  297. }
  298. unset($data['item'],$data['工单编号']);
  299. $this->success('成功',$data);
  300. }
  301. /**
  302. * 设备生产中工单信息
  303. * @ApiMethod (GET)
  304. * @param string $machine 机台编号
  305. * @return void
  306. * @throws \think\Exception
  307. * @throws \think\db\exception\DataNotFoundException
  308. * @throws \think\db\exception\ModelNotFoundException
  309. * @throws \think\exception\DbException
  310. */
  311. public function Production()
  312. {
  313. if (Request::instance()->isGet() == false) {
  314. $this->error('非法请求');
  315. }
  316. $params = Request::instance()->param();
  317. if (!isset($params['machine']) || empty($params['machine'])) {
  318. $this->error('参数错误');
  319. }
  320. $machine = $params['machine'];
  321. $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  322. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  323. $list = [];
  324. $row = [];
  325. if (!empty($data['工单编号'])){
  326. $endTime = \db('工单_工艺资料')
  327. ->where('Gy0_gdbh',$data['工单编号'])
  328. ->where('Gy0_yjno',$data['印件号'])
  329. ->where('Gy0_gxh',$data['工序号'])
  330. ->find();
  331. $list['工单编号'] = $data['工单编号'];
  332. if (!empty($endTime)){
  333. $list['印件号'] = $data['印件号'];
  334. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
  335. $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号');
  336. $list['产品名称'] = rtrim($name);
  337. $list['产品代号'] = rtrim($code);
  338. $list['工序名称'] = $data['工序名称'];
  339. }
  340. $list['状态'] = rtrim($data['当前状态']);
  341. $list['开工时间'] = $data['开工时间'];
  342. }else{
  343. $list['工单编号'] = '';
  344. $list['印件号'] = 0;
  345. $list['产品名称'] = '';
  346. $list['工序名称'] = '';
  347. $list['产品代号'] = '';
  348. $list['状态'] = '';
  349. $list['开工时间'] = '';
  350. }
  351. $list['班组编号'] = rtrim($data['班组编号']);
  352. $list['班组Id'] = rtrim($data['班组ID']);
  353. $class = \db('设备_班组资料')->where('UniqId',$data['班组ID'])->field("rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
  354. rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
  355. rtrim(sczl_bh10) as bh10")->find();
  356. if (!empty($class)){
  357. for ($i=1;$i<11;$i++) {
  358. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  359. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  360. $row[$i] = [
  361. '编号' => $class['bh' . $i],
  362. '姓名' => $name['姓名']
  363. ];
  364. }
  365. }
  366. $row = array_values($row);
  367. }
  368. $list['班组成员'] = $row;
  369. $list['定额代号'] = $machineCode;
  370. $this->success('成功',$list);
  371. }
  372. /**
  373. * 设备工作清单
  374. * @ApiMethod (GET)
  375. * @param string $machine 机台编号
  376. * @return void
  377. * @throws \think\db\exception\DataNotFoundException
  378. * @throws \think\db\exception\ModelNotFoundException
  379. * @throws \think\exception\DbException
  380. */
  381. public function EquipmentWorklist()
  382. {
  383. if ($this->request->isGet() === false){
  384. $this->error('请求错误');
  385. }
  386. $machine = input('machine');
  387. if (empty($machine)){
  388. $this->error('参数错误');
  389. }
  390. $orderList = \db('工单_工艺资料')
  391. ->alias('a')
  392. // ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_yjno = b.sczl_yjno AND a.Gy0_gxh = b.sczl_gxh','LEFT')
  393. ->join('工单_基本资料 c','a.Gy0_gdbh = c.Gd_gdbh')
  394. ->join('工单_印件资料 d','a.Gy0_gdbh = d.Yj_Gdbh AND a.Gy0_yjno = d.yj_Yjno')
  395. ->field('a.Gy0_gdbh as gdbh,rtrim(a.质量要求) as 质量信息,a.Gy0_yjno as yjno,a.Gy0_gxh as gxh,a.Gy0_sbbh as sbbh,
  396. rtrim(a.Gy0_gxmc) as gxmc,rtrim(a.Add_gxmc) as add_gxmc,a.Gy0_辅助工时 as 装版工时,a.Gy0_小时产能 as 工序产能,a.Gy0_生产工时 as 计划工时,
  397. a.Gy0_sj1 as sj1,a.Gy0_sj2 as sj2,rtrim(a.工序备注) as 排产备注,d.yj_yjmc as 印件名称,c.成品名称 as 产品名称,c.成品代号 as 产品代号,
  398. a.Gy0_计划接货数 as 计划接货数,a.Gy0_ls as ls,a.Gy0_班次安排 as 班组,a.UniqId as UniqId,a.Gy0_最早开工时间 as 最早开工时间')
  399. ->where('a.Gy0_sbbh','like','%'.$machine.'%')
  400. ->where('a.PD_WG','1900-01-01 00:00:00')
  401. ->where('a.Gy0_sj1','<>','1900-01-01 00:00:00')
  402. ->where('c.gd_statu','2-生产中')
  403. ->group('a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh')
  404. ->order('a.Gy0_sj1')
  405. ->select();
  406. if (!empty($orderList)){
  407. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  408. foreach ($orderList as $key=>$value){
  409. $machineList = explode(' ',$value['sbbh']);
  410. $cl_data = \db('设备_产量计酬')
  411. ->field('SUM(sczl_cl) as 已完成,SUM(sczl_zcfp) as 制程废品')
  412. ->where('sczl_gdbh',$value['gdbh'])
  413. ->where('sczl_yjno',$value['yjno'])
  414. ->where('sczl_gxh',$value['gxh'])
  415. ->select();
  416. $orderList[$key]['status'] = 0;
  417. if (!empty($data)){
  418. if ($value['gdbh'] === $data['工单编号'] && $value['yjno'] === $data['印件号'] && $value['gxh'] === $data['工序号']) {
  419. $orderList[$key]['status'] = 1;
  420. }
  421. }
  422. $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
  423. $orderList[$key]['印件号'] = $value['yjno'];
  424. $orderList[$key]['工序号'] = $value['gxh'];
  425. if ($value['yjno']<10){
  426. $orderList[$key]['yjno'] = '0'.$value['yjno'];
  427. }
  428. if ($value['gxh']<10){
  429. $orderList[$key]['gxh'] = '0'.$value['gxh'];
  430. }
  431. $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
  432. $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  433. if ((int)$cl_data[0]['制程废品'] === 0){
  434. $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$cl_data[0]['已完成']=null?'':(int)$cl_data[0]['已完成'];
  435. }else{
  436. $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$cl_data[0]['已完成']=null?'':(int)$cl_data[0]['已完成'].'('.$cl_data[0]['制程废品'].')';
  437. }
  438. $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
  439. unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['gxh'],$orderList[$key]['yjno'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['计划接货数'],$orderList[$key]['已完成'],$orderList[$key]['印件名称'],$orderList[$key]['ls'],$orderList[$key]['制程废品']);
  440. if (in_array($machine,$machineList) === false){
  441. unset($orderList[$key]);
  442. }
  443. }
  444. $data = array_values($orderList);
  445. $this->success('成功',$data);
  446. }else{
  447. $this->error('未找到数据');
  448. }
  449. }
  450. /**
  451. * 工序、印件、完成数量
  452. * @ApiMethod (GET)
  453. * @param string $workOrder 工单编号
  454. * @return void
  455. * @throws \think\Exception
  456. * @throws \think\db\exception\DataNotFoundException
  457. * @throws \think\db\exception\ModelNotFoundException
  458. * @throws \think\exception\DbException
  459. */
  460. public function Procedure()
  461. {
  462. if ($this->request->isGet() === false){
  463. $this->error('请求错误');
  464. }
  465. $workOrder = input('Gd_gdbh');
  466. $data = [];
  467. if (!empty($workOrder)){
  468. //右边工艺及完成数量
  469. $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  470. ->distinct(true)->order('sczl_gxh')
  471. ->column('sczl_gxh');
  472. foreach ($Process as $k=>$v){
  473. $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  474. ->where('sczl_gxh',$v)
  475. ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
  476. ->find();
  477. if ($res['sczl_yjno']<10){
  478. $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
  479. }
  480. $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
  481. $processList['completed'] = \db('设备_产量计酬')
  482. ->where('sczl_gdbh',$workOrder)
  483. ->where('sczl_gxh',$v)
  484. ->count('DISTINCT sczl_num');
  485. array_push($data,$processList);
  486. }
  487. }
  488. $this->success('成功',$data);
  489. }
  490. /**
  491. * 班组人员及分配比例
  492. * @ApiMethod (GET)
  493. * @param string $machine 机台编号
  494. * @return void
  495. * @throws \think\db\exception\DataNotFoundException
  496. * @throws \think\db\exception\ModelNotFoundException
  497. * @throws \think\exception\DbException
  498. */
  499. public function Team()
  500. {
  501. if ($this->request->isGet() === false){
  502. $this->error('请求错误');
  503. }
  504. $machine = input('machine');
  505. if (empty($machine)){
  506. $this->error('参数错误');
  507. }
  508. $where = [
  509. 'sczl_jtbh' => $machine,
  510. ];
  511. $field = 'rtrim(sczl_bzdh) as 班组号,rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
  512. rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
  513. rtrim(sczl_bh10) as bh10,rtrim(sczl_rate1) as rate1,rtrim(sczl_rate2) as rate2,rtrim(sczl_rate3) as rate3,rtrim(sczl_rate4) as rate4,
  514. rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
  515. rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
  516. $team = \db('设备_产量计酬')
  517. ->where('sczl_jtbh',$machine)
  518. ->field($field)
  519. ->order('UniqId desc')
  520. ->find();
  521. $list = \db('设备_班组资料')->where($where)->field($field)->select();
  522. $data = [];
  523. foreach ($list as $k=>$v){
  524. if ($team == $v){
  525. $data[$k]['status'] = 1;
  526. }else{
  527. $data[$k]['status'] = 0;
  528. }
  529. $data[$k]['ID'] = $v['ID'];
  530. $data[$k]['班组号'] = $v['班组号'];
  531. for ($i=1;$i<11;$i++){
  532. if ($v['bh'.$i] != ''){
  533. $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
  534. if ($v['rate'.$i] > 0){
  535. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
  536. }else{
  537. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' (0.00%'.')';
  538. }
  539. }
  540. }
  541. }
  542. $this->success('成功',$data);
  543. }
  544. /**
  545. * 当班产量明细
  546. * @ApiMethod (GET)
  547. * @param string $machine 机台编号
  548. * @param string $workOrder 工单编号
  549. * @param string $team 班次
  550. * @return void
  551. * @throws \think\db\exception\DataNotFoundException
  552. * @throws \think\db\exception\ModelNotFoundException
  553. * @throws \think\exception\DbException
  554. */
  555. public function OutputDetail()
  556. {
  557. if ($this->request->isGet() === false){
  558. $this->error('请求错误');
  559. }
  560. $machine = input('machine');
  561. $workOrder = input('Gd_gdbh');
  562. $team = substr(input('team'),0,1);
  563. if (empty($machine) || empty($team)){
  564. $this->success('');
  565. }
  566. $sczlTime = date('Y-m-d H:i:s',time());
  567. if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime<date('Y-m-d 08:30:00')){
  568. $time = date('Y-m-d 00:00:00',time()-86400);
  569. }else{
  570. $time = date('Y-m-d 00:00:00');
  571. }
  572. $where = [
  573. 'sczl_jtbh' => $machine,
  574. 'sczl_bzdh' => ['like',$team.'%'],
  575. 'sczl_rq' => $time,
  576. ];
  577. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_num) as 流程单号,rtrim(sczl_dedh) as dedh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as 标牌号,rtrim(sczl_cl) as 产量,
  578. rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
  579. rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
  580. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
  581. rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2,rtrim(UniqId) as UniqId,rtrim(sczl_bh98) as 拉料,rtrim(sczl_ls) as ls';
  582. $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
  583. if (!empty($list)){
  584. foreach ($list as $k=>$v){
  585. $name = \db('工单_印件资料')->where('Yj_Gdbh',$v['工单编号'])->where('yj_Yjno',$v['yjno'])->field('rtrim(yj_yjmc) as cpmc')->find();
  586. if ($v['yjno']<10){
  587. $list[$k]['yjno'] = '0'.$v['yjno'];
  588. }
  589. if (!empty($v['拉料'])){
  590. $list[$k]['拉料姓名'] = \db('人事_基本资料')->where('员工编号',$v['拉料'])->value('rtrim(员工姓名) as 员工姓名');
  591. }
  592. if (isset($list[$k]['拉料姓名']) === false){
  593. $list[$k]['拉料姓名'] = '';
  594. }
  595. $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
  596. $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
  597. $list[$k]['产品名称'] = $name['cpmc'];
  598. }
  599. $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
  600. SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
  601. SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
  602. SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
  603. $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
  604. $total[0]['版数'] = count($list);
  605. $list['total'] = $total[0];
  606. }
  607. $this->success('成功',$list);
  608. }
  609. /**
  610. * 检验记录
  611. * @ApiMethod (GET)
  612. * @param string $machine 机台编号
  613. * @param string $workOrder 工单编号
  614. * @param string $team 班次
  615. * @return void
  616. * @throws \think\db\exception\DataNotFoundException
  617. * @throws \think\db\exception\ModelNotFoundException
  618. * @throws \think\exception\DbException
  619. */
  620. public function InspectionRecord()
  621. {
  622. if ($this->request->isGet() === false){
  623. $this->error('请求失败');
  624. }
  625. $machine = input('machine');
  626. $workOrder = input('Gd_gdbh');
  627. $team = input('team');
  628. if (empty($machine) || empty($workOrder) || empty($team)){
  629. $this->success('');
  630. }
  631. $where = [
  632. '设备编号' => $machine,
  633. '工单编号' => $workOrder,
  634. '班组编号' => $team,
  635. '类别' => ['in',['IPQC检验','机台检验']],
  636. ];
  637. //检验项目筛选
  638. $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
  639. //检验时间
  640. $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  641. foreach ($InspectionTime as $k=>$v){
  642. $InspectionTime[$k] = date('H:i',strtotime($v));
  643. }
  644. //检测记录详情
  645. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  646. $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
  647. $data = [];
  648. //检测数据
  649. foreach ($item as $key=>$value){
  650. $SubmissionTime = \db('制程检验_记录')->where($where)
  651. ->where('检验项目',$value)
  652. ->where('检验结果','合格')
  653. ->field('rtrim(提交时间) as 提交时间')
  654. ->select();
  655. $time = [];
  656. foreach ($SubmissionTime as $k=>$v){
  657. $time[$k] = date('H:i',strtotime($v['提交时间']));
  658. }
  659. $data[$key] = [
  660. '工单编号' => $nameDetail['工单编号'],
  661. '印件号' => $nameDetail['印件号'],
  662. '工序名称' => $nameDetail['工序名称'],
  663. '检验项目' => $value,
  664. 'inspectresult' => implode(',',$time),
  665. ];
  666. }
  667. $data['inspectiontime'] = $InspectionTime;
  668. $this->success('成功',$data);
  669. }
  670. /**
  671. * 班组维护->班组添加
  672. * @ApiMethod (GET)
  673. * @param void
  674. * @return void
  675. * @throws \think\db\exception\DataNotFoundException
  676. * @throws \think\db\exception\ModelNotFoundException
  677. * @throws \think\exception\DbException
  678. */
  679. public function MachineTeamAdd()
  680. {
  681. if (Request::instance()->isPost() === false ){
  682. $this->error('请求错误');
  683. }
  684. $param = Request::instance()->post();
  685. if (empty($param)){
  686. $this->error('参数错误');
  687. }
  688. $lastId = \db('设备_班组资料')
  689. ->order('UniqId desc')
  690. ->value('UniqId');
  691. if (empty($lastId)){
  692. $lastId = 0;
  693. }
  694. for($i=1;$i<11;$i++){
  695. if (!empty($param['sczl_bh'.$i])){
  696. $name = \db('人事_基本资料')->where('员工编号',$param['sczl_bh'.$i])->value('员工编号');
  697. if (empty($name)){
  698. $this->error('未找到编号'.$param['sczl_bh'.$i].'员工信息,无法添加,请输入正确的员工编号');
  699. }
  700. }
  701. }
  702. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  703. $param['UniqId'] = $lastId + 1;
  704. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  705. $sql = \db('设备_班组资料')->fetchSql(true)->insert($param);
  706. $res = \db()->query($sql);
  707. if ($res !== false){
  708. $this->success('成功');
  709. }else{
  710. $this->error('失败');
  711. }
  712. }
  713. /**
  714. * 机台编号列表
  715. * @ApiMethod (GET)
  716. * @return void
  717. */
  718. public function MachineList()
  719. {
  720. if ($this->request->isGet() === false){
  721. $this->error('请求错误');
  722. }
  723. $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  724. if (empty($list)){
  725. $this->success('未找到机台编号');
  726. }
  727. $data = [];
  728. foreach ($list as $key=>$value){
  729. $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
  730. }
  731. $this->success('成功',$data);
  732. }
  733. /**
  734. * 删除班组信息
  735. * @ApiMethod (GET)
  736. * @param void
  737. * @return void
  738. * @throws \think\Exception
  739. * @throws \think\exception\PDOException
  740. */
  741. public function teamDel()
  742. {
  743. if (Request::instance()->isPost() === false){
  744. $this->error('请求错误');
  745. }
  746. $param = Request::instance()->post();
  747. if (empty($param)){
  748. $this->error('参数错误');
  749. }
  750. $machine = \db('设备_班组资料')
  751. ->where('UniqId',$param['UniqId'])
  752. ->value('sczl_jtbh');
  753. $teamId = \db('设备_产量采集')
  754. ->where('设备编号',$machine)
  755. ->order('UniqId desc')
  756. ->value('班组ID');
  757. if ($teamId === (int)$param['UniqId']){
  758. $this->success('无法删除正在生产的班组资料,请先切换班组');
  759. }
  760. $res = \db('设备_班组资料')
  761. ->where('UniqId',$param['UniqId'])
  762. ->delete();
  763. if ($res !== false){
  764. $this->success('成功');
  765. }else{
  766. $this->error('失败');
  767. }
  768. }
  769. /**
  770. * 管理人员现场巡检记录->展示
  771. * @ApiMethod (GET)
  772. * @param void
  773. * @return void
  774. * @throws \think\db\exception\DataNotFoundException
  775. * @throws \think\db\exception\ModelNotFoundException
  776. * @throws \think\exception\DbException
  777. */
  778. public function FieldInspectionRecord()
  779. {
  780. if ($this->request->isGet() === false){
  781. $this->error('请求错误');
  782. }
  783. $param = $this->request->param();
  784. if (empty($param)){
  785. $this->error('参数错误');
  786. }
  787. // $date = date('Y-m-d H:i:s',time());
  788. // if (empty($param['start'])){
  789. // $startTime = date('Y-m-d 08:30:00',time());
  790. // }else{
  791. // $startTime = date('Y-m-d H:i:s',strtotime($param['start']));
  792. // }
  793. // if ($date<$startTime){
  794. // $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  795. // }
  796. // 获取当前时间
  797. $current_time = time();
  798. // 设置时间范围
  799. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  800. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  801. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  802. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  803. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  804. // 判断当前时间属于哪个时间范围
  805. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  806. $startTime = date('Y-m-d') . ' 08:30:00';
  807. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  808. $startTime = date('Y-m-d') . ' 20:30:00';
  809. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  810. $startTime = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  811. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  812. $startTime = date('Y-m-d') . ' 20:30:00';
  813. }
  814. $where = [
  815. '工单编号' => $param['workOrder'],
  816. '开工时间' => $startTime,
  817. '类别' => '现场巡查记录',
  818. '班组编号' => ['like',substr($param['team'],0,1).'%']
  819. ];
  820. $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
  821. rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
  822. rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
  823. $list = \db('制程检验_记录')->where($where)
  824. ->field($filed)
  825. ->select();
  826. if (empty($list)){
  827. $this->success('',[]);
  828. }
  829. foreach ($list as $key=>$value){
  830. $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
  831. $list[$key]['归属时段'] = $value['开工时间'];
  832. $list[$key]['分钟差数'] = $number;
  833. if ($number != 0){
  834. $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
  835. }
  836. }
  837. $this->success('成功',$list);
  838. }
  839. /**
  840. * 管理人员现场巡检记录->添加
  841. * @ApiMethod (POST)
  842. * @param void
  843. * @return void
  844. */
  845. public function FieldInspectionRecordAdd()
  846. {
  847. if (Request::instance()->isPost() === false){
  848. $this->error('请求错误');
  849. }
  850. $param = Request::instance()->post();
  851. if (empty($param)){
  852. $this->error('参数错误');
  853. }
  854. if ($param['processCode']<10){
  855. $param['processCode'] = '0'.$param['processCode'];
  856. }
  857. $date = date('Y-m-d H:i:s',time());
  858. $startTime = date('Y-m-d 08:30:00',time());
  859. if ($date<$startTime){
  860. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  861. }
  862. $data = [
  863. '类别' => $param['category'],
  864. '工单编号' => $param['workOrder'],
  865. '印件号' => $param['printCode'],
  866. '工序名称' => $param['processCode'].'-'.$param['process'],
  867. '流程单号' => $param['flowCode'],
  868. '设备编号' => $param['machine'],
  869. '班组编号' => $param['team'],
  870. '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
  871. '相关标准' => '',
  872. '量测仪器' => '',
  873. '检验结果' => '',
  874. '检验备注' => $param['remark'],
  875. '提交时间' => date('Y-m-d H:i:s',time()),
  876. '开工时间' => $startTime,
  877. 'sys_id' => '',
  878. 'sys_rq' => date('Y-m-d H:i:s',time()),
  879. 'mod_rq' => '0000-00-00 00:00:00',
  880. 'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
  881. ];
  882. $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
  883. $res = Db::query($sql);
  884. if ($res !== false){
  885. $this->success('成功');
  886. }else{
  887. $this->error('失败');
  888. }
  889. }
  890. /**
  891. * 设备点检->左侧菜单栏
  892. * @ApiMethod (GET)
  893. * @param void
  894. * @return void
  895. */
  896. public function SpotCheckItem()
  897. {
  898. if ($this->request->isGet() === false){
  899. $this->error('请求错误');
  900. }
  901. $param = $this->request->param();
  902. if (empty($param)){
  903. $this->error('参数错误');
  904. }
  905. $list = \db('设备_点检项目')
  906. ->where('适用机型','LIKE','%;'.$param['machine'].';%')
  907. ->distinct(true)
  908. ->column('部件名称','部件编号');
  909. if (empty($list)){
  910. $this->success('');
  911. }
  912. $this->success('成功',$list);
  913. }
  914. /**
  915. * 设备点检->检测项目
  916. * @ApiMethod (GET)
  917. * @param void
  918. * @return void
  919. * @throws \think\db\exception\DataNotFoundException
  920. * @throws \think\db\exception\ModelNotFoundException
  921. * @throws \think\exception\DbException
  922. */
  923. public function InspectionItem()
  924. {
  925. if ($this->request->isGet() === false){
  926. $this->error('请求错误');
  927. }
  928. $param = $this->request->param();
  929. if (empty($param)){
  930. $this->error('参数错误');
  931. }
  932. $list = \db('设备_点检项目')
  933. ->where('部件名称',$param['unitName'])
  934. ->where('适用机型','like','%'.$param['machine'].'#%')
  935. ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
  936. ->select();
  937. if (empty($list)){
  938. $this->success('未找到检测项目');
  939. }
  940. $this->success('成功',$list);
  941. }
  942. /**
  943. * 设备点检->检测记录添加
  944. * @ApiMethod (POST)
  945. * @param void
  946. * @return void
  947. * @throws \think\db\exception\DataNotFoundException
  948. * @throws \think\db\exception\ModelNotFoundException
  949. * @throws \think\exception\DbException
  950. */
  951. public function InspectionItemAdd()
  952. {
  953. if (Request::instance()->isPost() === false){
  954. $this->error('请求错误');
  955. }
  956. $param = Request::instance()->post();
  957. if (empty($param)){
  958. $this->error('参数错误');
  959. }
  960. $lastNumber = \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
  961. if (empty($lastNumber)){
  962. $lastId = 0;
  963. }else{
  964. $lastId = $lastNumber;
  965. }
  966. $row = [];
  967. foreach ($param as $key=>$value){
  968. $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
  969. $row[$key] = [
  970. '日期' => date('Y-m-d 00:00:00',time()),
  971. '班组编号' => $value['team'],
  972. '点检设备' => $value['machine'],
  973. '部件编号' => $unitCode['部件编号'],
  974. '部件名称' => $value['unitName'],
  975. '检验项目' => $value['itemName'],
  976. '判定标准' => $value['standard'],
  977. '点检方法' => $value['method'],
  978. '点检结果' => $value['status'],
  979. '备注说明' => $value['remark'],
  980. 'Sys_id' =>'',
  981. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  982. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  983. 'Uniqid' => $lastId+$key+1
  984. ];
  985. }
  986. $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
  987. $res = Db::query($sql);
  988. if ($res !== false){
  989. $this->success('成功');
  990. }else{
  991. $this->error('失败');
  992. }
  993. }
  994. /**
  995. * 机台印版领用->左侧菜单
  996. * @ApiMethod (GET)
  997. * @param void
  998. * @return void
  999. */
  1000. public function PrintGetTab()
  1001. {
  1002. if ($this->request->isGet() === false){
  1003. $this->error('请求错误');
  1004. }
  1005. $param = $this->request->param();
  1006. if (empty($param)){
  1007. $this->error('参数错误');
  1008. }
  1009. $productCode = $param['productCode'];
  1010. $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
  1011. JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
  1012. WHERE a.YB_Cpdh = '{$productCode}'";
  1013. $res = Db::query($sql);
  1014. if (empty($res)){
  1015. $this->success('');
  1016. }
  1017. $this->success('成功',$res);
  1018. }
  1019. /**
  1020. * 机台印版领用记录->数据详情
  1021. * @ApiMethod (GET)
  1022. * @param void
  1023. * @return void
  1024. */
  1025. public function PrintDetail()
  1026. {
  1027. if (!$this->request->isGet()) {
  1028. $this->error('请求失败');
  1029. }
  1030. $param = $this->request->param();
  1031. if (empty($param)) {
  1032. $this->error('参数错误');
  1033. }
  1034. // 分页参数(带默认值)
  1035. $page = isset($param['page']) ? max(1, intval($param['page'])) : 1;
  1036. $limit = isset($param['limit']) ? min(max(1, intval($param['limit'])), 100) : 10;
  1037. $productCode = $param['productCode'];
  1038. $code = $param['code'] . '%';
  1039. $workOrder = $param['workOrder'];
  1040. // 1. 先查询总数
  1041. $countSql = "SELECT COUNT(*) AS total FROM (
  1042. SELECT
  1043. b.`供方批号`
  1044. FROM `产品_印版资料` a
  1045. JOIN `物料_存货编码` c ON c.`物料代码` = a.`存货编码`
  1046. JOIN `物料_存货结构` e ON e.`编号` = (
  1047. CASE
  1048. WHEN a.`存货编码` REGEXP '[A-Za-z]'
  1049. THEN SUBSTRING(a.`存货编码`, 1, 5)
  1050. ELSE SUBSTRING(a.`存货编码`, 1, 4)
  1051. END
  1052. )
  1053. JOIN `工单_基本资料` f ON a.YB_Cpdh = f.Gd_cpdh
  1054. LEFT JOIN `产品_印版库` b ON b.`存货编码` = a.`存货编码`
  1055. AND b.`报废日期` = '1900-01-01 00:00:00'
  1056. LEFT JOIN `工单_印版领用记录` d ON d.`Yb_供方批号` = b.`供方批号`
  1057. AND d.`Yb_工单编号` IS NOT NULL
  1058. WHERE
  1059. a.YB_Cpdh = '{$productCode}'
  1060. AND a.`存货编码` LIKE '{$code}'
  1061. AND f.Gd_gdbh = '{$workOrder}'
  1062. GROUP BY
  1063. a.`存货编码`,
  1064. b.`供方批号`
  1065. ) AS t";
  1066. $total = Db::query($countSql)[0]['total'] ?? 0;
  1067. // 2. 查询分页数据
  1068. $dataSql = "SELECT
  1069. RTRIM(a.`存货编码`) AS `存货编码`,
  1070. RTRIM(c.`物料名称`) AS `存货名称`,
  1071. RTRIM(b.`印版名称`) AS `印版名称`,
  1072. RTRIM(b.`供方批号`) AS `供方批号`,
  1073. RTRIM(b.`制造日期`) AS `制造日期`,
  1074. SUM(d.`Yb_印数`) AS `印数`,
  1075. RTRIM(e.`名称`) AS `印版类别`,
  1076. SUBSTRING(a.YB_Cpdh, 1, 4) AS `客户编号`,
  1077. RTRIM(f.`Gd_客户名称`) AS `客户名称`,
  1078. RTRIM(a.YB_Cpdh) AS `产品编号`,
  1079. RTRIM(f.Gd_cpmc) AS `产品名称`,
  1080. MAX(d.UniqID) AS UniqId,
  1081. MAX(CASE
  1082. WHEN d.`Yb_领用日期` IS NOT NULL AND d.`Yb_退还日期` IS NULL
  1083. THEN d.`Yb_工单编号`
  1084. ELSE NULL
  1085. END) AS `工单编号`
  1086. FROM `产品_印版资料` a
  1087. JOIN `物料_存货编码` c ON c.`物料代码` = a.`存货编码`
  1088. JOIN `物料_存货结构` e ON e.`编号` = (
  1089. CASE
  1090. WHEN a.`存货编码` REGEXP '[A-Za-z]'
  1091. THEN SUBSTRING(a.`存货编码`, 1, 5)
  1092. ELSE SUBSTRING(a.`存货编码`, 1, 4)
  1093. END
  1094. )
  1095. JOIN `工单_基本资料` f ON a.YB_Cpdh = f.Gd_cpdh
  1096. LEFT JOIN `产品_印版库` b ON b.`存货编码` = a.`存货编码`
  1097. AND b.`报废日期` = '1900-01-01 00:00:00'
  1098. LEFT JOIN `工单_印版领用记录` d ON d.`Yb_供方批号` = b.`供方批号`
  1099. AND d.`Yb_工单编号` IS NOT NULL
  1100. WHERE
  1101. a.YB_Cpdh = '{$productCode}'
  1102. AND a.`存货编码` LIKE '{$code}'
  1103. AND f.Gd_gdbh = '{$workOrder}'
  1104. GROUP BY
  1105. a.`存货编码`,
  1106. c.`物料名称`,
  1107. b.`印版名称`,
  1108. b.`供方批号`,
  1109. b.`制造日期`,
  1110. e.`名称`,
  1111. f.`Gd_客户名称`,
  1112. a.YB_Cpdh,
  1113. f.Gd_cpmc
  1114. ORDER BY a.`存货编码`
  1115. LIMIT " . ($page - 1) * $limit . ", " . $limit;
  1116. $list = Db::query($dataSql);
  1117. $this->success('成功', [
  1118. 'data' => $list ?: [],
  1119. 'total' => $total,
  1120. ]);
  1121. }
  1122. /**
  1123. * 换型清场->左侧菜单栏
  1124. * @ApiMethod (GET)
  1125. * @param void
  1126. * @return void
  1127. */
  1128. public function remodelGetTab()
  1129. {
  1130. if ($this->request->isGet() === false){
  1131. $this->error('请求错误');
  1132. }
  1133. $date = date('Y-m-d 00:00:00',time()-3456000);
  1134. $nowTime = date('Y-m-d H:i:s',time());
  1135. $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
  1136. if (empty($list)){
  1137. $this->error('失败');
  1138. }
  1139. $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId
  1140. FROM `设备_基本资料` as a
  1141. LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
  1142. WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' AND b.`工单编号A` <> '' AND b.`工单编号B` <> '' ORDER BY b.`UniqId`";
  1143. $res = Db::query($sql);
  1144. $data = $result = [];
  1145. foreach ($list as $key=>$value){
  1146. $data[$value] = $result[$value]= $time = [];
  1147. foreach ($res as $k=>$v){
  1148. if ($value === $v['设备编号']){
  1149. $row = [
  1150. '日期' => $v['日期'],
  1151. 'id' => $v['UniqId']
  1152. ];
  1153. array_push($data[$value],$row);
  1154. }
  1155. }
  1156. foreach ($data[$value] as $m=>$n){
  1157. $time[$m] = $n['日期'];
  1158. }
  1159. $time = array_values(array_unique($time));
  1160. foreach ($time as $kk=>$vv){
  1161. $i=1;
  1162. foreach ($data[$value] as $kkk=>$vvv){
  1163. if ($kkk>=$kk && $vv === $vvv['日期']){
  1164. array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
  1165. $i++;
  1166. }
  1167. }
  1168. }
  1169. }
  1170. $this->success('成功',$result);
  1171. }
  1172. /**
  1173. * 换型清场->详情
  1174. * @return void
  1175. * @throws \think\db\exception\DataNotFoundException
  1176. * @throws \think\db\exception\ModelNotFoundException
  1177. * @throws \think\exception\DbException
  1178. */
  1179. public function RemodelDetail()
  1180. {
  1181. if ($this->request->isGet() === false){
  1182. $this->error('请求错误');
  1183. }
  1184. $param = $this->request->param();
  1185. if (empty($param)){
  1186. $this->error('参数错误');
  1187. }
  1188. $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1189. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
  1190. rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
  1191. rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
  1192. $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
  1193. if (empty($list)){
  1194. $this->success('未找到该条清场记录');
  1195. }
  1196. $list['日期'] = date('Y-m-d',strtotime($list['日期']));
  1197. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1198. if (empty($printNameA)){
  1199. $list['印件名称A'] = '';
  1200. }else{
  1201. $list['印件名称A'] = $printNameA['yjmc'];
  1202. }
  1203. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1204. if (empty($printNameB)){
  1205. $list['印件名称B'] = '';
  1206. }else{
  1207. $list['印件名称B'] = $printNameB['yjmc'];
  1208. }
  1209. $this->success('成功',$list);
  1210. }
  1211. /**
  1212. * 换型清场->当前设备清场记录
  1213. * @ApiMethod (GET)
  1214. * @param void
  1215. * @return void
  1216. * @throws \think\db\exception\DataNotFoundException
  1217. * @throws \think\db\exception\ModelNotFoundException
  1218. * @throws \think\exception\DbException
  1219. */
  1220. public function ModelChangeRecord()
  1221. {
  1222. if ($this->request->isGet() === false){
  1223. $this->error('请求错误');
  1224. }
  1225. $param = $this->request->param();
  1226. if (empty($param)){
  1227. $this->error('参数错误');
  1228. }
  1229. $date = date('Y-m-d 00:00:00',time()-3888000);
  1230. $nowTime = date('Y-m-d H:i:s',time());
  1231. $where = [
  1232. '日期' =>['between',[$date,$nowTime]],
  1233. '机台编号' => $param['machine'],
  1234. '工单编号A' => ['<>',''],
  1235. '工单编号B' => ['<>',''],
  1236. ];
  1237. $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1238. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
  1239. rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
  1240. rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_rq) as 创建时间,rtrim(UniqId) as UNIQID";
  1241. $list = \db('制程_换型清场')
  1242. ->where($where)
  1243. ->field($field)
  1244. ->select();
  1245. if (empty($list)){
  1246. $this->success('未找到换型记录');
  1247. }
  1248. foreach ($list as $key=>$value){
  1249. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->value('rtrim(yj_yjmc) as yjmc');
  1250. if (empty($printNameA)){
  1251. $list[$key]['印件名称A'] = '';
  1252. }else{
  1253. $list[$key]['印件名称A'] = $printNameA;
  1254. }
  1255. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->value('rtrim(yj_yjmc) as yjmc');
  1256. if (empty($printNameB)){
  1257. $list[$key]['印件名称B'] = '';
  1258. }else{
  1259. $list[$key]['印件名称B'] = $printNameB;
  1260. }
  1261. }
  1262. $this->success('成功',$list);
  1263. }
  1264. /**
  1265. * 车间机台状态列表展示
  1266. * @ApiMethod (GET)
  1267. * @param void
  1268. * @return void
  1269. * @throws \think\db\exception\BindParamException
  1270. * @throws \think\exception\PDOException
  1271. */
  1272. public function MachineDetailList()
  1273. {
  1274. if ($this->request->isGet() === false){
  1275. $this->error('请求错误');
  1276. }
  1277. $param = $this->request->param();
  1278. if (empty($param)){
  1279. $this->error('参数错误');
  1280. }
  1281. $workshop = $param['workshop'];
  1282. $sql = "SELECT
  1283. RTRIM( a.`设备编号` ) AS 设备编号,
  1284. RTRIM( a.`设备名称` ) AS 设备名称,
  1285. RTRIM( d.`当前状态` ) AS 状态
  1286. FROM
  1287. `设备_基本资料` AS a
  1288. JOIN (
  1289. SELECT
  1290. b.`设备编号`,
  1291. b.`当前状态`,
  1292. b.`开工时间`
  1293. FROM
  1294. `设备_产量采集` AS b
  1295. JOIN ( SELECT `设备编号`, MAX( `UniqId` ) AS `UniqId` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号`
  1296. AND b.`UniqId` = c.`UniqId`
  1297. ) AS d ON a.`设备编号` = d.`设备编号`
  1298. WHERE
  1299. a.`使用部门` = '{$workshop}'
  1300. GROUP BY
  1301. a.`设备编号`
  1302. ORDER BY
  1303. a.UniqId";
  1304. $list = \db()->query($sql);
  1305. foreach ($list as $key=>$value){
  1306. if ($value['状态'] == ''){
  1307. $list[$key]['状态'] = '待单';
  1308. }
  1309. }
  1310. $this->success('成功',$list);
  1311. }
  1312. /**
  1313. * 机台当前参数展示
  1314. * @ApiMethod (GET)
  1315. * @return void
  1316. * @throws \think\db\exception\DataNotFoundException
  1317. * @throws \think\db\exception\ModelNotFoundException
  1318. * @throws \think\exception\DbException
  1319. */
  1320. public function MachineDetail()
  1321. {
  1322. if ($this->request->isGet() === false){
  1323. $this->error('请求错误');
  1324. }
  1325. $param = $this->request->param();
  1326. if (empty($param)){
  1327. $this->error('参数错误');
  1328. }
  1329. $data = [];
  1330. if ($param['start'] === ''){
  1331. if (date('Y-m-d H:i:s')>date('Y-m-d 08:30:00',time()) && date('Y-m-d H:i:s')<date('Y-m-d 20:30:00',time())){
  1332. $param['start'] = date('Y-m-d 08:30:00',time());
  1333. }elseif (date('Y-m-d H:i:s')>date('Y-m-d 20:30:00',time()) && date('Y-m-d H:i:s')<date('Y-m-d 23:59:59',time())){
  1334. $param['start'] = date('Y-m-d 20:30:00',time());
  1335. }else{
  1336. $param['start'] = date('Y-m-d 20:30:00',time()-86400);
  1337. }
  1338. }
  1339. $machineDetail = \db('设备_产量采集')
  1340. ->alias('a')
  1341. ->join('设备_基本资料 b','a.设备编号 = b.设备编号')
  1342. ->join('工单_工艺资料 c', "a.工单编号 = c.Gy0_gdbh AND c.Gy0_sbbh LIKE CONCAT('%', a.设备编号, '%')")
  1343. ->join('工单_基本资料 d','a.工单编号 = d.Gd_gdbh')
  1344. ->field([
  1345. 'rtrim(a.开工时间)' => '开工时间',
  1346. 'rtrim(a.设备编号)' => '设备编号',
  1347. 'rtrim(a.工单编号)' => '工单编号',
  1348. 'rtrim(b.设备名称)' => '设备名称',
  1349. 'rtrim(c.Gy0_gxh)' => '工序号',
  1350. 'rtrim(c.Gy0_gxmc)' => '工序名称',
  1351. 'rtrim(d.Gd_cpmc)' => '产品名称'
  1352. ])
  1353. ->where('a.设备编号', $param['machine'])
  1354. ->order('a.UniqId desc')
  1355. ->find();
  1356. $data['machine'] = [
  1357. '日期' => $machineDetail['开工时间'],
  1358. '设备' => $machineDetail['设备编号'].'-->'.$machineDetail['设备名称'],
  1359. '工单' => $machineDetail['工单编号'].'-->'.$machineDetail['产品名称'],
  1360. '工艺' => ($machineDetail['工序号']<10?'0'.$machineDetail['工序号']:$machineDetail['工序号']).'--'.$machineDetail['工序名称']
  1361. ];
  1362. //机台状态时间
  1363. $startTime = \db('设备_产量采集')
  1364. ->where('设备编号',$param['machine'])
  1365. ->where('开工时间',$param['start'])
  1366. ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
  1367. ->group('当前状态')
  1368. ->select();
  1369. if (!empty($startTime)){
  1370. foreach ($startTime as $key=>$value){
  1371. $data['timeDifference'][$key] = [
  1372. '时间' => round((strtotime($value['最大时间'])-strtotime($value['时间']))/3600,2),
  1373. '状态' => $value['状态'] = null?'待单':$value['状态'],
  1374. ];
  1375. if ($value['状态'] === '生产'){
  1376. $data['当班产量'] = $value['最大产量']-$value['当班产量'];
  1377. }
  1378. }
  1379. }else{
  1380. $data['timeDifference'][0] = [
  1381. '时间' => 0,
  1382. '状态' => '待单'
  1383. ];
  1384. $data['当班产量'] = 0;
  1385. }
  1386. //机台产能/时间明细
  1387. $row = \db('设备_产量采集')
  1388. ->where('设备编号',$param['machine'])
  1389. ->where('开工时间',$param['start'])
  1390. ->where('当班产量','<>',-1)
  1391. ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
  1392. ->select();
  1393. if (empty($row)){
  1394. $data['row'] = [];
  1395. }
  1396. foreach ($row as $key=>$value){
  1397. $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
  1398. $data['row'][$key]['状态'] = $value['状态'];
  1399. if ($key<2){
  1400. $data['row'][$key]['产能'] = 0;
  1401. }else{
  1402. $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
  1403. }
  1404. }
  1405. //机台状态
  1406. $status = end($row);
  1407. if (empty($status['状态'])){
  1408. $data['status'] = '待单';
  1409. }else{
  1410. $data['status'] = $status['状态'];
  1411. }
  1412. //检验数据
  1413. $list = \db('制程检验_记录')
  1414. ->where('开工时间',$param['start'])
  1415. ->where('设备编号',$param['machine'])
  1416. ->where('sys_rq','>',$param['start'])
  1417. ->where('工单编号',$machineDetail['工单编号'])
  1418. ->field('rtrim(类别) as 类别,提交时间')
  1419. ->select();
  1420. $data['首件'] = $data['自检'] = $data['IPQC'] = [];
  1421. if (!empty($list)){
  1422. foreach ($list as $key=>$value){
  1423. if ($value['类别'] == '首件与过程确认'){
  1424. array_push($data['首件'],$value['提交时间']);
  1425. }
  1426. if ($value['类别'] == '机台检验'){
  1427. array_push($data['自检'],$value['提交时间']);
  1428. }
  1429. if ($value['类别'] == 'IPQC检验'){
  1430. array_push($data['IPQC'],$value['提交时间']);
  1431. }
  1432. }
  1433. $data['首件'] = array_values(array_unique($data['首件']));
  1434. $data['自检'] = array_values(array_unique($data['自检']));
  1435. $data['IPQC'] = array_values(array_unique($data['IPQC']));
  1436. }else{
  1437. $data['首件'] = [];
  1438. $data['自检'] = [];
  1439. $data['IPQC'] = [];
  1440. }
  1441. $this->success('成功',$data);
  1442. }
  1443. /**
  1444. * 制程检验记录->检验项目
  1445. * @ApiMethod (GET)
  1446. * @param void
  1447. * @return void
  1448. * @throws \think\db\exception\DataNotFoundException
  1449. * @throws \think\db\exception\ModelNotFoundException
  1450. * @throws \think\exception\DbException
  1451. */
  1452. public function ProcessInspectionRecordsItem()
  1453. {
  1454. if ($this->request->isGet() === false){
  1455. $this->error('请求错误');
  1456. }
  1457. $param = $this->request->param();
  1458. if (empty($param)){
  1459. $this->error('参数错误');
  1460. }
  1461. $list = \db('制程检验_项目')
  1462. ->where('工序','like','%'.$param['process'].'%')
  1463. ->select();
  1464. if (empty($list)){
  1465. $this->success('未找到检测项目');
  1466. }
  1467. $data = [];
  1468. foreach ($list as $key=>$value){
  1469. $data['首件']['指标检验'][$key] = [
  1470. '检验项目' => rtrim($value['检测项目']),
  1471. '检测方法' => rtrim($value['检测方法']),
  1472. '检验频率' => rtrim($value['首件签样要求']),
  1473. '相关标准' => rtrim($value['技术要求'])
  1474. ];
  1475. $data['机台检验']['指标检验'][$key] = [
  1476. '检验项目' => rtrim($value['检测项目']),
  1477. '检测方法' => rtrim($value['检测方法']),
  1478. '检验频率' => rtrim($value['机台自检频率']),
  1479. '相关标准' => rtrim($value['技术要求'])
  1480. ];
  1481. $data['IPQC']['指标检验'][$key] = [
  1482. '检验项目' => rtrim($value['检测项目']),
  1483. '检测方法' => rtrim($value['检测方法']),
  1484. '检验频率' => rtrim($value['IPQC检验频率']),
  1485. '相关标准' => rtrim($value['技术要求'])
  1486. ];
  1487. }
  1488. $row = \db('制程检验_项目附加')
  1489. ->where('工序','like','%'.$param['process'].'%')
  1490. ->select();
  1491. foreach ($row as $key=>$value){
  1492. $data['首件']['附加'][$key] = [
  1493. '缺陷备注' => rtrim($value['缺陷备注']),
  1494. '编号' => rtrim($value['编号'])
  1495. ];
  1496. $data['机台检验']['附加'][$key] = [
  1497. '缺陷备注' => rtrim($value['缺陷备注']),
  1498. '编号' => rtrim($value['编号'])
  1499. ];
  1500. $data['IPQC']['附加'][$key] = [
  1501. '缺陷备注' => rtrim($value['缺陷备注']),
  1502. '编号' => rtrim($value['编号'])
  1503. ];
  1504. }
  1505. $this->success('成功',$data);
  1506. }
  1507. /**
  1508. * 车间报工
  1509. * 制程检验记录->检测记录添加
  1510. */
  1511. public function ProcessInspectionRecordsItemAdd(){
  1512. if (Request::instance()->isPost() === false){
  1513. $this->error('请求错误');
  1514. }
  1515. $param = Request::instance()->post();
  1516. if (empty($param)){
  1517. $this->error('参数错误');
  1518. }
  1519. $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
  1520. if (empty($startID)){
  1521. $startID = 0;
  1522. }
  1523. $process = \db('工单_工艺资料')
  1524. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1525. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1526. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1527. ->find();
  1528. $startTime = \db('设备_产量采集')
  1529. ->where('设备编号', 'like', '%' . $param[0]['machine'] . '#%')
  1530. ->where('工单编号', $param[0]['workOrder'])
  1531. ->order('UniqId desc')
  1532. ->find();
  1533. // 解决车间因未更换班组,导致开工时间仍为前一个班次,导致下一个班组进行上报时数据录到了前一个班次中的问题
  1534. if (!$startTime) {
  1535. $this->error('未找到对应的开工时间');
  1536. }
  1537. /*
  1538. * 系统提交时间(应报工时间)和开工时间
  1539. */
  1540. // $startTime = $startTime['开工时间'];
  1541. $rqTime = isset($param[0]['rq']) ? $param[0]['rq'] : date('Y-m-d H:i:s');
  1542. //转换为时间戳
  1543. $rqTimestamp = strtotime($rqTime);
  1544. $startTimestamp = strtotime($startTime['开工时间']);
  1545. // 计算时间差(秒)
  1546. $timeDiff = abs($rqTimestamp - $startTimestamp); // 取绝对值,防止负数
  1547. /*
  1548. * 计算时间差
  1549. */
  1550. // 转换时间差为 天、小时、分钟、秒
  1551. $days = floor($timeDiff / 86400);
  1552. $hours = floor(($timeDiff % 86400) / 3600);
  1553. $minutes = floor(($timeDiff % 3600) / 60);
  1554. $seconds = $timeDiff % 60;
  1555. // 格式化时间差
  1556. $formattedDiff = "";
  1557. if ($days > 0) $formattedDiff .= $days . "天";
  1558. if ($hours > 0) $formattedDiff .= $hours . "小时";
  1559. if ($minutes > 0) $formattedDiff .= $minutes . "分钟";
  1560. if ($seconds > 0) $formattedDiff .= $seconds . "秒";
  1561. //测试进行时间比较,查看时间判断是否正确
  1562. // echo "<pre>";
  1563. // print_r("系统提交时间:" .$rqTime);
  1564. // print_r("\n当前开工时间:" . $startTime);
  1565. // print_r("\n时间差:" . $formattedDiff);
  1566. // echo "<pre>";
  1567. // 判断是否超过 12 小时(12 * 3600 = 43200 秒)
  1568. if ($timeDiff > 43200) {
  1569. $this->error('请先更换班组后,再提交数据');
  1570. }
  1571. if ((int)$process['gxh']<10){
  1572. $process['gxh'] = '0'.$process['gxh'];
  1573. }
  1574. if ($process['add_gxmc'] !== ''){
  1575. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1576. }else{
  1577. $printName = $process['gxh'].'-'.$process['gxmc'];
  1578. }
  1579. if (empty($process)){
  1580. $this->success('数据错误');
  1581. }
  1582. $data = [];
  1583. foreach ($param as $key=>$value){
  1584. $data[$key] = [
  1585. '类别' => $value['category'],
  1586. '工单编号' => $value['workOrder'],
  1587. '印件号' => $value['yjno'],
  1588. '工序名称' => $printName,
  1589. '流程单号' => $value['flow'],
  1590. '设备编号' => $value['machine'].'#',
  1591. '班组编号' => $startTime['班组编号'],
  1592. '检验项目' => $value['item'],
  1593. '相关标准' => $value['standard'],
  1594. '量测仪器' => $value['instrument'],
  1595. '检验结果' => $value['selected'],
  1596. '检验备注' => $value['remark'],
  1597. '提交时间' => date('Y-m-d H:i:s',time()),
  1598. '开工时间' => rtrim($startTime['开工时间']),
  1599. 'sys_id' => '',
  1600. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1601. 'mod_rq' => '0000-00-00 00:00:00',
  1602. 'UniqId' => $startID + $key +1
  1603. ];
  1604. }
  1605. $res = \db('制程检验_记录')->insertAll($data);
  1606. if ($res !== false){
  1607. $this->success('成功');
  1608. }else{
  1609. $this->error('失败');
  1610. }
  1611. }
  1612. /**
  1613. * 制程检验记录->附加检验记录添加
  1614. * @ApiMethod (POST)
  1615. * @param void
  1616. * @return void
  1617. * @throws \think\db\exception\DataNotFoundException
  1618. * @throws \think\db\exception\ModelNotFoundException
  1619. * @throws \think\exception\DbException
  1620. */
  1621. public function AdditionalInspectionRecordAdd()
  1622. {
  1623. if (Request::instance()->isPost() === false){
  1624. $this->error('请求错误');
  1625. }
  1626. $param = Request::instance()->post();
  1627. if (empty($param)){
  1628. $this->error('参数错误');
  1629. }
  1630. $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
  1631. if (empty($startID)){
  1632. $startID = 0;
  1633. }
  1634. $process = \db('工单_工艺资料')
  1635. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1636. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1637. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1638. ->find();
  1639. $startTime = \db('设备_产量采集')
  1640. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1641. ->where('工单编号',$param[0]['workOrder'])
  1642. ->order('UniqId desc')
  1643. ->find();
  1644. if ((int)$process['gxh']<10){
  1645. $process['gxh'] = '0'.$process['gxh'];
  1646. }
  1647. if ($process['add_gxmc'] !== ''){
  1648. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1649. }else{
  1650. $printName = $process['gxh'].'-'.$process['gxmc'];
  1651. }
  1652. if (empty($process)){
  1653. $this->success('数据错误');
  1654. }
  1655. $data = [];
  1656. foreach ($param as $key=>$value){
  1657. $data[$key] = [
  1658. '工单编号' => $value['workOrder'],
  1659. '印件号' => $value['yjno'],
  1660. '工序名称' => $printName,
  1661. '流程单号' => $value['flow'],
  1662. '设备编号' => $value['machine'],
  1663. '班组编号' => $startTime['班组编号'],
  1664. '缺陷备注' => $value['remark'],
  1665. '提交时间' => date('Y-m-d H:i:s',time()),
  1666. '开工时间' => rtrim($startTime['开工时间']),
  1667. 'sys_id' => '',
  1668. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1669. 'mod_rq' => '0000-00-00 00:00:00',
  1670. 'UniqId' => $startID + $key +1
  1671. ];
  1672. }
  1673. $res = \db('制程检验_记录附加')->insertAll($data);
  1674. if ($res !== false){
  1675. $this->success('成功');
  1676. }else{
  1677. $this->error('失败');
  1678. }
  1679. }
  1680. /**
  1681. * 客诉记录
  1682. * @ApiMethod (GET)
  1683. * @param void
  1684. * @return void
  1685. * @throws \think\db\exception\DataNotFoundException
  1686. * @throws \think\db\exception\ModelNotFoundException
  1687. * @throws \think\exception\DbException
  1688. */
  1689. public function ComplaintRecord()
  1690. {
  1691. if ($this->request->isGet() === false){
  1692. $this->error('请求错误');
  1693. }
  1694. $param = $this->request->param();
  1695. if (isset($param['productCode'])){
  1696. $where['产品编号'] = $param['productCode'];
  1697. }
  1698. $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
  1699. rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
  1700. rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
  1701. rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
  1702. $list = \db('db_客诉记录')
  1703. ->where($where)
  1704. ->field($filed)
  1705. ->select();
  1706. if (empty($list)){
  1707. $this->success('未找到该产品客诉记录');
  1708. }
  1709. $this->success('成功',$list);
  1710. }
  1711. /**
  1712. * 设置机台班组信息
  1713. * @return void
  1714. * @throws \think\db\exception\DataNotFoundException
  1715. * @throws \think\db\exception\ModelNotFoundException
  1716. * @throws \think\exception\DbException
  1717. */
  1718. public function setMachineTeam()
  1719. {
  1720. if (Request::instance()->isPost() == false) {
  1721. $this->error('非法请求');
  1722. }
  1723. $params = Request::instance()->post();
  1724. if (!isset($params['machine']) || empty($params['machine'] )) {
  1725. $this->error('参数不能为空');
  1726. }
  1727. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  1728. $this->error('请先选择班组成员');
  1729. }
  1730. $machine = $params['machine'] . '#';
  1731. $data = [];
  1732. $lastData = \db('设备_产量采集')
  1733. ->order('UniqId desc')
  1734. ->find();
  1735. $id = $lastData['UniqId']+1;
  1736. $data['当前状态'] = $params['status'];
  1737. $data['时间'] = date('Y-m-d H:i:s');
  1738. $data['设备编号'] = $machine;
  1739. $data['工单编号'] = empty($params['order']) ? '':$params['order'];
  1740. $data['印件号'] = empty($params['yjno']) ? '':$params['yjno'];
  1741. $data['工序号'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  1742. $data['工序名称'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  1743. $data['当班产量'] = $params['production_now'];
  1744. $data['累计产量'] = $params['production_all'];
  1745. $data['班组编号'] = $params['sczl_bzdh'];
  1746. $data['班组ID'] = $params['team_id'];
  1747. // 获取当前时间
  1748. $current_time = time();
  1749. // 设置时间范围
  1750. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  1751. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  1752. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  1753. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  1754. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  1755. // 判断当前时间属于哪个时间范围
  1756. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  1757. $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
  1758. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  1759. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1760. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  1761. $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  1762. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  1763. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1764. }
  1765. if (!empty($params['order']) && !empty($params['yjno'])){
  1766. $option['Gy0_gdbh'] = $params['order'];
  1767. $option['Gy0_yjno'] = $params['yjno'];
  1768. $option['Gy0_gxh'] = $data['工序号'];
  1769. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  1770. }else{
  1771. $data['任务ID'] = '';
  1772. }
  1773. $data['UniqId'] = $id;
  1774. $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
  1775. $res = Db::query($sql);
  1776. if ($res === false) {
  1777. $this->error('设置失败');
  1778. } else {
  1779. $this->success('设置成功');
  1780. }
  1781. }
  1782. /**
  1783. * 首页数据
  1784. * @return void
  1785. * @throws \think\Exception
  1786. * @throws \think\db\exception\DataNotFoundException
  1787. * @throws \think\db\exception\ModelNotFoundException
  1788. * @throws \think\exception\DbException
  1789. */
  1790. public function index()
  1791. {
  1792. if ($this->request->isGet() === false){
  1793. $this->error('请求错误');
  1794. }
  1795. $nowTime = date('Y-m-d H:i:s',time());
  1796. $oldTime = (date('Y')-1).'-'.date('m-d H:i:s');
  1797. $where =[
  1798. 'Mod_rq' => ['between',[$oldTime,$nowTime]],
  1799. '行号' => '1'
  1800. ];
  1801. $data = [];
  1802. //按状态查询工单信息
  1803. $orderList = \db('工单_基本资料')
  1804. ->where($where)
  1805. ->field('count(Gd_gdbh) as 数量,rtrim(gd_statu) as 状态')
  1806. ->group('gd_statu')
  1807. ->select();
  1808. foreach ($orderList as $value){
  1809. if ($value['状态'] === '1-已完工'){
  1810. $data['workOrderData']['已完工'] = $value['数量'];
  1811. }
  1812. if ($value['状态'] === '3-计划中'){
  1813. $data['workOrderData']['计划中'] = $value['数量'];
  1814. }
  1815. }
  1816. $data['workOrderData']['排程中'] = db('工单_基本资料')->alias('a')
  1817. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1818. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1819. ->where([
  1820. 'a.gd_statu' => '2-生产中',
  1821. 'a.行号' => '1',
  1822. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1823. 'b.PD_WG' => '1900-01-01 00:00:00',
  1824. 'b.Gy0_sj1' => '1900-01-01 00:00:00',
  1825. 'c.状态' => '',
  1826. ])
  1827. ->group('a.Gd_gdbh')
  1828. ->count();
  1829. $data['workOrderData']['制程中'] = db('工单_基本资料')->alias('a')
  1830. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1831. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1832. ->where([
  1833. 'a.gd_statu' => '2-生产中',
  1834. 'a.行号' => '1',
  1835. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1836. 'b.PD_WG' => '1900-01-01 00:00:00',
  1837. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  1838. 'c.状态' => '',
  1839. ])
  1840. ->group('a.Gd_gdbh')
  1841. ->count();
  1842. //按月份查询工单信息
  1843. $data['monthData'] = \db('工单_基本资料')
  1844. ->where('Mod_rq', 'between', [$oldTime, $nowTime])
  1845. ->field('DATE_FORMAT(Mod_rq, "%Y-%m") as month, COUNT(*) as count')
  1846. ->group('month')
  1847. ->order('month')
  1848. ->select();
  1849. //查询最近十条客诉信息
  1850. $data['customer'] = \db('db_客诉记录')
  1851. ->field('rtrim(客诉描述) as 客诉描述,DATE_FORMAT(客诉日期, "%Y-%m-%d") as 日期,rtrim(UniqID) as UniqId')
  1852. ->limit(10)
  1853. ->order('Sys_rq desc')
  1854. ->select();
  1855. $this->success('成功',$data);
  1856. }
  1857. /**
  1858. * 员工信息获取
  1859. * @return void
  1860. * @throws \think\db\exception\DataNotFoundException
  1861. * @throws \think\db\exception\ModelNotFoundException
  1862. * @throws \think\exception\DbException
  1863. */
  1864. public function EmployeeData()
  1865. {
  1866. if ($this->request->isGet() === false){
  1867. $this->error('请求错误');
  1868. }
  1869. $param = $this->request->param();
  1870. if (isset($param['code']) === false){
  1871. $this->error('参数错误');
  1872. }
  1873. $res = \db('人事_基本资料')
  1874. ->where('员工编号','like',$param['code'].'%')
  1875. ->field('rtrim(员工编号) as 员工编号,rtrim(员工姓名) as 员工姓名')
  1876. ->select();
  1877. if (empty($res)){
  1878. $this->success('未找到该员工');
  1879. }
  1880. $this->success('成功',$res);
  1881. }
  1882. /**
  1883. * 换型清场添加
  1884. * @return void
  1885. * @throws \think\db\exception\BindParamException
  1886. * @throws \think\exception\PDOException
  1887. */
  1888. public function remodelDataAdd()
  1889. {
  1890. if (Request::instance()->isPost() === false){
  1891. $this->error('请求错误');
  1892. }
  1893. $param = Request::instance()->post();
  1894. if (empty($param)){
  1895. $this->error('参数错误');
  1896. }
  1897. $lastId = \db('制程_换型清场')->order('UniqId desc')->value('UniqId');
  1898. $param['sys_id'] = '['.$param['机台编号'].']';
  1899. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  1900. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1901. $param['UniqId'] = $lastId + 1;
  1902. $sql = \db('制程_换型清场')->fetchSql(true)->insert($param);
  1903. $res = \db()->query($sql);
  1904. if ($res !== false){
  1905. $this->success('成功');
  1906. }else{
  1907. $this->error('失败');
  1908. }
  1909. }
  1910. /**
  1911. * 换型清场记录修改
  1912. * @return void
  1913. * @throws \think\Exception
  1914. * @throws \think\db\exception\BindParamException
  1915. * @throws \think\exception\PDOException
  1916. */
  1917. public function remodelDataEdit()
  1918. {
  1919. if (Request::instance()->isPost() === false){
  1920. $this->error('请求错误');
  1921. }
  1922. $param = Request::instance()->post();
  1923. if (empty($param)){
  1924. $this->error('参数错误');
  1925. }
  1926. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1927. $sql = \db('制程_换型清场')->fetchSql(true)->update($param);
  1928. $res = \db()->query($sql);
  1929. if ($res !== false){
  1930. $this->success('成功');
  1931. }else{
  1932. $this->error('失败');
  1933. }
  1934. }
  1935. /**
  1936. * 换型清场记录删除
  1937. * @return void
  1938. * @throws \think\Exception
  1939. * @throws \think\exception\PDOException
  1940. */
  1941. public function remodelDataDel()
  1942. {
  1943. if ($this->request->isGet() === false){
  1944. $this->error('请求错误');
  1945. }
  1946. $param = $this->request->param();
  1947. if (empty($param)){
  1948. $this->error('参数错误');
  1949. }
  1950. $res = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->delete();
  1951. if ($res !== false){
  1952. $this->success('删除成功');
  1953. }else{
  1954. $this->error('删除失败');
  1955. }
  1956. }
  1957. /**
  1958. * 印版领用记录添加
  1959. * @return void
  1960. * @throws \think\db\exception\BindParamException
  1961. * @throws \think\exception\PDOException
  1962. */
  1963. public function PrintDetailAdd()
  1964. {
  1965. if (Request::instance()->isPost() === false){
  1966. $this->error('请求错误');
  1967. }
  1968. $param = Request::instance()->post();
  1969. if (empty($param)){
  1970. $this->error('参数错误');
  1971. }
  1972. $lastId = \db('工单_印版领用记录')->order('UniqID desc')->value('UniqID');
  1973. foreach ($param as $key=>$value){
  1974. $param[$key]['Yb_领用日期'] = date('Y-m-d H:i:s',time());
  1975. $param[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  1976. $param[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  1977. }
  1978. $sql = \db('工单_印版领用记录')->fetchSql(true)->insertAll($param);
  1979. $res = \db()->query($sql);
  1980. if ($res !== false){
  1981. $this->success('添加成功');
  1982. }else{
  1983. $this->error('添加失败');
  1984. }
  1985. }
  1986. /**
  1987. * 印版领用记录退还
  1988. * @return void
  1989. * @throws \think\Exception
  1990. * @throws \think\db\exception\BindParamException
  1991. * @throws \think\exception\PDOException
  1992. */
  1993. public function PrintDetailEdit()
  1994. {
  1995. if ($this->request->isGet() === false){
  1996. $this->error('请求错误');
  1997. }
  1998. $param = $this->request->param();
  1999. if (empty($param) || !isset($param['id']) || !isset($param['number'])){
  2000. $this->error('参数错误');
  2001. }
  2002. $idList = explode(',',$param['id']);
  2003. $i = 0;
  2004. foreach ($idList as $key=>$value){
  2005. $data['Yb_退还日期'] = date('Y-m-d H:i:s',time());
  2006. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  2007. $data['Yb_印数'] = $param['number'];
  2008. $sql = \db('工单_印版领用记录')->where('UniqID',$value)->fetchSql(true)->update($data);
  2009. $res = \db()->query($sql);
  2010. if ($res === false){
  2011. $i++;
  2012. }
  2013. }
  2014. if ($i !== 0){
  2015. $this->error('退还失败');
  2016. }else{
  2017. $this->success('退还成功');
  2018. }
  2019. }
  2020. /**
  2021. * 当班产量明细修改
  2022. * @return void
  2023. * @throws \think\Exception
  2024. * @throws \think\db\exception\BindParamException
  2025. * @throws \think\exception\PDOException
  2026. */
  2027. // public function chanliangEdit()
  2028. // {
  2029. // if (Request::instance()->isPost() === false){
  2030. // $this->error('请求错误');
  2031. // }
  2032. // $param = Request::instance()->post();
  2033. // if (empty($param['UniqId'])){
  2034. // $this->error('参数错误');
  2035. // }
  2036. // $param['mod_rq'] = date('Y-m-d H:i:s',time());
  2037. // $data = $param;
  2038. // unset($data['UniqId']);
  2039. // unset($data['sczl_rq']);
  2040. // $sql = \db('设备_产量计酬')
  2041. // ->where('UniqId',$param['UniqId'])
  2042. // ->fetchSql(true)
  2043. // ->update($data);
  2044. // $res = \db()->query($sql);
  2045. // if ($res !== false){
  2046. // $this->success('修改成功');
  2047. // }else {
  2048. // $this->error('修改失败');
  2049. // }
  2050. // }
  2051. public function chanliangEdit()
  2052. {
  2053. // 使用更简洁的请求判断方式
  2054. if (!Request::instance()->isPost()) {
  2055. $this->error('请使用POST请求');
  2056. }
  2057. // 获取并过滤POST参数
  2058. $param = Request::instance()->post();
  2059. // 更严格的参数验证
  2060. if (empty($param['UniqId'])) {
  2061. $this->error('缺少必要参数: UniqId');
  2062. }
  2063. // 整理更新数据
  2064. $updateData = [
  2065. 'mod_rq' => date('Y-m-d H:i:s')
  2066. ];
  2067. // 合并其他参数(排除不需要的字段)
  2068. $excludeFields = ['UniqId', 'sczl_rq', 'sczl_装版总工时', 'sczl_换版联拼数', '换版类型'];
  2069. foreach ($param as $key => $value) {
  2070. if (!in_array($key, $excludeFields)) {
  2071. $updateData[$key] = $value;
  2072. }
  2073. }
  2074. $uniqId = $param['UniqId'];
  2075. $success = false;
  2076. try {
  2077. // 处理装版工时数据(如果存在)
  2078. if (!empty($param['sczl_装版总工时']) && $param['sczl_装版总工时'] != 0) {
  2079. $priData = [
  2080. '换版总工时' => $param['sczl_装版总工时'],
  2081. '换版联拼数' => $param['sczl_换版联拼数'] ?? 0,
  2082. '换版类型' => $param['换版类型'] ?? '',
  2083. '装版补产工时' => $param['sczl_装版工时'] ?? ''
  2084. ];
  2085. $priSql = \db('设备_装版工时')->where('yieldUid', $uniqId)->fetchSql(true)->update($priData);
  2086. \db()->query($priSql);
  2087. }
  2088. // 更新产量计酬数据
  2089. $rowSql = \db('设备_产量计酬')->where('UniqId', $uniqId)->fetchSql(true)->update($updateData);
  2090. $rowCount = \db()->query($rowSql);
  2091. $success = $rowCount !== false;
  2092. } catch (\Exception $e) {
  2093. // 记录错误日志
  2094. \think\Log::error('修改产量详情失败: ' . $e->getMessage() . ' 堆栈: ' . $e->getTraceAsString());
  2095. $this->error('操作失败: ' . $e->getMessage());
  2096. }
  2097. if ($success) {
  2098. $this->success('修改成功');
  2099. } else {
  2100. $this->error('修改失败,未更新任何数据');
  2101. }
  2102. }
  2103. /**
  2104. * 获取当日上报产量详细数据
  2105. * @return void
  2106. * @throws \think\db\exception\DataNotFoundException
  2107. * @throws \think\db\exception\ModelNotFoundException
  2108. * @throws \think\exception\DbException
  2109. */
  2110. public function MachineChanliangDetail()
  2111. {
  2112. if ($this->request->isGet() === false){
  2113. $this->error('请求错误');
  2114. }
  2115. $param = $this->request->param();
  2116. if (empty($param['UniqId'])){
  2117. $this->error('参数错误');
  2118. }
  2119. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,rtrim(sczl_ls) as 联数,
  2120. rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,rtrim(sczl_zcfp) as 制程废品,
  2121. rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,
  2122. rtrim(sczl_装版总工时) as 装版总工时,rtrim(sczl_打样总工时) as 打样总工时,
  2123. rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,
  2124. rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
  2125. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,
  2126. rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
  2127. rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  2128. rtrim(sczl_装版工时) as 装版补产工时,rtrim(sczl_打样工时) as 打样补产工时,
  2129. sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,
  2130. sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
  2131. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId';
  2132. $list = \db('设备_产量计酬')->where('UniqId',$param['UniqId'])->field($field)->find();
  2133. $pridata = \db('设备_装版工时')
  2134. ->field('换版联拼数,换版类型,Uniqid,coefficient')
  2135. ->where('yieldUid',$param['UniqId'])
  2136. ->order('Uniqid desc')
  2137. ->find();
  2138. if (empty($list)){
  2139. $this->success('未找到产量详情信息');
  2140. }
  2141. $list['换版联拼数'] = '';
  2142. $list['换版类型'] = '';
  2143. $list['Uid'] = '';
  2144. if (!empty($pridata)){
  2145. $list['换版联拼数'] = $pridata['换版联拼数'];
  2146. $list['换版类型'] = $pridata['换版类型'];
  2147. $list['Uid'] = $pridata['Uniqid'];
  2148. $list['系数'] = $pridata['coefficient'];
  2149. }
  2150. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$list['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  2151. $list['印件名称'] = $productName['cpmc'];
  2152. if (!empty($productName['成品名称'])){
  2153. $list['cpmc'] = $productName['成品名称'];
  2154. }elseif (empty($productName['成品名称']) && !empty($productName['cpmc'])){
  2155. $list['cpmc'] = $productName['cpmc'];
  2156. }else{
  2157. $list['cpmc'] = '';
  2158. }
  2159. for ($i=1;$i<11;$i++){
  2160. if (isset($list['sczl_bh'.$i])){
  2161. $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  2162. if (isset($name['name'])){
  2163. $list['组员'.$i] = [
  2164. '编号' => $list['sczl_bh'.$i],
  2165. '姓名' => $name['name'],
  2166. '比例' => (float)$list['sczl_rate'.$i]
  2167. ];
  2168. }
  2169. }
  2170. if (empty($list['sczl_bh'.$i])){
  2171. $list['组员'.$i] = [
  2172. '编号' => '',
  2173. '姓名' => '',
  2174. '比例' => ''
  2175. ];
  2176. }
  2177. unset($list['sczl_bh'.$i],$list['sczl_rate'.$i]);
  2178. }
  2179. $list['拉料'] = [
  2180. '编号' => $list['sczl_bh98'],
  2181. '姓名' => \db('人事_基本资料')->where('员工编号',$list['sczl_bh98'])->value('rtrim(员工姓名)')
  2182. ];
  2183. unset($list['sczl_bh98']);
  2184. $this->success('成功',$list);
  2185. }
  2186. /**
  2187. * 当日上报产量详细数据修改
  2188. * @return void
  2189. * @throws \think\Exception
  2190. * @throws \think\db\exception\BindParamException
  2191. * @throws \think\exception\PDOException
  2192. */
  2193. // public function MachineChanliangDetailEdit()
  2194. // {
  2195. // if (Request::instance()->isPost() === false){
  2196. // $this->error('请求错误');
  2197. // }
  2198. // $param = Request::instance()->post();
  2199. // if (empty($param['UniqId'])){
  2200. // $this->error('参数错误');
  2201. // }
  2202. // $param['sczl_type'] = $param['sczl_gxmc'];
  2203. // $param['mod_rq'] = date('Y-m-d H:i:s',time());
  2204. // $UnidId = $param['UniqId'];
  2205. // unset($param['UniqId']);
  2206. // unset($param['sczl_rq']);
  2207. // if (!empty($param['sczl_装版总工时']) && $param['sczl_装版总工时'] !== 0){
  2208. // $data = [
  2209. // 'gdbh' => $param['sczl_gdbh'],
  2210. // 'yjno' => $param['sczl_yjno'],
  2211. // 'gxh' => $param['sczl_gxh'],
  2212. // 'jtbh' => $param['sczl_jtbh'],
  2213. // 'startTime' => $param['sczl_sj1'],
  2214. // 'endTime' => $param['sczl_sj2'],
  2215. // '换版总工时' => $param['sczl_装版总工时'],
  2216. // '换版联拼数' => $param['sczl_换版联拼数'],
  2217. // '换版类型' => $param['换版类型']
  2218. // ];
  2219. // $priSql = \db('设备_装版工时')->where('yieldUid')->fetchSql(true)->update($data);
  2220. // $priRes = \db()->query($priSql);
  2221. //
  2222. // }
  2223. // $sql = \db('设备_产量计酬')->where('UniqId',$UnidId)->fetchSql(true)->update($param);
  2224. // $res = \db()->query($sql);
  2225. // if ($res !== false){
  2226. // $this->success('修改成功');
  2227. // }else{
  2228. // $this->error('修改失败');
  2229. // }
  2230. // }
  2231. public function MachineChanliangDetailEdit()
  2232. {
  2233. // 使用更简洁的请求判断方式
  2234. if (!Request::instance()->isPost()) {
  2235. $this->error('请使用POST请求');
  2236. }
  2237. // 获取并过滤POST参数
  2238. $param = Request::instance()->post();
  2239. // 更严格的参数验证
  2240. if (empty($param['UniqId'])) {
  2241. $this->error('缺少必要参数: UniqId');
  2242. }
  2243. // 整理更新数据
  2244. $updateData = [
  2245. 'sczl_type' => $param['sczl_gxmc'] ?? '',
  2246. 'mod_rq' => date('Y-m-d H:i:s')
  2247. ];
  2248. // 合并其他参数(排除不需要的字段)
  2249. $excludeFields = ['UniqId', 'sczl_rq', 'sczl_装版总工时', 'sczl_换版联拼数', '换版类型'];
  2250. foreach ($param as $key => $value) {
  2251. if (!in_array($key, $excludeFields)) {
  2252. $updateData[$key] = $value;
  2253. }
  2254. }
  2255. $uniqId = $param['UniqId'];
  2256. $success = false;
  2257. try {
  2258. // 处理装版工时数据(如果存在)
  2259. if (!empty($param['sczl_装版总工时']) && $param['sczl_装版总工时'] != 0) {
  2260. $priData = [
  2261. 'gdbh' => $param['sczl_gdbh'] ?? '',
  2262. 'yjno' => $param['sczl_yjno'] ?? '',
  2263. 'gxh' => $param['sczl_gxh'] ?? '',
  2264. 'jtbh' => $param['sczl_jtbh'] ?? '',
  2265. 'startTime' => $param['sczl_sj1'] ?? '',
  2266. 'endTime' => $param['sczl_sj2'] ?? '',
  2267. '换版总工时' => $param['sczl_装版总工时'],
  2268. '换版联拼数' => $param['sczl_换版联拼数'] ?? 0,
  2269. '换版类型' => $param['换版类型'] ?? '',
  2270. '装版补产工时' => $param['sczl_装版工时'] ?? ''
  2271. ];
  2272. $priSql = \db('设备_装版工时')->where('yieldUid', $uniqId)->fetchSql(true)->update($priData);
  2273. \db()->query($priSql);
  2274. }
  2275. // 更新产量计酬数据
  2276. $rowSql = \db('设备_产量计酬')->where('UniqId', $uniqId)->fetchSql(true)->update($updateData);
  2277. $rowCount = \db()->query($rowSql);
  2278. $success = $rowCount !== false;
  2279. } catch (\Exception $e) {
  2280. // 记录错误日志
  2281. \think\Log::error('修改产量详情失败: ' . $e->getMessage() . ' 堆栈: ' . $e->getTraceAsString());
  2282. $this->error('操作失败: ' . $e->getMessage());
  2283. }
  2284. if ($success) {
  2285. $this->success('修改成功');
  2286. } else {
  2287. $this->error('修改失败,未更新任何数据');
  2288. }
  2289. }
  2290. /**
  2291. * 产量上报数据删除
  2292. * @return void
  2293. * @throws \think\Exception
  2294. * @throws \think\exception\PDOException
  2295. */
  2296. public function ChanliangDel()
  2297. {
  2298. if ($this->request->isGet() === false){
  2299. $this->error('请求错误');
  2300. }
  2301. $param = $this->request->param();
  2302. if (empty($param['UniqId'])){
  2303. $this->error('参数错误');
  2304. }
  2305. $idList = explode(',',$param['UniqId']);
  2306. foreach ($idList as $key=>$value){
  2307. $res = \db('设备_产量计酬')
  2308. ->where('UniqId',$value)
  2309. ->delete();
  2310. }
  2311. if ($res !== false){
  2312. $this->success('删除成功');
  2313. }else{
  2314. $this->error('删除失败');
  2315. }
  2316. }
  2317. /**
  2318. * 日产量上报添加
  2319. * @return void
  2320. * @throws \think\db\exception\BindParamException
  2321. * @throws \think\exception\PDOException
  2322. */
  2323. // public function ChanliangAdd()
  2324. // {
  2325. // if (Request::instance()->isPost() === false){
  2326. // $this->error('请求错误');
  2327. // }
  2328. // $params = Request::instance()->post();
  2329. // if (empty($params['sczl_gdbh'])){
  2330. // $this->error('参数错误');
  2331. // }
  2332. // $lastId = \db('设备_产量计酬')->order('UniqId desc')->value('rtrim(UniqId)');
  2333. // $massage = \db('工单_工艺资料')
  2334. // ->where('Gy0_gdbh',$params['sczl_gdbh'])
  2335. // ->where('Gy0_yjno',$params['sczl_yjno'])
  2336. // ->where('Gy0_gxh',$params['sczl_gxh'])
  2337. // ->count();
  2338. // if ($massage === 0){
  2339. // $this->error('请选择正确的工序');
  2340. // }
  2341. // $params['sczl_type'] = $params['sczl_gxmc'];
  2342. // $params['sczl_wgsj'] = '1900-01-01 00:00:00';
  2343. // $params['sczl_废品率系数'] = 0;
  2344. // $params['sys_rq'] = date('Y-m-d H:i:s',time());
  2345. // $params['mod_rq'] = date('Y-m-d H:i:s',time());
  2346. // $params['UniqId'] = $lastId + 1;
  2347. // if (!empty($params['sczl_装版总工时']) && $params['sczl_装版总工时'] !== 0){
  2348. // $data = [
  2349. // 'gdbh' => $params['sczl_gdbh'],
  2350. // 'yjno' => $params['sczl_yjno'],
  2351. // 'gxh' => $params['sczl_gxh'],
  2352. // 'jtbh' => $params['sczl_jtbh'],
  2353. // 'startTime' => $params['sczl_sj1'],
  2354. // 'endTime' => $params['sczl_sj2'],
  2355. // 'yieldUid' => $params['UniqId'],
  2356. // '换版总工时' => $params['sczl_装版总工时'],
  2357. // '换版联拼数' => $params['sczl_换版联拼数'],
  2358. // '换版类型' => $params['换版类型'],
  2359. // 'sys_rq' => date('Y-m-d H:i:s',time()),
  2360. // 'sys_id' => $params['sys_id']
  2361. // ];
  2362. // $chSql = \db('设备_装版工时')->fetchSql(true)->insert($data);
  2363. // $chRes = \db()->query($chSql);
  2364. // }
  2365. // unset($params['sczl_换版联拼数'],$params['换版类型']);
  2366. // $sql = \db('设备_产量计酬')->fetchSql(true)->insert($params);
  2367. // $res = \db()->query($sql);
  2368. // if ($res !== false){
  2369. // $this->success('成功');
  2370. // }else{
  2371. // $this->error('失败');
  2372. // }
  2373. // }
  2374. public function ChanliangAdd()
  2375. {
  2376. // 1. 请求验证
  2377. if (!Request::instance()->isPost()) {
  2378. $this->error('请求错误');
  2379. }
  2380. $params = Request::instance()->post();
  2381. // 2. 参数验证
  2382. if (empty($params['sczl_gdbh'])) {
  2383. $this->error('参数错误');
  2384. }
  2385. // 3. 获取最新ID
  2386. $lastId = db('设备_产量计酬')->order('UniqId desc')->value('rtrim(UniqId)');
  2387. // 4. 验证工序存在性
  2388. $massage = db('工单_工艺资料')
  2389. ->where('Gy0_gdbh', $params['sczl_gdbh'])
  2390. ->where('Gy0_yjno', $params['sczl_yjno'])
  2391. ->where('Gy0_gxh', $params['sczl_gxh'])
  2392. ->count();
  2393. if ($massage === 0) {
  2394. $this->error('请选择正确的工序');
  2395. }
  2396. // 5. 准备基础数据
  2397. $currentTime = date('Y-m-d H:i:s');
  2398. $params['sczl_type'] = $params['sczl_gxmc'];
  2399. $params['sczl_wgsj'] = '1900-01-01 00:00:00';
  2400. $params['sczl_废品率系数'] = 0;
  2401. $params['sys_rq'] = $currentTime;
  2402. $params['mod_rq'] = $currentTime;
  2403. $params['UniqId'] = $lastId + 1;
  2404. // 6. 处理装版工时记录(如果有)
  2405. if (!empty($params['sczl_装版总工时']) && $params['sczl_装版总工时'] != 0) {
  2406. $plateData = [
  2407. 'gdbh' => $params['sczl_gdbh'],
  2408. 'yjno' => $params['sczl_yjno'],
  2409. 'gxh' => $params['sczl_gxh'],
  2410. 'jtbh' => $params['sczl_jtbh'],
  2411. 'startTime' => $params['sczl_sj1'],
  2412. 'endTime' => $params['sczl_sj2'],
  2413. 'yieldUid' => $params['UniqId'],
  2414. '换版总工时' => $params['sczl_装版总工时'],
  2415. '换版联拼数' => $params['sczl_换版联拼数'],
  2416. '换版类型' => $params['换版类型'],
  2417. 'sys_rq' => $currentTime,
  2418. 'sys_id' => $params['sys_id']
  2419. ];
  2420. $chSql = db('设备_装版工时')->fetchSql(true)->insert($plateData);
  2421. $chRes = \db()->query($chSql);
  2422. if ($chRes === false) {
  2423. $this->error('装版工时记录保存失败');
  2424. }
  2425. }
  2426. // 7. 移除不需要的字段
  2427. unset($params['sczl_换版联拼数'], $params['换版类型']);
  2428. // 8. 保存主记录
  2429. $sql = db('设备_产量计酬')->fetchSql(true)->insert($params);
  2430. $res = db()->query($sql);
  2431. if ($res !== false) {
  2432. $this->success('成功');
  2433. } else {
  2434. $this->error('失败');
  2435. }
  2436. }
  2437. /**
  2438. * 日产量上报添加获取工单信息
  2439. * @return void
  2440. * @throws \think\db\exception\DataNotFoundException
  2441. * @throws \think\db\exception\ModelNotFoundException
  2442. * @throws \think\exception\DbException
  2443. */
  2444. public function ChanliangWorkorder()
  2445. {
  2446. if ($this->request->isGet() === false)
  2447. {
  2448. $this->error('请求错误');
  2449. }
  2450. $param = $this->request->param();
  2451. if (empty($param)){
  2452. $this->error('参数错误');
  2453. }
  2454. // $where = [
  2455. // 'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
  2456. // ];
  2457. // if (!empty($param['machine'])){
  2458. // $where = [
  2459. // 'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
  2460. // ];
  2461. // }
  2462. if (!empty($param['search'])){
  2463. $where['b.Gy0_gdbh'] = ['like','%'.$param['search'].'%'];
  2464. }
  2465. $list = \db('工单_基本资料')
  2466. ->alias('a')
  2467. ->field('rtrim(Gd_gdbh) as gdbh,rtrim(成品名称) as cpmc')
  2468. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  2469. ->where($where)
  2470. ->select();
  2471. if (empty($list)){
  2472. $this->success('未找到相关工单');
  2473. }else{
  2474. $this->success('成功',$list);
  2475. }
  2476. }
  2477. /**
  2478. * 日产量上报工单印件资料
  2479. * @return void
  2480. * @throws \think\db\exception\DataNotFoundException
  2481. * @throws \think\db\exception\ModelNotFoundException
  2482. * @throws \think\exception\DbException
  2483. */
  2484. public function ChanliangPrintDetail()
  2485. {
  2486. if ($this->request->isGet() === false){
  2487. $this->error('请求错误');
  2488. }
  2489. $param = $this->request->param();
  2490. if (empty($param['gdbh'])){
  2491. $this->error('参数错误');
  2492. }
  2493. $where = [
  2494. 'Yj_Gdbh' => $param['gdbh']
  2495. ];
  2496. $list = \db('工单_印件资料')
  2497. ->where($where)
  2498. ->field('rtrim(yj_Yjno) as yjno,rtrim(yj_yjmc) as yjmc,rtrim(yj_ls) as ls')
  2499. ->select();
  2500. if (empty($list)){
  2501. $this->success('未找到印件资料');
  2502. }else{
  2503. $this->success('成功',$list);
  2504. }
  2505. }
  2506. /**
  2507. * 日产量上报工艺资料获取
  2508. * @return void
  2509. * @throws \think\db\exception\DataNotFoundException
  2510. * @throws \think\db\exception\ModelNotFoundException
  2511. * @throws \think\exception\DbException
  2512. */
  2513. public function ChanliangProcessDetail()
  2514. {
  2515. if ($this->request->isGet() === false){
  2516. $this->error('请求错误');
  2517. }
  2518. $param = $this->request->param();
  2519. if (empty($param['gdbh'])){
  2520. $this->error('参数错误');
  2521. }
  2522. // $sys_bh = \db('dic_lzde')->where('适用机型',$param['machine'])->value('sys_bh');
  2523. $list = \db('工单_工艺资料')
  2524. ->where('Gy0_gdbh',$param['gdbh'])
  2525. ->where('Gy0_yjno',$param['yjno'])
  2526. // ->where('Gy0_sbbh','like','%'.$param['machine'].'%')
  2527. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  2528. ->select();
  2529. if (empty($list)){
  2530. $this->success('未获取工序');
  2531. }
  2532. // $time = \db('设备_产量计酬')
  2533. // ->where('sczl_gdbh',$param['gdbh'])
  2534. // ->where('sczl_yjno',$param['yjno'])
  2535. // ->where('sczl_jtbh','like','%'.$param['machine'].'%')
  2536. // ->order('UniqId desc')
  2537. // ->value('sczl_sj2');
  2538. // $newTime = date('Y-m-d H:i:s');
  2539. // if ($newTime > date('Y-m-d 08:30:00') && $newTime < date('Y-m-d 20:30:00') && $time < date('Y-m-d 08:30:00')){
  2540. // $time = date('Y-m-d 08:30:00');
  2541. // }elseif ($newTime > date('Y-m-d 20:30:00') && $time < date('Y-m-d 20:30:00')){
  2542. // $time = date('Y-m-d 20:30:00');
  2543. // }
  2544. foreach ($list as $key=>$value){
  2545. if ((int)$value['gxh'] < 10){
  2546. $value['gxh'] = '0'.$value['gxh'];
  2547. }
  2548. if (empty($value['add_gxmc'])){
  2549. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'];
  2550. }else{
  2551. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  2552. }
  2553. unset( $list[$key]['add_gxmc']);
  2554. // $list[$key]['time'] = $time;
  2555. }
  2556. // $list['sys_bh'] = $sys_bh;
  2557. $this->success('成功',$list);
  2558. }
  2559. /**
  2560. * 工价系数修改
  2561. * @return void
  2562. * @throws \think\Exception
  2563. * @throws \think\db\exception\BindParamException
  2564. * @throws \think\exception\PDOException
  2565. */
  2566. public function CoefficientEdit()
  2567. {
  2568. if (Request::instance()->isPost() === false){
  2569. $this->error('请求错误');
  2570. }
  2571. $params = Request::instance()->post();
  2572. if (empty($params['id'])){
  2573. $this->error('参数错误');
  2574. }
  2575. $idList = explode(',',$params['id']);
  2576. $i=0;
  2577. foreach ($idList as $key=>$value){
  2578. $sql = \db('设备_产量计酬')
  2579. ->where('UniqId',$value)
  2580. ->fetchSql(true)
  2581. ->update(['sczl_工价系数'=>$params['工价系数']]);
  2582. $res = \db()->query($sql);
  2583. if ($res === false){
  2584. $i++;
  2585. }
  2586. }
  2587. if ($i!==0){
  2588. $this->error('修改失败');
  2589. }else{
  2590. $this->success('修改成功');
  2591. }
  2592. }
  2593. /**
  2594. * 色度系数修改
  2595. * @return void
  2596. * @throws \think\Exception
  2597. * @throws \think\db\exception\BindParamException
  2598. * @throws \think\exception\PDOException
  2599. */
  2600. public function ChromaDataEdit()
  2601. {
  2602. if (Request::instance()->isPost() === false){
  2603. $this->error('请求错误');
  2604. }
  2605. $params = Request::instance()->post();
  2606. if (empty($params['id'])){
  2607. $this->error('参数错误');
  2608. }
  2609. $idList = explode(',',$params['id']);
  2610. $i=0;
  2611. foreach ($idList as $key=>$value){
  2612. $sql = \db('设备_产量计酬')
  2613. ->where('UniqId',$value)
  2614. ->fetchSql(true)
  2615. ->update(['sczl_ms'=>$params['ms']]);
  2616. $res = \db()->query($sql);
  2617. if ($res === false){
  2618. $i++;
  2619. }
  2620. }
  2621. if ($i!==0){
  2622. $this->error('修改失败');
  2623. }else{
  2624. $this->success('修改成功');
  2625. }
  2626. }
  2627. /**
  2628. * 凹印版距修改
  2629. * @return void
  2630. * @throws \think\Exception
  2631. * @throws \think\db\exception\BindParamException
  2632. * @throws \think\exception\PDOException
  2633. */
  2634. public function PrintingModeDataEdit()
  2635. {
  2636. if (Request::instance()->isPost() === false){
  2637. $this->error('请求错误');
  2638. }
  2639. $params = Request::instance()->post();
  2640. if (empty($params['id'])){
  2641. $this->error('参数错误');
  2642. }
  2643. $idList = explode(',',$params['id']);
  2644. //获取工单印件工序
  2645. $orderList = \db('设备_产量计酬')
  2646. ->where('UniqId',$idList[0])
  2647. ->field('rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as 印件号,rtrim(sczl_gxh) as 工序号')
  2648. ->find();
  2649. //修改工艺资料
  2650. $sql = \db('工单_工艺资料')
  2651. ->where([
  2652. 'Gy0_gdbh'=>$orderList['工单编号'],
  2653. 'Gy0_yjno'=>$orderList['印件号'],
  2654. 'Gy0_gxh'=>$orderList['工序号']
  2655. ])
  2656. ->fetchSql(true)
  2657. ->update(['版距'=>$params['plate'],'印刷方式'=>$params['mode']]);
  2658. $res = \db()->query($sql);
  2659. if ($res === false){
  2660. $this->error('修改失败');
  2661. }else{
  2662. $this->success('修改成功');
  2663. }
  2664. }
  2665. /**
  2666. * 废品率系数批量修改
  2667. * @return void
  2668. * @throws \think\Exception
  2669. * @throws \think\db\exception\BindParamException
  2670. * @throws \think\exception\PDOException
  2671. */
  2672. public function RejectionEdit()
  2673. {
  2674. if (Request::instance()->isPost() === false){
  2675. $this->error('请求错误');
  2676. }
  2677. $params = Request::instance()->post();
  2678. if (empty($params['id'])){
  2679. $this->error('参数错误');
  2680. }
  2681. $idList = explode(',',$params['id']);
  2682. $i=0;
  2683. foreach ($idList as $key=>$value){
  2684. $sql = \db('设备_产量计酬')
  2685. ->where('UniqId',$value)
  2686. ->fetchSql(true)
  2687. ->update(['sczl_废品率系数'=>$params['rejection']]);
  2688. $res = \db()->query($sql);
  2689. if ($res === false){
  2690. $i++;
  2691. }
  2692. }
  2693. if ($i!==0){
  2694. $this->error('修改失败');
  2695. }else{
  2696. $this->success('修改成功');
  2697. }
  2698. }
  2699. /**
  2700. * 日产量上报班组信息批量修改
  2701. * @return void
  2702. * @throws \think\Exception
  2703. * @throws \think\db\exception\BindParamException
  2704. * @throws \think\db\exception\DataNotFoundException
  2705. * @throws \think\db\exception\ModelNotFoundException
  2706. * @throws \think\exception\DbException
  2707. * @throws \think\exception\PDOException
  2708. */
  2709. public function YieldTeamEdit()
  2710. {
  2711. if ($this->request->isGet() === false){
  2712. $this->error('请求错误');
  2713. }
  2714. $param = $this->request->param();
  2715. if (empty($param['Uniqid']) || empty($param['teamID'])){
  2716. $this->error('参数错误');
  2717. }
  2718. $idList = explode(',',$param['Uniqid']);
  2719. $teamList = \db('设备_班组资料')->where('UniqId',$param['teamID'])->find();
  2720. $data = [];
  2721. for ($i=1;$i<11;$i++){
  2722. $data['sczl_bh'.$i] = $teamList['sczl_bh'.$i];
  2723. $data['sczl_rate'.$i] = $teamList['sczl_rate'.$i];
  2724. $data['sczl_bzdh'] = $teamList['sczl_bzdh'];
  2725. }
  2726. $j = 0;
  2727. foreach ($idList as $key => $value){
  2728. $sql = \db('设备_产量计酬')
  2729. ->where('UniqId',$value)
  2730. ->fetchSql(true)
  2731. ->update($data);
  2732. $res = \db()->query($sql);
  2733. if ($res === false){
  2734. $j++;
  2735. }
  2736. }
  2737. if ($j === 0){
  2738. $this->success('修改成功');
  2739. }else{
  2740. $this->error('修改失败');
  2741. }
  2742. }
  2743. /**
  2744. * 检品机日产量上报数据修改
  2745. * @return void
  2746. * @throws \think\Exception
  2747. * @throws \think\db\exception\BindParamException
  2748. * @throws \think\exception\PDOException
  2749. */
  2750. public function JpChanliangEdit()
  2751. {
  2752. if (Request::instance()->isPost() == false){
  2753. $this->error('非法请求');
  2754. }
  2755. $params = Request::instance()->post();
  2756. if (empty($params['UniqId'])){
  2757. $this->error('参数错误');
  2758. }
  2759. $params['mod_rq'] = date('Y-m-d H:i:s');
  2760. $data = $params;
  2761. unset($data['UniqId']);
  2762. $sql = \db('设备_产量计酬')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
  2763. $res = \db()->query($sql);
  2764. if ($res === false){
  2765. $this->error('修改失败');
  2766. }else{
  2767. $this->success('成功');
  2768. }
  2769. }
  2770. /**
  2771. * 检品机日产量上报数据列表
  2772. * @return void
  2773. * @throws \think\db\exception\DataNotFoundException
  2774. * @throws \think\db\exception\ModelNotFoundException
  2775. * @throws \think\exception\DbException
  2776. */
  2777. public function JPmachineDetail()
  2778. {
  2779. if ($this->request->isGet() === false){
  2780. $this->error('请求错误');
  2781. }
  2782. $machine = input('machine');
  2783. $date = input('date');
  2784. $where = [
  2785. 'sczl_jtbh' => $machine,
  2786. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  2787. ];
  2788. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_type) as 检验类型,rtrim(sczl_num) as num,rtrim(sczl_cl) as 计件箱数,
  2789. rtrim(sczl_Pgcl) as 每箱数量,rtrim(sczl_bzdh) as bzdh,IF(sczl_废品率系数 = 0, "",sczl_废品率系数) as 废品率系数,IF(sczl_装版工时 = 0, "",sczl_装版工时) as 换膜补时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
  2790. rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  2791. sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
  2792. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,rtrim(sczl_dedh) as 定额代号,sczl_rq,sczl_装版总工时 as 换膜总工时';
  2793. //机台信息
  2794. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  2795. //组员信息
  2796. $list = \db('设备_产量计酬')->where($where)->field($field)->select();
  2797. $totalA = \db('设备_产量计酬')
  2798. ->where($where)
  2799. ->where('sczl_bzdh','like','A%')
  2800. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数,SUM(sczl_装版工时) as 总换膜补时,SUM(sczl_保养工时) as 总保养工时,SUM(sczl_异常停机工时) as 总异常总工时,SUM(sczl_设备运行工时) as 总通电工时')
  2801. ->group('检验类型')
  2802. ->select();
  2803. $totalB = \db('设备_产量计酬')
  2804. ->where($where)
  2805. ->where('sczl_bzdh','like','B%')
  2806. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数,SUM(sczl_装版工时) as 总换膜补时,SUM(sczl_保养工时) as 总保养工时,SUM(sczl_异常停机工时) as 总异常总工时,SUM(sczl_设备运行工时) as 总通电工时')
  2807. ->group('检验类型')
  2808. ->select();
  2809. if (empty($list)){
  2810. $this->success('',[]);
  2811. }
  2812. foreach ($list as $key=>$value){
  2813. //产品名称
  2814. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  2815. if (!empty($productName)){
  2816. if (!empty($productName['成品名称'])){
  2817. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
  2818. $list[$key]['cpmc'] = $productName['成品名称'];
  2819. }else{
  2820. $list[$key]['产品名称'] = $value['工单编号'];
  2821. $list[$key]['cpmc'] = '';
  2822. }
  2823. }else{
  2824. $list[$key]['产品名称'] = $value['工单编号'];
  2825. $list[$key]['cpmc'] = '';
  2826. }
  2827. if (empty($value['定额代号'])){
  2828. $list[$key]['千件工价'] = '';
  2829. $list[$key]['日定额'] = '';
  2830. $list[$key]['补产标准'] = '';
  2831. }else{
  2832. $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
  2833. $list[$key]['千件工价'] = $row['千件工价'];
  2834. $list[$key]['日定额'] = $row['日定额'];
  2835. $list[$key]['补产标准'] = $row['补产标准'];
  2836. }
  2837. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxh'].'-'.$list[$key]['gxmc'];
  2838. for ($i=1;$i<11;$i++){
  2839. if (isset($value['sczl_bh'.$i])){
  2840. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('员工姓名 as name')->find();
  2841. if (isset($name['name'])){
  2842. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  2843. $list[$key]['sczl_name'.$i] = $name['name'];
  2844. }else{
  2845. $list[$key]['sczl_name'.$i] = '';
  2846. }
  2847. }
  2848. }
  2849. }
  2850. $list['totalA'] = $totalA;
  2851. $list['totalB'] = $totalB;
  2852. $this->success('成功',$list);
  2853. }
  2854. /**
  2855. * 检品机每日上报数据修改页面数据获取接口
  2856. * @return void
  2857. * @throws \think\db\exception\DataNotFoundException
  2858. * @throws \think\db\exception\ModelNotFoundException
  2859. * @throws \think\exception\DbException
  2860. */
  2861. public function JPchanliangDetailList()
  2862. {
  2863. if ($this->request->isGet() === false){
  2864. $this->error('请求错误');
  2865. }
  2866. $param = $this->request->param();
  2867. if (empty($param)){
  2868. $this->error('参数错误');
  2869. }
  2870. $list = \db('设备_产量计酬')
  2871. ->alias('a')
  2872. ->join('工单_基本资料 b','a.sczl_gdbh = b.Gd_gdbh AND a.sczl_yjno = b.行号')
  2873. ->field('rtrim(a.sczl_gdbh) as 工单编号,rtrim(a.sczl_dedh) as dedh,rtrim(a.sczl_yjno) as yjno,
  2874. rtrim(a.sczl_gxh) as gxh,rtrim(a.sczl_gxmc) as gxmc,rtrim(a.sczl_type) as 检验类型,rtrim(a.sczl_num) as num,
  2875. rtrim(a.sczl_cl) as 计件箱数,rtrim(a.sczl_Pgcl) as 每箱数量,rtrim(a.sczl_bzdh) as bzdh,
  2876. IF(a.sczl_废品率系数 = 0, "",a.sczl_废品率系数) as 废品率系数,IF(a.sczl_装版工时 = 0, "",a.sczl_装版工时) as 换膜补时,
  2877. IF(a.sczl_保养工时 = 0, "",a.sczl_保养工时) as 保养工时,IF(a.sczl_异常停机工时 = 0, "",a.sczl_异常停机工时) as 异常总工时,
  2878. IF(a.sczl_设备运行工时 = 0, "",a.sczl_设备运行工时) as 通电工时,rtrim(a.sys_id) as 用户,rtrim(a.mod_rq) as 更新时间,
  2879. IF(a.sczl_异常工时1 = 0, "",a.sczl_异常工时1) as 异常补时,IF(a.sczl_异常类型1 = 0, "",a.sczl_异常类型1) as 异常类型,
  2880. a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.sczl_bh5,a.sczl_bh6,a.sczl_bh7,a.sczl_bh8,a.sczl_bh9,a.sczl_bh10,
  2881. a.sczl_rate1,a.sczl_rate2,a.sczl_rate3,a.sczl_rate4,a.sczl_rate5,a.sczl_rate6,a.sczl_rate7,a.sczl_rate8,
  2882. a.sczl_rate9,a.sczl_rate10,a.sczl_bh98,rtrim(a.UniqId) as UniqId,rtrim(a.sczl_工价系数) as 难度系数,
  2883. rtrim(a.sczl_dedh) as 定额代号,a.sczl_rq,a.sczl_装版总工时 as 换膜总工时,rtrim(b.Gd_cpmc) as 产品名称,rtrim(b.成品名称) as 成品名称')
  2884. ->where('a.UniqId',$param['UniqId'])
  2885. ->find();
  2886. for ($i=1;$i<11;$i++){
  2887. if (isset($list['sczl_bh'.$i])){
  2888. $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('员工姓名 as name')->find();
  2889. if (isset($name['name'])){
  2890. $list['组员'.$i] = $list['sczl_bh'.$i].$name['name'].'('.((float)$list['sczl_rate'.$i]*100).'%'.')';
  2891. $list['sczl_name'.$i] = $name['name'];
  2892. }else{
  2893. $list['sczl_name'.$i] = '';
  2894. }
  2895. }
  2896. }
  2897. if (!empty($list)){
  2898. $this->success('成功',$list);
  2899. }else{
  2900. $this->error('未找到数据');
  2901. }
  2902. }
  2903. /**
  2904. * 拉纸工数据导出
  2905. * @return void
  2906. * @throws \think\db\exception\DataNotFoundException
  2907. * @throws \think\db\exception\ModelNotFoundException
  2908. * @throws \think\exception\DbException
  2909. */
  2910. public function LazhiGongData()
  2911. {
  2912. if ($this->request->isGet() === false){
  2913. $this->error('请求错误');
  2914. }
  2915. $param = $this->request->param();
  2916. if (empty($param['mouth'])){
  2917. $this->error('请选择月份');
  2918. }
  2919. $filed = [
  2920. 'a.sczl_gdbh' => '工单编号',
  2921. 'b.yj_yjmc' => '产品名称',
  2922. 'a.sczl_num' => '流程单号',
  2923. 'a.sczl_yjno' => '印件号',
  2924. 'a.sczl_gxh' => '工序号',
  2925. 'a.sczl_jtbh' => '机台编号',
  2926. 'a.sczl_rq' => '日期',
  2927. 'a.sczl_type' => '工序名称',
  2928. 'a.sczl_cl' => '产量',
  2929. 'a.sczl_bh1' => '机长工号',
  2930. 'c1.员工姓名' => '机长姓名',
  2931. 'a.sczl_bh2' => '组员工号1',
  2932. 'c2.员工姓名' => '组员姓名1',
  2933. 'a.sczl_bh3' => '组员工号2',
  2934. 'c3.员工姓名' => '组员姓名2',
  2935. 'a.sczl_bh98' => '拉料工工号',
  2936. 'c4.员工姓名' => '拉料工姓名'
  2937. ];
  2938. $list = \db('设备_产量计酬')
  2939. ->alias('a')
  2940. ->join('工单_印件资料 b','a.sczl_gdbh = b.Yj_Gdbh AND a.sczl_yjno = b.yj_Yjno')
  2941. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  2942. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  2943. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  2944. ->join('人事_基本资料 c4','a.sczl_bh98 = c4.员工编号','left')
  2945. ->field($filed)
  2946. ->where('a.sczl_rq','like',$param['mouth'].'%')
  2947. ->where('a.sczl_bh98','<>','')
  2948. ->order('a.sczl_rq,a.sczl_jtbh')
  2949. ->select();
  2950. if (!empty($list)){
  2951. $this->success('成功',$list);
  2952. }else{
  2953. $this->error('未找到相关数据');
  2954. }
  2955. }
  2956. }