Facility.php 92 KB

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