Facility.php 102 KB

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