Facility.php 84 KB

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