Facility.php 85 KB

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