Facility.php 90 KB

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