Facility.php 115 KB

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