Facility.php 110 KB

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