Facility.php 90 KB

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