Facility.php 91 KB

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