Facility.php 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535
  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. */
  16. public function ApiMouthlist() {
  17. // 检查请求类型是否为GET
  18. if ($this->request->isGet() === false) {
  19. $this->error('请求错误');
  20. }
  21. $param = $this->request->param();
  22. // 查询符合条件的数据
  23. $list = \db('设备_质量汇总')
  24. ->where('状态', $param['code'])
  25. ->where('mod_rq', null)
  26. ->group('Sys_rq')
  27. ->select();
  28. if (empty($list)) {
  29. $this->error('没有找到数据');
  30. }
  31. // 用于存储按年和月分类的数据
  32. $data = [];
  33. // 遍历查询结果,将日期按年、月分组
  34. foreach ($list as $item) {
  35. // 获取 Sys_rq 字段的值(日期)
  36. $sys_rq = $item['Sys_rq'];
  37. // 提取年、月、日
  38. $year = date('Y', strtotime($sys_rq));
  39. $month = date('Y-m', strtotime($sys_rq));
  40. $day = date('Y-m-d', strtotime($sys_rq));
  41. // 将数据按年、月、日分类
  42. if (!isset($data[$year])) {
  43. $data[$year] = [];
  44. }
  45. if (!isset($data[$year][$month])) {
  46. $data[$year][$month] = [];
  47. }
  48. // 将日期加入到对应的年、月下
  49. $data[$year][$month][] = $day;
  50. }
  51. $this->success('成功', $data);
  52. }
  53. /**
  54. * 新增次品和新增返工
  55. */
  56. public function ApiAddDefective(){
  57. if (!$this->request->isPost()) {
  58. $this->error('非法请求');
  59. }
  60. $params = $this->request->param();
  61. if (empty($params)){
  62. $this->error('参数错误');
  63. }
  64. $res = \db('设备_质量汇总')->where('mod_rq', null)->order('status_num desc')->find();
  65. //记录每次新增次数排序
  66. $status_num = $res['status_num'];
  67. // 构建单条记录的函数,传递 $list_gd 作为参数
  68. function buildRecords($item,$status_num) {
  69. // 拆分物料名称(假设格式为 面料分类-面料名称)
  70. $materialParts = explode('-', $item['物料名称']);
  71. $materialCategory = isset($materialParts[0]) ? $materialParts[0] : ''; // 面料分类
  72. $materialName = isset($materialParts[1]) ? $materialParts[1] : ''; // 面料名称
  73. return [
  74. '订单编号' => $item['订单编号'],
  75. '生产款号' => $item['生产款号'],
  76. '款式' => $item['款式'],
  77. '颜色' => $item['颜色'],
  78. '尺码' => $item['尺码'],
  79. '数量' => $item['数量'],
  80. '组别' => $item['组别'],
  81. '实际用料' => $item['实际用料'],
  82. '计划用料' => $item['计划用料'],
  83. '备注' => $item['备注'],
  84. '问题分类' => $item['问题分类'],
  85. 'sczl_rq' => date('Y-m-d H:i:s'),
  86. 'Sys_rq' => $item['Sys_rq'],
  87. 'Sys_id' => $item['Sys_id'],
  88. '状态' => $item['状态'],
  89. 'status_num' => $status_num + 1,
  90. '面料分类' => $materialCategory,
  91. '面料名称' => $materialName,
  92. ];
  93. }
  94. // 检查是否是索引数组(多条记录)
  95. if (isset($params[0]) && is_array($params[0])) {
  96. foreach ($params as $item) {
  97. $list[] = buildRecords($item,$status_num);
  98. }
  99. } else {
  100. // 处理单条记录
  101. $list[] = buildRecords($params,$status_num);
  102. }
  103. // 插入数据到设备_产量计酬表
  104. $result = \db('设备_质量汇总')->insertAll($list);
  105. if ($result) {
  106. $this->success('数据插入成功 : ' . date('H:i:s'));
  107. } else {
  108. $this->error('数据插入失败');
  109. }
  110. }
  111. /**
  112. * 查询订单对应尺码
  113. */
  114. public function queryOrderSize() {
  115. // 检查请求类型是否为GET
  116. if ($this->request->isGet() === false) {
  117. $this->error('请求错误');
  118. }
  119. $param = $this->request->param();
  120. // 获取问题分类
  121. $fetchCategory = \db('db_问题分类')->field('问题类型')->select();
  122. $category = array_column($fetchCategory, '问题类型'); // 获取问题类型列表
  123. // 查询订单基本信息
  124. $gdlist = \db('工单_基本资料')
  125. ->field('订单编号,生产款号,款式,订单数量')
  126. // ->where('订单编号|生产款号','like','%'.$param['订单编号'].'%')
  127. ->where(['订单编号|生产款号' => $param['订单编号']])
  128. ->where('Mod_rq', null)
  129. ->find();
  130. if (empty($gdlist)) {
  131. $this->error('未找到相关数据');
  132. }
  133. // 查询订单尺码信息
  134. $sizeData = \db('工单_印件资料')->where(['订单编号' => $gdlist['订单编号']])->where('Mod_rq', null)->select();
  135. if (empty($sizeData)) {
  136. $this->error('未找到相关数据');
  137. }
  138. // 计算所有尺码数据
  139. $sizes = [];
  140. foreach ($sizeData as $order) {
  141. foreach ($order as $key => $value) {
  142. if (strpos($key, 'cm') === 0 && strpos($key, 'cmsl') === false && $value !== null && $value !== '') {
  143. $sizes[] = $value;
  144. }
  145. }
  146. }
  147. $sizes = array_values(array_unique($sizes)); // 去重后的尺码数据
  148. // 获取颜色备注并统计每个颜色的sctotal和zdtotal
  149. $colorData = []; // 用于存储每个颜色备注对应的sctotal和zdtotal
  150. foreach ($sizeData as $item) {
  151. if (!empty($item['颜色备注'])) {
  152. $color = $item['颜色备注'];
  153. $sctotal = (int)$item['sctotal'];
  154. $zdtotal = (int)$item['zdtotal'];
  155. if (isset($colorData[$color])) {
  156. $colorData[$color]['sctotal'] += $sctotal;
  157. $colorData[$color]['zdtotal'] += $zdtotal;
  158. } else {
  159. $colorData[$color] = [
  160. 'sctotal' => $sctotal,
  161. 'zdtotal' => $zdtotal
  162. ];
  163. }
  164. }
  165. }
  166. // 获取颜色备注(去重)
  167. $colorremark = array_values(array_unique(array_keys($colorData)));
  168. // 获取面料数据
  169. $getAllFabricData = \db('工单_面料资料')
  170. ->field('BOM_desc,BOM_物料名称,BOM_定额门幅,BOM_计划门幅,BOM_颜色')
  171. ->where('BOM_工单编号', $param['订单编号'])
  172. ->where('Mod_rq', null)
  173. ->select();
  174. $fabricData = [];
  175. $materialSeen = [];
  176. $descNullData = [];
  177. // 处理面料数据
  178. foreach ($getAllFabricData as $value) {
  179. $materialName = $value['BOM_物料名称'];
  180. $bomDesc = $value['BOM_desc'];
  181. $combinedData = ($bomDesc ? $bomDesc : '') . ' - ' . $materialName;
  182. // 如果 BOM_desc 为空,记录该物料名称
  183. if (empty($bomDesc)) {
  184. $descNullData[] = $combinedData;
  185. continue;
  186. }
  187. // 如果 BOM_desc 不为空,检查该物料名称是否已经出现过
  188. if (!in_array($materialName, $materialSeen)) {
  189. $fabricData[] = $combinedData;
  190. $materialSeen[] = $materialName;
  191. }
  192. }
  193. // 处理 BOM_desc 为空的物料名称,确保不重复添加
  194. foreach ($descNullData as $combinedData) {
  195. if (!in_array($combinedData, $fabricData)) {
  196. $fabricData[] = $combinedData;
  197. }
  198. }
  199. // 去重处理面料数据
  200. $finalFabricData = [];
  201. $seenDescriptions = [];
  202. foreach ($fabricData as $item) {
  203. $parts = explode(' - ', $item);
  204. if (count($parts) == 2) {
  205. $desc = $parts[0];
  206. $material = $parts[1];
  207. // 如果物料没有被记录过,或者描述不为空,保留数据
  208. if (!in_array($material, $seenDescriptions)) {
  209. $finalFabricData[] = $item;
  210. $seenDescriptions[] = $material;
  211. }
  212. } else {
  213. // 描述为空的直接保留
  214. $finalFabricData[] = $item;
  215. }
  216. }
  217. // 用于统计每个物料的用料情况
  218. $uniqueFabricData = []; // 去重后的面料数据
  219. foreach ($getAllFabricData as $fabric) {
  220. $key = $fabric['BOM_颜色'] . '-' . $fabric['BOM_物料名称']; // 以颜色和物料名称为唯一标识
  221. $uniqueFabricData[$key] = $fabric; // 使用唯一标识作为数组的键,自动去重
  222. }
  223. // 重建数组索引,移除键名
  224. $uniqueFabricData = array_values($uniqueFabricData);
  225. $materialUsage = [];
  226. // 遍历每种颜色的统计数据
  227. foreach ($colorData as $color => $data) {
  228. // 遍历去重后的面料数据
  229. foreach ($uniqueFabricData as $fabric) {
  230. // 判断颜色是否匹配
  231. if ($fabric['BOM_颜色'] === $color) {
  232. // 直接统计每个物料的数量,而不进行用料的计算
  233. $materialUsage[$color][$fabric['BOM_物料名称']][] = $fabric; // 使用物料名称作为键,存储所有相关的面料数据
  234. }
  235. }
  236. }
  237. // 生成实际用料数据
  238. $actualUsage = [];
  239. foreach ($materialUsage as $color => $materials) {
  240. foreach ($materials as $materialName => $fabricData) {
  241. // 获取该颜色下的 sctotal 和 zdtotal
  242. $sctotal = isset($colorData[$color]['sctotal']) ? $colorData[$color]['sctotal'] : 0;
  243. $zdtotal = isset($colorData[$color]['zdtotal']) ? $colorData[$color]['zdtotal'] : 0;
  244. // 获取定额门幅和计划门幅
  245. $standardWidth = isset($fabricData[0]['BOM_定额门幅']) ? $fabricData[0]['BOM_定额门幅'] : 0;
  246. $plannedWidth = isset($fabricData[0]['BOM_计划门幅']) ? $fabricData[0]['BOM_计划门幅'] : 0;
  247. // 直接根据去重后的面料数据进行统计
  248. $actualUsage[] = [
  249. '颜色' => $color,
  250. '物料名称' => $materialName,
  251. '定额门幅' => $standardWidth,
  252. '计划门幅' => $plannedWidth,
  253. 'sctotal' => $sctotal,
  254. 'zdtotal' => $zdtotal
  255. ];
  256. }
  257. }
  258. foreach ($actualUsage as &$item) {
  259. $item['实际用料'] = $item['sctotal'] * $item['定额门幅'];
  260. $item['计划用料'] = $item['zdtotal'] * $item['计划门幅'];
  261. }
  262. // 选择显示的字段
  263. $fieldsToShow = ['颜色', '物料名称', '实际用料', '计划用料'];
  264. $finalResult = array();
  265. foreach ($actualUsage as $item) {
  266. $filteredItem = array();
  267. foreach ($fieldsToShow as $field) {
  268. if (isset($item[$field])) {
  269. $filteredItem[$field] = $item[$field];
  270. }
  271. }
  272. $finalResult[] = $filteredItem;
  273. }
  274. $this->success('成功', [
  275. 'list' => $gdlist,
  276. 'colorremark' => $colorremark,
  277. 'fetchCategory' => $category,
  278. 'FabricData' => $finalFabricData,
  279. 'size' => $sizes,
  280. '面料统计' => $finalResult
  281. ]);
  282. }
  283. /**
  284. * 查询次片、返工列表数据
  285. */
  286. /**
  287. * 查询次片、返工列表数据
  288. */
  289. public function ApiSubPieceAndReworkList() {
  290. if ($this->request->isGet() === false) {
  291. $this->error('请求错误');
  292. }
  293. $params = $this->request->param();
  294. $where = ['mod_rq' => null];
  295. if (!empty($params['code'])) {
  296. $where['状态'] = $params['code'];
  297. }
  298. if (!empty($params['search'])) {
  299. $where['订单编号|生产款号|面料名称'] = ['like', '%' . $params['search'] . '%'];
  300. }
  301. if (!empty($params['Sys_rq'])) {
  302. $where['Sys_rq'] = $params['Sys_rq'];
  303. }
  304. $query = \db('设备_质量汇总')
  305. ->where($where)
  306. ->limit(($params['page'] - 1) * $params['limit'], $params['limit']);
  307. $res = $query->select();
  308. $total = $query->count();
  309. $this->success('成功', ['data' => $res, 'total' => $total]);
  310. }
  311. // /**
  312. // * 更新问题分类接口
  313. // */
  314. // public function Production()
  315. // {
  316. //
  317. // }
  318. /**
  319. * 统计面料次品汇总
  320. * 统计面料返工汇总
  321. */
  322. // if ($this->request->isGet() === false){
  323. // $this->error('请求错误');
  324. // }
  325. // $params = $this->request->param();
  326. public function ApiDefectsAndRework()
  327. {
  328. // 查询设备质量汇总数据,mod_rq为空
  329. $list = \db('设备_质量汇总')
  330. ->where('mod_rq', null)
  331. ->where('状态', '次片')
  332. ->select();
  333. // 创建一个空数组来存储面料名称及其对应的总数量
  334. $fabricSummary = [];
  335. // 遍历查询结果,累加相同面料名称的数量
  336. foreach ($list as $item) {
  337. $fabricName = $item['面料名称'];
  338. $quantity = $item['数量'];
  339. // 如果该面料名称已存在于数组中,则累加数量
  340. if (isset($fabricSummary[$fabricName])) {
  341. $fabricSummary[$fabricName] += $quantity;
  342. } else {
  343. // 如果该面料名称不存在,则初始化数量
  344. $fabricSummary[$fabricName] = $quantity;
  345. }
  346. }
  347. // 打印结果
  348. echo "<pre>";
  349. print_r($fabricSummary);
  350. echo "</pre>";
  351. }
  352. /**
  353. * 工序、印件、完成数量
  354. * @ApiMethod (GET)
  355. * @param string $workOrder 工单编号
  356. * @return void
  357. * @throws \think\Exception
  358. * @throws \think\db\exception\DataNotFoundException
  359. * @throws \think\db\exception\ModelNotFoundException
  360. * @throws \think\exception\DbException
  361. */
  362. public function Procedure()
  363. {
  364. if ($this->request->isGet() === false){
  365. $this->error('请求错误');
  366. }
  367. $workOrder = input('Gd_gdbh');
  368. $data = [];
  369. if (!empty($workOrder)){
  370. //右边工艺及完成数量
  371. $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  372. ->distinct(true)->order('sczl_gxh')
  373. ->column('sczl_gxh');
  374. foreach ($Process as $k=>$v){
  375. $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  376. ->where('sczl_gxh',$v)
  377. ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
  378. ->find();
  379. if ($res['sczl_yjno']<10){
  380. $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
  381. }
  382. $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
  383. $processList['completed'] = \db('设备_产量计酬')
  384. ->where('sczl_gdbh',$workOrder)
  385. ->where('sczl_gxh',$v)
  386. ->count();
  387. array_push($data,$processList);
  388. }
  389. }
  390. $this->success('成功',$data);
  391. }
  392. /**
  393. * 班组人员及分配比例
  394. * @ApiMethod (GET)
  395. * @param string $machine 机台编号
  396. * @return void
  397. * @throws \think\db\exception\DataNotFoundException
  398. * @throws \think\db\exception\ModelNotFoundException
  399. * @throws \think\exception\DbException
  400. */
  401. public function Team()
  402. {
  403. if ($this->request->isGet() === false){
  404. $this->error('请求错误');
  405. }
  406. $machine = input('machine');
  407. if (empty($machine)){
  408. $this->error('参数错误');
  409. }
  410. $where = [
  411. 'sczl_jtbh' => $machine,
  412. ];
  413. $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,
  414. 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,
  415. 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,
  416. rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
  417. rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
  418. $team = \db('设备_产量计酬')
  419. ->where('sczl_jtbh',$machine)
  420. ->field($field)
  421. ->order('UniqId desc')
  422. ->find();
  423. $list = \db('设备_班组资料')->where($where)->field($field)->select();
  424. $data = [];
  425. foreach ($list as $k=>$v){
  426. if ($team == $v){
  427. $data[$k]['status'] = 1;
  428. }else{
  429. $data[$k]['status'] = 0;
  430. }
  431. $data[$k]['ID'] = $v['ID'];
  432. $data[$k]['班组号'] = $v['班组号'];
  433. for ($i=1;$i<11;$i++){
  434. if ($v['bh'.$i] != '' && $v['bh'.$i] != '000000'){
  435. $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
  436. if ($v['rate'.$i] > 0){
  437. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
  438. }else{
  439. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' (0.00%'.')';
  440. }
  441. }
  442. }
  443. }
  444. $this->success('成功',$data);
  445. }
  446. /**
  447. * 当班产量明细
  448. * @ApiMethod (GET)
  449. * @param string $machine 机台编号
  450. * @param string $workOrder 工单编号
  451. * @param string $team 班次
  452. * @return void
  453. * @throws \think\db\exception\DataNotFoundException
  454. * @throws \think\db\exception\ModelNotFoundException
  455. * @throws \think\exception\DbException
  456. */
  457. public function OutputDetail()
  458. {
  459. if ($this->request->isGet() === false){
  460. $this->error('请求错误');
  461. }
  462. $machine = input('machine');
  463. $workOrder = input('Gd_gdbh');
  464. $team = substr(input('team'),0,1);
  465. if (empty($machine) || empty($team)){
  466. $this->success('');
  467. }
  468. $sczlTime = date('Y-m-d H:i:s',time());
  469. if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime<date('Y-m-d 08:30:00')){
  470. $time = date('Y-m-d 00:00:00',time()-86400);
  471. }else{
  472. $time = date('Y-m-d 00:00:00');
  473. }
  474. $where = [
  475. 'sczl_jtbh' => $machine,
  476. 'sczl_bzdh' => ['like',$team.'%'],
  477. 'sczl_rq' => $time,
  478. ];
  479. $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 产量,
  480. rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
  481. rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
  482. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
  483. rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2,rtrim(UniqId) as UniqId,rtrim(sczl_bh98) as 拉料,rtrim(sczl_ls) as ls';
  484. $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
  485. if (!empty($list)){
  486. foreach ($list as $k=>$v){
  487. $name = \db('工单_基本资料')->where('Gd_gdbh',$v['工单编号'])->where('行号',$v['yjno'])->field('rtrim(Gd_cpmc) as productName,rtrim(成品名称) as 成品名称')->find();
  488. if ($v['yjno']<10){
  489. $list[$k]['yjno'] = '0'.$v['yjno'];
  490. }
  491. if (!empty($v['拉料'])){
  492. $list[$k]['拉料姓名'] = \db('人事_基本资料')->where('员工编号',$v['拉料'])->value('rtrim(员工姓名) as 员工姓名');
  493. }
  494. if (isset($list[$k]['拉料姓名']) === false){
  495. $list[$k]['拉料姓名'] = '';
  496. }
  497. $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
  498. $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
  499. $list[$k]['产品名称'] = $name['productName'];
  500. if (empty($name['productName'])){
  501. $list[$k]['产品名称'] = $name['成品名称'];
  502. }
  503. }
  504. $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
  505. SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
  506. SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
  507. SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
  508. $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
  509. $total[0]['版数'] = count($list);
  510. $list['total'] = $total[0];
  511. }
  512. $this->success('成功',$list);
  513. }
  514. /**
  515. * 检验记录
  516. * @ApiMethod (GET)
  517. * @param string $machine 机台编号
  518. * @param string $workOrder 工单编号
  519. * @param string $team 班次
  520. * @return void
  521. * @throws \think\db\exception\DataNotFoundException
  522. * @throws \think\db\exception\ModelNotFoundException
  523. * @throws \think\exception\DbException
  524. */
  525. public function InspectionRecord()
  526. {
  527. if ($this->request->isGet() === false){
  528. $this->error('请求失败');
  529. }
  530. $machine = input('machine');
  531. $workOrder = input('Gd_gdbh');
  532. $team = input('team');
  533. if (empty($machine) || empty($workOrder) || empty($team)){
  534. $this->success('');
  535. }
  536. $where = [
  537. '设备编号' => $machine,
  538. '工单编号' => $workOrder,
  539. '班组编号' => $team,
  540. '类别' => ['in',['IPQC检验','机台检验']],
  541. ];
  542. //检验项目筛选
  543. $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
  544. //检验时间
  545. $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  546. foreach ($InspectionTime as $k=>$v){
  547. $InspectionTime[$k] = date('H:i',strtotime($v));
  548. }
  549. //检测记录详情
  550. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  551. $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
  552. $data = [];
  553. //检测数据
  554. foreach ($item as $key=>$value){
  555. $SubmissionTime = \db('制程检验_记录')->where($where)
  556. ->where('检验项目',$value)
  557. ->where('检验结果','合格')
  558. ->field('rtrim(提交时间) as 提交时间')
  559. ->select();
  560. $time = [];
  561. foreach ($SubmissionTime as $k=>$v){
  562. $time[$k] = date('H:i',strtotime($v['提交时间']));
  563. }
  564. $data[$key] = [
  565. '工单编号' => $nameDetail['工单编号'],
  566. '印件号' => $nameDetail['印件号'],
  567. '工序名称' => $nameDetail['工序名称'],
  568. '检验项目' => $value,
  569. 'inspectresult' => implode(',',$time),
  570. ];
  571. }
  572. $data['inspectiontime'] = $InspectionTime;
  573. $this->success('成功',$data);
  574. }
  575. /**
  576. * 班组维护->班组添加
  577. * @ApiMethod (GET)
  578. * @param void
  579. * @return void
  580. * @throws \think\db\exception\DataNotFoundException
  581. * @throws \think\db\exception\ModelNotFoundException
  582. * @throws \think\exception\DbException
  583. */
  584. public function MachineTeamAdd()
  585. {
  586. if (Request::instance()->isPost() === false ){
  587. $this->error('请求错误');
  588. }
  589. $param = Request::instance()->post();
  590. if (empty($param)){
  591. $this->error('参数错误');
  592. }
  593. $lastId = \db('设备_班组资料')
  594. ->order('UniqId desc')
  595. ->value('UniqId');
  596. if (empty($lastId)){
  597. $lastId = 0;
  598. }
  599. for($i=1;$i<11;$i++){
  600. if (!empty($param['sczl_bh'.$i])){
  601. $name = \db('人事_基本资料')->where('员工编号',$param['sczl_bh'.$i])->value('员工编号');
  602. if (empty($name)){
  603. $this->error('未找到编号'.$param['sczl_bh'.$i].'员工信息,无法添加,请输入正确的员工编号');
  604. }
  605. }
  606. }
  607. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  608. $param['UniqId'] = $lastId + 1;
  609. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  610. $sql = \db('设备_班组资料')->fetchSql(true)->insert($param);
  611. $res = \db()->query($sql);
  612. if ($res !== false){
  613. $this->success('成功');
  614. }else{
  615. $this->error('失败');
  616. }
  617. }
  618. /**
  619. * 机台编号列表
  620. * @ApiMethod (GET)
  621. * @return void
  622. */
  623. public function MachineList()
  624. {
  625. if ($this->request->isGet() === false){
  626. $this->error('请求错误');
  627. }
  628. $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  629. if (empty($list)){
  630. $this->success('未找到机台编号');
  631. }
  632. $data = [];
  633. foreach ($list as $key=>$value){
  634. $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
  635. }
  636. $this->success('成功',$data);
  637. }
  638. /**
  639. * 删除班组信息
  640. * @ApiMethod (GET)
  641. * @param void
  642. * @return void
  643. * @throws \think\Exception
  644. * @throws \think\exception\PDOException
  645. */
  646. public function teamDel()
  647. {
  648. if (Request::instance()->isPost() === false){
  649. $this->error('请求错误');
  650. }
  651. $param = Request::instance()->post();
  652. if (empty($param)){
  653. $this->error('参数错误');
  654. }
  655. $machine = \db('设备_班组资料')
  656. ->where('UniqId',$param['UniqId'])
  657. ->value('sczl_jtbh');
  658. $teamId = \db('设备_产量采集')
  659. ->where('设备编号',$machine)
  660. ->order('UniqId desc')
  661. ->value('班组ID');
  662. if ($teamId === (int)$param['UniqId']){
  663. $this->success('无法删除正在生产的班组资料,请先切换班组');
  664. }
  665. $res = \db('设备_班组资料')
  666. ->where('UniqId',$param['UniqId'])
  667. ->delete();
  668. if ($res !== false){
  669. $this->success('成功');
  670. }else{
  671. $this->error('失败');
  672. }
  673. }
  674. /**
  675. * 管理人员现场巡检记录->展示
  676. * @ApiMethod (GET)
  677. * @param void
  678. * @return void
  679. * @throws \think\db\exception\DataNotFoundException
  680. * @throws \think\db\exception\ModelNotFoundException
  681. * @throws \think\exception\DbException
  682. */
  683. public function FieldInspectionRecord()
  684. {
  685. if ($this->request->isGet() === false){
  686. $this->error('请求错误');
  687. }
  688. $param = $this->request->param();
  689. if (empty($param)){
  690. $this->error('参数错误');
  691. }
  692. $date = date('Y-m-d H:i:s',time());
  693. if (empty($param['start'])){
  694. $startTime = date('Y-m-d 08:30:00',time());
  695. }else{
  696. $startTime = $param['start'];
  697. }
  698. if ($date<$startTime){
  699. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  700. }
  701. $where = [
  702. '工单编号' => $param['workOrder'],
  703. '开工时间' => $startTime,
  704. '类别' => '现场巡查记录',
  705. '班组编号' => $param['team']
  706. ];
  707. $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
  708. rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
  709. rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
  710. $list = \db('制程检验_记录')->where($where)
  711. ->field($filed)
  712. ->select();
  713. if (empty($list)){
  714. $this->success('',[]);
  715. }
  716. foreach ($list as $key=>$value){
  717. $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
  718. $list[$key]['归属时段'] = $value['开工时间'];
  719. $list[$key]['分钟差数'] = $number;
  720. if ($number != 0){
  721. $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
  722. }
  723. }
  724. $this->success('成功',$list);
  725. }
  726. /**
  727. * 管理人员现场巡检记录->添加
  728. * @ApiMethod (POST)
  729. * @param void
  730. * @return void
  731. */
  732. public function FieldInspectionRecordAdd()
  733. {
  734. if (Request::instance()->isPost() === false){
  735. $this->error('请求错误');
  736. }
  737. $param = Request::instance()->post();
  738. if (empty($param)){
  739. $this->error('参数错误');
  740. }
  741. if ($param['processCode']<10){
  742. $param['processCode'] = '0'.$param['processCode'];
  743. }
  744. $date = date('Y-m-d H:i:s',time());
  745. $startTime = date('Y-m-d 08:30:00',time());
  746. if ($date<$startTime){
  747. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  748. }
  749. $data = [
  750. '类别' => $param['category'],
  751. '工单编号' => $param['workOrder'],
  752. '印件号' => $param['printCode'],
  753. '工序名称' => $param['processCode'].'-'.$param['process'],
  754. '流程单号' => $param['flowCode'],
  755. '设备编号' => $param['machine'],
  756. '班组编号' => $param['team'],
  757. '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
  758. '相关标准' => '',
  759. '量测仪器' => '',
  760. '检验结果' => '',
  761. '检验备注' => $param['remark'],
  762. '提交时间' => date('Y-m-d H:i:s',time()),
  763. '开工时间' => $startTime,
  764. 'sys_id' => '',
  765. 'sys_rq' => date('Y-m-d H:i:s',time()),
  766. 'mod_rq' => '0000-00-00 00:00:00',
  767. 'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
  768. ];
  769. $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
  770. $res = Db::query($sql);
  771. if ($res !== false){
  772. $this->success('成功');
  773. }else{
  774. $this->error('失败');
  775. }
  776. }
  777. /**
  778. * 设备点检->左侧菜单栏
  779. * @ApiMethod (GET)
  780. * @param void
  781. * @return void
  782. */
  783. public function SpotCheckItem()
  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('适用机型','LIKE','%;'.$param['machine'].';%')
  794. ->distinct(true)
  795. ->column('部件名称','部件编号');
  796. if (empty($list)){
  797. $this->success('');
  798. }
  799. $this->success('成功',$list);
  800. }
  801. /**
  802. * 设备点检->检测项目
  803. * @ApiMethod (GET)
  804. * @param void
  805. * @return void
  806. * @throws \think\db\exception\DataNotFoundException
  807. * @throws \think\db\exception\ModelNotFoundException
  808. * @throws \think\exception\DbException
  809. */
  810. public function InspectionItem()
  811. {
  812. if ($this->request->isGet() === false){
  813. $this->error('请求错误');
  814. }
  815. $param = $this->request->param();
  816. if (empty($param)){
  817. $this->error('参数错误');
  818. }
  819. $list = \db('设备_点检项目')
  820. ->where('部件名称',$param['unitName'])
  821. ->where('适用机型','like','%'.$param['machine'].'#%')
  822. ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
  823. ->select();
  824. if (empty($list)){
  825. $this->success('未找到检测项目');
  826. }
  827. $this->success('成功',$list);
  828. }
  829. /**
  830. * 设备点检->检测记录添加
  831. * @ApiMethod (POST)
  832. * @param void
  833. * @return void
  834. * @throws \think\db\exception\DataNotFoundException
  835. * @throws \think\db\exception\ModelNotFoundException
  836. * @throws \think\exception\DbException
  837. */
  838. public function InspectionItemAdd()
  839. {
  840. if (Request::instance()->isPost() === false){
  841. $this->error('请求错误');
  842. }
  843. $param = Request::instance()->post();
  844. if (empty($param)){
  845. $this->error('参数错误');
  846. }
  847. $lastNumber = \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
  848. if (empty($lastNumber)){
  849. $lastId = 0;
  850. }else{
  851. $lastId = $lastNumber;
  852. }
  853. $row = [];
  854. foreach ($param as $key=>$value){
  855. $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
  856. $row[$key] = [
  857. '日期' => date('Y-m-d 00:00:00',time()),
  858. '班组编号' => $value['team'],
  859. '点检设备' => $value['machine'],
  860. '部件编号' => $unitCode['部件编号'],
  861. '部件名称' => $value['unitName'],
  862. '检验项目' => $value['itemName'],
  863. '判定标准' => $value['standard'],
  864. '点检方法' => $value['method'],
  865. '点检结果' => $value['status'],
  866. '备注说明' => $value['remark'],
  867. 'Sys_id' =>'',
  868. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  869. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  870. 'Uniqid' => $lastId+$key+1
  871. ];
  872. }
  873. $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
  874. $res = Db::query($sql);
  875. if ($res !== false){
  876. $this->success('成功');
  877. }else{
  878. $this->error('失败');
  879. }
  880. }
  881. /**
  882. * 机台印版领用->左侧菜单
  883. * @ApiMethod (GET)
  884. * @param void
  885. * @return void
  886. */
  887. public function PrintGetTab()
  888. {
  889. if ($this->request->isGet() === false){
  890. $this->error('请求错误');
  891. }
  892. $param = $this->request->param();
  893. if (empty($param)){
  894. $this->error('参数错误');
  895. }
  896. $productCode = $param['productCode'];
  897. $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
  898. JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
  899. WHERE a.YB_Cpdh = '{$productCode}'";
  900. $res = Db::query($sql);
  901. if (empty($res)){
  902. $this->success('');
  903. }
  904. $this->success('成功',$res);
  905. }
  906. /**
  907. * 机台印版领用记录->数据详情
  908. * @ApiMethod (GET)
  909. * @param void
  910. * @return void
  911. */
  912. public function PrintDetail()
  913. {
  914. if ($this->request->isGet() === false){
  915. $this->error('请求失败');
  916. }
  917. $param = $this->request->param();
  918. if (empty($param)){
  919. $this->error('参数错误');
  920. }
  921. $productCode = $param['productCode'];
  922. $code = $param['code'].'%';
  923. $workOrder = $param['workOrder'];
  924. $sql = "SELECT
  925. RTRIM(a.`存货编码`) as `存货编码`,
  926. RTRIM(c.`物料名称`) as `存货名称`,
  927. RTRIM(b.`印版名称`) as `印版名称`,
  928. RTRIM(b.`供方批号`) as `供方批号`,
  929. RTRIM(b.`制造日期`) as `制造日期`,
  930. SUM(d.`Yb_印数`) as `印数`,
  931. RTRIM(e.`名称`) as `印版类别`,
  932. SUBSTRING(a.YB_Cpdh,1,4) as `客户编号`,
  933. RTRIM(f.`Gd_客户名称`) as `客户名称`,
  934. RTRIM(a.YB_Cpdh) as `产品编号`,
  935. RTRIM(f.Gd_cpmc) as `产品名称`,
  936. RTRIM(d.UniqID) as UniqId
  937. FROM `产品_印版资料` as a
  938. LEFT JOIN `产品_印版库` as b ON b.`存货编码` = a.`存货编码`
  939. JOIN `物料_存货编码` as c ON c.`物料代码` = a.`存货编码`
  940. LEFT JOIN `工单_印版领用记录` as d ON d.`Yb_供方批号` = b.`供方批号`
  941. JOIN `物料_存货结构` as e ON e.`编号` = SUBSTRING(a.`存货编码`,1,4)
  942. JOIN `工单_基本资料` as f ON a.YB_Cpdh = f.Gd_cpdh
  943. WHERE a.YB_Cpdh = '{$productCode}'
  944. AND a.`存货编码` LIKE '{$code}'
  945. AND f.Gd_gdbh = '{$workOrder}'
  946. AND b.`报废日期` = '1900-01-01 00:00:00'
  947. GROUP BY b.`供方批号`
  948. ORDER BY a.`存货编码`";
  949. $list = Db::query($sql);
  950. if (empty($list)){
  951. $this->success('');
  952. }
  953. $this->success('成功',$list);
  954. }
  955. /**
  956. * 换型清场->左侧菜单栏
  957. * @ApiMethod (GET)
  958. * @param void
  959. * @return void
  960. */
  961. public function remodelGetTab()
  962. {
  963. if ($this->request->isGet() === false){
  964. $this->error('请求错误');
  965. }
  966. $date = date('Y-m-d 00:00:00',time()-3456000);
  967. $nowTime = date('Y-m-d H:i:s',time());
  968. $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
  969. if (empty($list)){
  970. $this->error('失败');
  971. }
  972. $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId
  973. FROM `设备_基本资料` as a
  974. LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
  975. WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' AND b.`工单编号A` <> '' AND b.`工单编号B` <> '' ORDER BY b.`UniqId`";
  976. $res = Db::query($sql);
  977. $data = $result = [];
  978. foreach ($list as $key=>$value){
  979. $data[$value] = $result[$value]= $time = [];
  980. foreach ($res as $k=>$v){
  981. if ($value === $v['设备编号']){
  982. $row = [
  983. '日期' => $v['日期'],
  984. 'id' => $v['UniqId']
  985. ];
  986. array_push($data[$value],$row);
  987. }
  988. }
  989. foreach ($data[$value] as $m=>$n){
  990. $time[$m] = $n['日期'];
  991. }
  992. $time = array_values(array_unique($time));
  993. foreach ($time as $kk=>$vv){
  994. $i=1;
  995. foreach ($data[$value] as $kkk=>$vvv){
  996. if ($kkk>=$kk && $vv === $vvv['日期']){
  997. array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
  998. $i++;
  999. }
  1000. }
  1001. }
  1002. }
  1003. $this->success('成功',$result);
  1004. }
  1005. /**
  1006. * 换型清场->详情
  1007. * @return void
  1008. * @throws \think\db\exception\DataNotFoundException
  1009. * @throws \think\db\exception\ModelNotFoundException
  1010. * @throws \think\exception\DbException
  1011. */
  1012. public function RemodelDetail()
  1013. {
  1014. if ($this->request->isGet() === false){
  1015. $this->error('请求错误');
  1016. }
  1017. $param = $this->request->param();
  1018. if (empty($param)){
  1019. $this->error('参数错误');
  1020. }
  1021. $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1022. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
  1023. rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
  1024. rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
  1025. $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
  1026. if (empty($list)){
  1027. $this->success('未找到该条清场记录');
  1028. }
  1029. $list['日期'] = date('Y-m-d',strtotime($list['日期']));
  1030. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1031. if (empty($printNameA)){
  1032. $list['印件名称A'] = '';
  1033. }else{
  1034. $list['印件名称A'] = $printNameA['yjmc'];
  1035. }
  1036. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1037. if (empty($printNameB)){
  1038. $list['印件名称B'] = '';
  1039. }else{
  1040. $list['印件名称B'] = $printNameB['yjmc'];
  1041. }
  1042. $this->success('成功',$list);
  1043. }
  1044. /**
  1045. * 换型清场->当前设备清场记录
  1046. * @ApiMethod (GET)
  1047. * @param void
  1048. * @return void
  1049. * @throws \think\db\exception\DataNotFoundException
  1050. * @throws \think\db\exception\ModelNotFoundException
  1051. * @throws \think\exception\DbException
  1052. */
  1053. public function ModelChangeRecord()
  1054. {
  1055. if ($this->request->isGet() === false){
  1056. $this->error('请求错误');
  1057. }
  1058. $param = $this->request->param();
  1059. if (empty($param)){
  1060. $this->error('参数错误');
  1061. }
  1062. $date = date('Y-m-d 00:00:00',time()-3888000);
  1063. $nowTime = date('Y-m-d H:i:s',time());
  1064. $where = [
  1065. '日期' =>['between',[$date,$nowTime]],
  1066. '机台编号' => $param['machine'],
  1067. '工单编号A' => ['<>',''],
  1068. '工单编号B' => ['<>',''],
  1069. ];
  1070. $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1071. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
  1072. rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
  1073. rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_rq) as 创建时间,rtrim(UniqId) as UNIQID";
  1074. $list = \db('制程_换型清场')
  1075. ->where($where)
  1076. ->field($field)
  1077. ->select();
  1078. if (empty($list)){
  1079. $this->success('未找到换型记录');
  1080. }
  1081. foreach ($list as $key=>$value){
  1082. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->value('rtrim(yj_yjmc) as yjmc');
  1083. if (empty($printNameA)){
  1084. $list[$key]['印件名称A'] = '';
  1085. }else{
  1086. $list[$key]['印件名称A'] = $printNameA;
  1087. }
  1088. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->value('rtrim(yj_yjmc) as yjmc');
  1089. if (empty($printNameB)){
  1090. $list[$key]['印件名称B'] = '';
  1091. }else{
  1092. $list[$key]['印件名称B'] = $printNameB;
  1093. }
  1094. }
  1095. $this->success('成功',$list);
  1096. }
  1097. /**
  1098. * 车间机台状态列表展示
  1099. * @ApiMethod (GET)
  1100. * @param void
  1101. * @return void
  1102. * @throws \think\db\exception\BindParamException
  1103. * @throws \think\exception\PDOException
  1104. */
  1105. public function MachineDetailList()
  1106. {
  1107. if ($this->request->isGet() === false){
  1108. $this->error('请求错误');
  1109. }
  1110. $param = $this->request->param();
  1111. if (empty($param)){
  1112. $this->error('参数错误');
  1113. }
  1114. $workshop = $param['workshop'];
  1115. $sql = "SELECT
  1116. RTRIM( a.`设备编号` ) AS 设备编号,
  1117. RTRIM( a.`设备名称` ) AS 设备名称,
  1118. RTRIM( d.`当前状态` ) AS 状态
  1119. FROM
  1120. `设备_基本资料` AS a
  1121. JOIN (
  1122. SELECT
  1123. b.`设备编号`,
  1124. b.`当前状态`,
  1125. b.`开工时间`
  1126. FROM
  1127. `设备_产量采集` AS b
  1128. JOIN ( SELECT `设备编号`, MAX( `UniqId` ) AS `UniqId` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号`
  1129. AND b.`UniqId` = c.`UniqId`
  1130. ) AS d ON a.`设备编号` = d.`设备编号`
  1131. WHERE
  1132. a.`使用部门` = '{$workshop}'
  1133. GROUP BY
  1134. a.`设备编号`
  1135. ORDER BY
  1136. a.UniqId";
  1137. $list = \db()->query($sql);
  1138. foreach ($list as $key=>$value){
  1139. if ($value['状态'] == ''){
  1140. $list[$key]['状态'] = '待单';
  1141. }
  1142. }
  1143. $this->success('成功',$list);
  1144. }
  1145. /**
  1146. * 机台当前参数展示
  1147. * @ApiMethod (GET)
  1148. * @return void
  1149. * @throws \think\db\exception\DataNotFoundException
  1150. * @throws \think\db\exception\ModelNotFoundException
  1151. * @throws \think\exception\DbException
  1152. */
  1153. public function MachineDetail()
  1154. {
  1155. if ($this->request->isGet() === false){
  1156. $this->error('请求错误');
  1157. }
  1158. $param = $this->request->param();
  1159. if (empty($param)){
  1160. $this->error('参数错误');
  1161. }
  1162. $data = [];
  1163. if ($param['start'] === ''){
  1164. 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())){
  1165. $param['start'] = date('Y-m-d 08:30:00',time());
  1166. }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())){
  1167. $param['start'] = date('Y-m-d 20:30:00',time());
  1168. }else{
  1169. $param['start'] = date('Y-m-d 20:30:00',time()-86400);
  1170. }
  1171. }
  1172. $machineDetail = \db('设备_产量采集')
  1173. ->alias('a')
  1174. ->join('设备_基本资料 b','a.设备编号 = b.设备编号')
  1175. ->join('工单_工艺资料 c','a.工单编号 = c.Gy0_gdbh AND a.设备编号 = c.Gy0_sbbh')
  1176. ->join('工单_基本资料 d','a.工单编号 = d.Gd_gdbh')
  1177. ->field([
  1178. 'rtrim(a.开工时间)' => '开工时间',
  1179. 'rtrim(a.设备编号)' => '设备编号',
  1180. 'rtrim(a.工单编号)' => '工单编号',
  1181. 'rtrim(b.设备名称)' => '设备名称',
  1182. 'rtrim(c.Gy0_gxh)' => '工序号',
  1183. 'rtrim(c.Gy0_gxmc)' => '工序名称',
  1184. 'rtrim(d.Gd_cpmc)' => '产品名称'
  1185. ])
  1186. ->where('a.设备编号', $param['machine'])
  1187. ->order('a.UniqId desc')
  1188. ->find();
  1189. $data['machine'] = [
  1190. '日期' => $machineDetail['开工时间'],
  1191. '设备' => $machineDetail['设备编号'].'-->'.$machineDetail['设备名称'],
  1192. '工单' => $machineDetail['工单编号'].'-->'.$machineDetail['产品名称'],
  1193. '工艺' => ($machineDetail['工序号']<10?'0'.$machineDetail['工序号']:$machineDetail['工序号']).'--'.$machineDetail['工序名称']
  1194. ];
  1195. //机台状态时间
  1196. $startTime = \db('设备_产量采集')
  1197. ->where('设备编号',$param['machine'])
  1198. ->where('开工时间',$param['start'])
  1199. ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
  1200. ->group('当前状态')
  1201. ->select();
  1202. if (!empty($startTime)){
  1203. foreach ($startTime as $key=>$value){
  1204. $data['timeDifference'][$key] = [
  1205. '时间' => round((strtotime($value['最大时间'])-strtotime($value['时间']))/3600,2),
  1206. '状态' => $value['状态'] = null?'待单':$value['状态'],
  1207. ];
  1208. if ($value['状态'] === '生产'){
  1209. $data['当班产量'] = $value['最大产量']-$value['当班产量'];
  1210. }
  1211. }
  1212. }else{
  1213. $data['timeDifference'][0] = [
  1214. '时间' => 0,
  1215. '状态' => '待单'
  1216. ];
  1217. $data['当班产量'] = 0;
  1218. }
  1219. //机台产能/时间明细
  1220. $row = \db('设备_产量采集')
  1221. ->where('设备编号',$param['machine'])
  1222. ->where('开工时间',$param['start'])
  1223. ->where('当班产量','<>',-1)
  1224. ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
  1225. ->select();
  1226. if (empty($row)){
  1227. $data['row'] = [];
  1228. }
  1229. foreach ($row as $key=>$value){
  1230. $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
  1231. $data['row'][$key]['状态'] = $value['状态'];
  1232. if ($key<2){
  1233. $data['row'][$key]['产能'] = 0;
  1234. }else{
  1235. $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
  1236. }
  1237. }
  1238. //机台状态
  1239. $status = end($row);
  1240. if (empty($status['状态'])){
  1241. $data['status'] = '待单';
  1242. }else{
  1243. $data['status'] = $status['状态'];
  1244. }
  1245. //检验数据
  1246. $list = \db('制程检验_记录')
  1247. ->where('开工时间',$param['start'])
  1248. ->where('设备编号',$param['machine'])
  1249. ->where('sys_rq','>',$param['start'])
  1250. ->where('工单编号',$machineDetail['工单编号'])
  1251. ->field('rtrim(类别) as 类别,提交时间')
  1252. ->select();
  1253. $data['首件'] = $data['自检'] = $data['IPQC'] = [];
  1254. if (!empty($list)){
  1255. foreach ($list as $key=>$value){
  1256. if ($value['类别'] == '首件与过程确认'){
  1257. array_push($data['首件'],$value['提交时间']);
  1258. }
  1259. if ($value['类别'] == '机台检验'){
  1260. array_push($data['自检'],$value['提交时间']);
  1261. }
  1262. if ($value['类别'] == 'IPQC检验'){
  1263. array_push($data['IPQC'],$value['提交时间']);
  1264. }
  1265. }
  1266. $data['首件'] = array_values(array_unique($data['首件']));
  1267. $data['自检'] = array_values(array_unique($data['自检']));
  1268. $data['IPQC'] = array_values(array_unique($data['IPQC']));
  1269. }else{
  1270. $data['首件'] = [];
  1271. $data['自检'] = [];
  1272. $data['IPQC'] = [];
  1273. }
  1274. $this->success('成功',$data);
  1275. }
  1276. /**
  1277. * 制程检验记录->检验项目
  1278. * @ApiMethod (GET)
  1279. * @param void
  1280. * @return void
  1281. * @throws \think\db\exception\DataNotFoundException
  1282. * @throws \think\db\exception\ModelNotFoundException
  1283. * @throws \think\exception\DbException
  1284. */
  1285. public function ProcessInspectionRecordsItem()
  1286. {
  1287. if ($this->request->isGet() === false){
  1288. $this->error('请求错误');
  1289. }
  1290. $param = $this->request->param();
  1291. if (empty($param)){
  1292. $this->error('参数错误');
  1293. }
  1294. $list = \db('制程检验_项目')
  1295. ->where('工序','like','%'.$param['process'].'%')
  1296. ->select();
  1297. if (empty($list)){
  1298. $this->success('未找到检测项目');
  1299. }
  1300. $data = [];
  1301. foreach ($list as $key=>$value){
  1302. $data['首件']['指标检验'][$key] = [
  1303. '检验项目' => rtrim($value['检测项目']),
  1304. '检测方法' => rtrim($value['检测方法']),
  1305. '检验频率' => rtrim($value['首件签样要求']),
  1306. '相关标准' => rtrim($value['技术要求'])
  1307. ];
  1308. $data['机台检验']['指标检验'][$key] = [
  1309. '检验项目' => rtrim($value['检测项目']),
  1310. '检测方法' => rtrim($value['检测方法']),
  1311. '检验频率' => rtrim($value['机台自检频率']),
  1312. '相关标准' => rtrim($value['技术要求'])
  1313. ];
  1314. $data['IPQC']['指标检验'][$key] = [
  1315. '检验项目' => rtrim($value['检测项目']),
  1316. '检测方法' => rtrim($value['检测方法']),
  1317. '检验频率' => rtrim($value['IPQC检验频率']),
  1318. '相关标准' => rtrim($value['技术要求'])
  1319. ];
  1320. }
  1321. $row = \db('制程检验_项目附加')
  1322. ->where('工序','like','%'.$param['process'].'%')
  1323. ->select();
  1324. foreach ($row as $key=>$value){
  1325. $data['首件']['附加'][$key] = [
  1326. '缺陷备注' => rtrim($value['缺陷备注']),
  1327. '编号' => rtrim($value['编号'])
  1328. ];
  1329. $data['机台检验']['附加'][$key] = [
  1330. '缺陷备注' => rtrim($value['缺陷备注']),
  1331. '编号' => rtrim($value['编号'])
  1332. ];
  1333. $data['IPQC']['附加'][$key] = [
  1334. '缺陷备注' => rtrim($value['缺陷备注']),
  1335. '编号' => rtrim($value['编号'])
  1336. ];
  1337. }
  1338. $this->success('成功',$data);
  1339. }
  1340. /**
  1341. * 制程检验记录->检测记录添加
  1342. * @ApiMethod (POST)
  1343. * @param void
  1344. * @return void
  1345. * @throws \think\db\exception\DataNotFoundException
  1346. * @throws \think\db\exception\ModelNotFoundException
  1347. * @throws \think\exception\DbException
  1348. */
  1349. public function ProcessInspectionRecordsItemAdd()
  1350. {
  1351. if (Request::instance()->isPost() === false){
  1352. $this->error('请求错误');
  1353. }
  1354. $param = Request::instance()->post();
  1355. if (empty($param)){
  1356. $this->error('参数错误');
  1357. }
  1358. $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
  1359. if (empty($startID)){
  1360. $startID = 0;
  1361. }
  1362. $process = \db('工单_工艺资料')
  1363. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1364. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1365. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1366. ->find();
  1367. $startTime = \db('设备_产量采集')
  1368. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1369. ->where('工单编号',$param[0]['workOrder'])
  1370. ->order('UniqId desc')
  1371. ->find();
  1372. if ((int)$process['gxh']<10){
  1373. $process['gxh'] = '0'.$process['gxh'];
  1374. }
  1375. if ($process['add_gxmc'] !== ''){
  1376. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1377. }else{
  1378. $printName = $process['gxh'].'-'.$process['gxmc'];
  1379. }
  1380. if (empty($process)){
  1381. $this->success('数据错误');
  1382. }
  1383. $data = [];
  1384. foreach ($param as $key=>$value){
  1385. $data[$key] = [
  1386. '类别' => $value['category'],
  1387. '工单编号' => $value['workOrder'],
  1388. '印件号' => $value['yjno'],
  1389. '工序名称' => $printName,
  1390. '流程单号' => $value['flow'],
  1391. '设备编号' => $value['machine'].'#',
  1392. '班组编号' => $startTime['班组编号'],
  1393. '检验项目' => $value['item'],
  1394. '相关标准' => $value['standard'],
  1395. '量测仪器' => $value['instrument'],
  1396. '检验结果' => $value['result'],
  1397. '检验备注' => $value['remark'],
  1398. '提交时间' => date('Y-m-d H:i:s',time()),
  1399. '开工时间' => rtrim($startTime['开工时间']),
  1400. 'sys_id' => '',
  1401. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1402. 'mod_rq' => '0000-00-00 00:00:00',
  1403. 'UniqId' => $startID + $key +1
  1404. ];
  1405. }
  1406. $res = \db('制程检验_记录')->insertAll($data);
  1407. if ($res !== false){
  1408. $this->success('成功');
  1409. }else{
  1410. $this->error('失败');
  1411. }
  1412. }
  1413. /**
  1414. * 制程检验记录->附加检验记录添加
  1415. * @ApiMethod (POST)
  1416. * @param void
  1417. * @return void
  1418. * @throws \think\db\exception\DataNotFoundException
  1419. * @throws \think\db\exception\ModelNotFoundException
  1420. * @throws \think\exception\DbException
  1421. */
  1422. public function AdditionalInspectionRecordAdd()
  1423. {
  1424. if (Request::instance()->isPost() === false){
  1425. $this->error('请求错误');
  1426. }
  1427. $param = Request::instance()->post();
  1428. if (empty($param)){
  1429. $this->error('参数错误');
  1430. }
  1431. $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
  1432. if (empty($startID)){
  1433. $startID = 0;
  1434. }
  1435. $process = \db('工单_工艺资料')
  1436. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1437. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1438. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1439. ->find();
  1440. $startTime = \db('设备_产量采集')
  1441. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1442. ->where('工单编号',$param[0]['workOrder'])
  1443. ->order('UniqId desc')
  1444. ->find();
  1445. if ((int)$process['gxh']<10){
  1446. $process['gxh'] = '0'.$process['gxh'];
  1447. }
  1448. if ($process['add_gxmc'] !== ''){
  1449. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1450. }else{
  1451. $printName = $process['gxh'].'-'.$process['gxmc'];
  1452. }
  1453. if (empty($process)){
  1454. $this->success('数据错误');
  1455. }
  1456. $data = [];
  1457. foreach ($param as $key=>$value){
  1458. $data[$key] = [
  1459. '工单编号' => $value['workOrder'],
  1460. '印件号' => $value['yjno'],
  1461. '工序名称' => $printName,
  1462. '流程单号' => $value['flow'],
  1463. '设备编号' => $value['machine'],
  1464. '班组编号' => $startTime['班组编号'],
  1465. '缺陷备注' => $value['remark'],
  1466. '提交时间' => date('Y-m-d H:i:s',time()),
  1467. '开工时间' => rtrim($startTime['开工时间']),
  1468. 'sys_id' => '',
  1469. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1470. 'mod_rq' => '0000-00-00 00:00:00',
  1471. 'UniqId' => $startID + $key +1
  1472. ];
  1473. }
  1474. $res = \db('制程检验_记录附加')->insertAll($data);
  1475. if ($res !== false){
  1476. $this->success('成功');
  1477. }else{
  1478. $this->error('失败');
  1479. }
  1480. }
  1481. /**
  1482. * 客诉记录
  1483. * @ApiMethod (GET)
  1484. * @param void
  1485. * @return void
  1486. * @throws \think\db\exception\DataNotFoundException
  1487. * @throws \think\db\exception\ModelNotFoundException
  1488. * @throws \think\exception\DbException
  1489. */
  1490. public function ComplaintRecord()
  1491. {
  1492. if ($this->request->isGet() === false){
  1493. $this->error('请求错误');
  1494. }
  1495. $param = $this->request->param();
  1496. if (isset($param['productCode'])){
  1497. $where['产品编号'] = $param['productCode'];
  1498. }
  1499. $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
  1500. rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
  1501. rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
  1502. rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
  1503. $list = \db('db_客诉记录')
  1504. ->where($where)
  1505. ->field($filed)
  1506. ->select();
  1507. if (empty($list)){
  1508. $this->success('未找到该产品客诉记录');
  1509. }
  1510. $this->success('成功',$list);
  1511. }
  1512. /**
  1513. * 设置机台班组信息
  1514. * @return void
  1515. * @throws \think\db\exception\DataNotFoundException
  1516. * @throws \think\db\exception\ModelNotFoundException
  1517. * @throws \think\exception\DbException
  1518. */
  1519. public function setMachineTeam()
  1520. {
  1521. if (Request::instance()->isPost() == false) {
  1522. $this->error('非法请求');
  1523. }
  1524. $params = Request::instance()->post();
  1525. if (!isset($params['machine']) || empty($params['machine'] )) {
  1526. $this->error('参数不能为空');
  1527. }
  1528. if (!isset($params['order']) || empty($params['order'])){
  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. $id = $lastData['UniqId']+1;
  1540. $data['当前状态'] = $params['status'];
  1541. $data['时间'] = date('Y-m-d H:i:s');
  1542. $data['设备编号'] = $machine;
  1543. $data['工单编号'] = empty($params['order']) ? '':$params['order'];
  1544. $data['印件号'] = empty($params['yjno']) ? '':$params['yjno'];
  1545. $data['工序号'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  1546. $data['工序名称'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  1547. $data['当班产量'] = $params['production_now'];
  1548. $data['累计产量'] = $params['production_all'];
  1549. $data['班组编号'] = $params['sczl_bzdh'];
  1550. $data['班组ID'] = $params['team_id'];
  1551. // 获取当前时间
  1552. $current_time = time();
  1553. // 设置时间范围
  1554. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  1555. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  1556. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  1557. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  1558. // 判断当前时间属于哪个时间范围
  1559. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  1560. $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
  1561. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  1562. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1563. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  1564. $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  1565. }
  1566. if (!empty($params['order']) && !empty($params['yjno'])){
  1567. $option['Gy0_gdbh'] = $params['order'];
  1568. $option['Gy0_yjno'] = $params['yjno'];
  1569. $option['Gy0_gxh'] = $data['工序号'];
  1570. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  1571. }else{
  1572. $data['任务ID'] = '';
  1573. }
  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. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1840. $data = $param;
  1841. unset($data['UniqId']);
  1842. $sql = \db('设备_产量计酬')
  1843. ->where('UniqId',$param['UniqId'])
  1844. ->fetchSql(true)
  1845. ->update($data);
  1846. $res = \db()->query($sql);
  1847. if ($res !== false){
  1848. $this->success('修改成功');
  1849. }else {
  1850. $this->error('修改失败');
  1851. }
  1852. }
  1853. /**
  1854. * 获取当日上报产量详细数据
  1855. * @return void
  1856. * @throws \think\db\exception\DataNotFoundException
  1857. * @throws \think\db\exception\ModelNotFoundException
  1858. * @throws \think\exception\DbException
  1859. */
  1860. public function MachineChanliangDetail()
  1861. {
  1862. if ($this->request->isGet() === false){
  1863. $this->error('请求错误');
  1864. }
  1865. $param = $this->request->param();
  1866. if (empty($param['UniqId'])){
  1867. $this->error('参数错误');
  1868. }
  1869. $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 联数,
  1870. 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 来料异常,
  1871. rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
  1872. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
  1873. rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,rtrim(sczl_装版工时) as 装版补产工时,rtrim(sczl_打样工时) as 打样补产工时,
  1874. 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,
  1875. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId';
  1876. $list = \db('设备_产量计酬')->where('UniqId',$param['UniqId'])->field($field)->find();
  1877. if (empty($list)){
  1878. $this->success('未找到产量详情信息');
  1879. }
  1880. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$list['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  1881. $list['印件名称'] = $productName['cpmc'];
  1882. if (!empty($productName['成品名称'])){
  1883. $list['cpmc'] = $productName['成品名称'];
  1884. }elseif (empty($productName['成品名称']) && !empty($productName['cpmc'])){
  1885. $list['cpmc'] = $productName['cpmc'];
  1886. }else{
  1887. $list['cpmc'] = '';
  1888. }
  1889. for ($i=1;$i<11;$i++){
  1890. if (isset($list['sczl_bh'.$i])){
  1891. $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  1892. if (isset($name['name'])){
  1893. $list['组员'.$i] = [
  1894. '编号' => $list['sczl_bh'.$i],
  1895. '姓名' => $name['name'],
  1896. '比例' => ((float)$list['sczl_rate'.$i]*100).'%'
  1897. ];
  1898. }
  1899. }
  1900. if (empty($list['sczl_bh'.$i])){
  1901. $list['组员'.$i] = [
  1902. '编号' => '',
  1903. '姓名' => '',
  1904. '比例' => ''
  1905. ];
  1906. }
  1907. unset($list['sczl_bh'.$i],$list['sczl_rate'.$i]);
  1908. }
  1909. $list['拉料'] = [
  1910. '编号' => $list['sczl_bh98'],
  1911. '姓名' => \db('人事_基本资料')->where('员工编号',$list['sczl_bh98'])->value('rtrim(员工姓名)')
  1912. ];
  1913. unset($list['sczl_bh98']);
  1914. $this->success('成功',$list);
  1915. }
  1916. /**
  1917. * 当日上报产量详细数据修改
  1918. * @return void
  1919. * @throws \think\Exception
  1920. * @throws \think\db\exception\BindParamException
  1921. * @throws \think\exception\PDOException
  1922. */
  1923. public function MachineChanliangDetailEdit()
  1924. {
  1925. if (Request::instance()->isPost() === false){
  1926. $this->error('请求错误');
  1927. }
  1928. $param = Request::instance()->post();
  1929. if (empty($param['UniqId'])){
  1930. $this->error('参数错误');
  1931. }
  1932. $param['sczl_type'] = $param['sczl_gxmc'];
  1933. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1934. $UnidId = $param['UniqId'];
  1935. unset($param['UniqId']);
  1936. $sql = \db('设备_产量计酬')->where('UniqId',$UnidId)->fetchSql(true)->update($param);
  1937. $res = \db()->query($sql);
  1938. if ($res !== false){
  1939. $this->success('修改成功');
  1940. }else{
  1941. $this->error('修改失败');
  1942. }
  1943. }
  1944. /**
  1945. * 产量上报数据删除
  1946. * @return void
  1947. * @throws \think\Exception
  1948. * @throws \think\exception\PDOException
  1949. */
  1950. public function ChanliangDel()
  1951. {
  1952. if ($this->request->isGet() === false){
  1953. $this->error('请求错误');
  1954. }
  1955. $param = $this->request->param();
  1956. if (empty($param['UniqId'])){
  1957. $this->error('参数错误');
  1958. }
  1959. $idList = explode(',',$param['UniqId']);
  1960. foreach ($idList as $key=>$value){
  1961. $res = \db('设备_产量计酬')
  1962. ->where('UniqId',$value)
  1963. ->delete();
  1964. }
  1965. if ($res !== false){
  1966. $this->success('删除成功');
  1967. }else{
  1968. $this->error('删除失败');
  1969. }
  1970. }
  1971. /**
  1972. * 日产量上报添加
  1973. * @return void
  1974. * @throws \think\db\exception\BindParamException
  1975. * @throws \think\exception\PDOException
  1976. */
  1977. public function ChanliangAdd()
  1978. {
  1979. if (Request::instance()->isPost() === false){
  1980. $this->error('请求错误');
  1981. }
  1982. $params = Request::instance()->post();
  1983. if (empty($params['sczl_gdbh'])){
  1984. $this->error('参数错误');
  1985. }
  1986. $lastId = \db('设备_产量计酬')->order('UniqId desc')->value('rtrim(UniqId)');
  1987. $params['sczl_type'] = $params['sczl_gxmc'];
  1988. $params['sczl_wgsj'] = '1900-01-01 00:00:00';
  1989. $params['sczl_废品率系数'] = 0;
  1990. $params['sys_rq'] = date('Y-m-d H:i:s',time());
  1991. $params['mod_rq'] = date('Y-m-d H:i:s',time());
  1992. $params['UniqId'] = $lastId + 1;
  1993. $sql = \db('设备_产量计酬')->fetchSql(true)->insert($params);
  1994. $res = \db()->query($sql);
  1995. if ($res !== false){
  1996. $this->success('成功');
  1997. }else{
  1998. $this->error('失败');
  1999. }
  2000. }
  2001. /**
  2002. * 日产量上报添加获取工单信息
  2003. * @return void
  2004. * @throws \think\db\exception\DataNotFoundException
  2005. * @throws \think\db\exception\ModelNotFoundException
  2006. * @throws \think\exception\DbException
  2007. */
  2008. public function ChanliangWorkorder()
  2009. {
  2010. if ($this->request->isGet() === false)
  2011. {
  2012. $this->error('请求错误');
  2013. }
  2014. $param = $this->request->param();
  2015. if (empty($param)){
  2016. $this->error('参数错误');
  2017. }
  2018. // $where = [
  2019. // 'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
  2020. // ];
  2021. // if (!empty($param['machine'])){
  2022. // $where = [
  2023. // 'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
  2024. // ];
  2025. // }
  2026. if (!empty($param['search'])){
  2027. $where['b.Gy0_gdbh'] = ['like','%'.$param['search'].'%'];
  2028. }
  2029. $list = \db('工单_基本资料')
  2030. ->alias('a')
  2031. ->field('rtrim(Gd_gdbh) as gdbh,rtrim(成品名称) as cpmc')
  2032. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  2033. ->where($where)
  2034. ->select();
  2035. if (empty($list)){
  2036. $this->success('未找到相关工单');
  2037. }else{
  2038. $this->success('成功',$list);
  2039. }
  2040. }
  2041. /**
  2042. * 日产量上报工单印件资料
  2043. * @return void
  2044. * @throws \think\db\exception\DataNotFoundException
  2045. * @throws \think\db\exception\ModelNotFoundException
  2046. * @throws \think\exception\DbException
  2047. */
  2048. public function ChanliangPrintDetail()
  2049. {
  2050. if ($this->request->isGet() === false){
  2051. $this->error('请求错误');
  2052. }
  2053. $param = $this->request->param();
  2054. if (empty($param['gdbh'])){
  2055. $this->error('参数错误');
  2056. }
  2057. $where = [
  2058. 'Yj_Gdbh' => $param['gdbh']
  2059. ];
  2060. $list = \db('工单_印件资料')
  2061. ->where($where)
  2062. ->field('rtrim(yj_Yjno) as yjno,rtrim(yj_yjmc) as yjmc,rtrim(yj_ls) as ls')
  2063. ->select();
  2064. if (empty($list)){
  2065. $this->success('未找到印件资料');
  2066. }else{
  2067. $this->success('成功',$list);
  2068. }
  2069. }
  2070. /**
  2071. * 日产量上报工艺资料获取
  2072. * @return void
  2073. * @throws \think\db\exception\DataNotFoundException
  2074. * @throws \think\db\exception\ModelNotFoundException
  2075. * @throws \think\exception\DbException
  2076. */
  2077. public function ChanliangProcessDetail()
  2078. {
  2079. if ($this->request->isGet() === false){
  2080. $this->error('请求错误');
  2081. }
  2082. $param = $this->request->param();
  2083. if (empty($param['gdbh'])){
  2084. $this->error('参数错误');
  2085. }
  2086. // $sys_bh = \db('dic_lzde')->where('适用机型',$param['machine'])->value('sys_bh');
  2087. $list = \db('工单_工艺资料')
  2088. ->where('Gy0_gdbh',$param['gdbh'])
  2089. ->where('Gy0_yjno',$param['yjno'])
  2090. // ->where('Gy0_sbbh','like','%'.$param['machine'].'%')
  2091. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  2092. ->select();
  2093. if (empty($list)){
  2094. $this->success('未获取工序');
  2095. }
  2096. // $time = \db('设备_产量计酬')
  2097. // ->where('sczl_gdbh',$param['gdbh'])
  2098. // ->where('sczl_yjno',$param['yjno'])
  2099. // ->where('sczl_jtbh','like','%'.$param['machine'].'%')
  2100. // ->order('UniqId desc')
  2101. // ->value('sczl_sj2');
  2102. // $newTime = date('Y-m-d H:i:s');
  2103. // 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')){
  2104. // $time = date('Y-m-d 08:30:00');
  2105. // }elseif ($newTime > date('Y-m-d 20:30:00') && $time < date('Y-m-d 20:30:00')){
  2106. // $time = date('Y-m-d 20:30:00');
  2107. // }
  2108. foreach ($list as $key=>$value){
  2109. if ((int)$value['gxh'] < 10){
  2110. $value['gxh'] = '0'.$value['gxh'];
  2111. }
  2112. if (empty($value['add_gxmc'])){
  2113. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'];
  2114. }else{
  2115. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  2116. }
  2117. unset( $list[$key]['add_gxmc']);
  2118. // $list[$key]['time'] = $time;
  2119. }
  2120. // $list['sys_bh'] = $sys_bh;
  2121. $this->success('成功',$list);
  2122. }
  2123. /**
  2124. * 工价系数修改
  2125. * @return void
  2126. * @throws \think\Exception
  2127. * @throws \think\db\exception\BindParamException
  2128. * @throws \think\exception\PDOException
  2129. */
  2130. public function CoefficientEdit()
  2131. {
  2132. if (Request::instance()->isPost() === false){
  2133. $this->error('请求错误');
  2134. }
  2135. $params = Request::instance()->post();
  2136. if (empty($params['id'])){
  2137. $this->error('参数错误');
  2138. }
  2139. $idList = explode(',',$params['id']);
  2140. $i=0;
  2141. foreach ($idList as $key=>$value){
  2142. $sql = \db('设备_产量计酬')
  2143. ->where('UniqId',$value)
  2144. ->fetchSql(true)
  2145. ->update(['sczl_工价系数'=>$params['工价系数']]);
  2146. $res = \db()->query($sql);
  2147. if ($res === false){
  2148. $i++;
  2149. }
  2150. }
  2151. if ($i!==0){
  2152. $this->error('修改失败');
  2153. }else{
  2154. $this->success('修改成功');
  2155. }
  2156. }
  2157. /**
  2158. * 色度系数修改
  2159. * @return void
  2160. * @throws \think\Exception
  2161. * @throws \think\db\exception\BindParamException
  2162. * @throws \think\exception\PDOException
  2163. */
  2164. public function ChromaDataEdit()
  2165. {
  2166. if (Request::instance()->isPost() === false){
  2167. $this->error('请求错误');
  2168. }
  2169. $params = Request::instance()->post();
  2170. if (empty($params['id'])){
  2171. $this->error('参数错误');
  2172. }
  2173. $idList = explode(',',$params['id']);
  2174. $i=0;
  2175. foreach ($idList as $key=>$value){
  2176. $sql = \db('设备_产量计酬')
  2177. ->where('UniqId',$value)
  2178. ->fetchSql(true)
  2179. ->update(['sczl_ms'=>$params['ms']]);
  2180. $res = \db()->query($sql);
  2181. if ($res === false){
  2182. $i++;
  2183. }
  2184. }
  2185. if ($i!==0){
  2186. $this->error('修改失败');
  2187. }else{
  2188. $this->success('修改成功');
  2189. }
  2190. }
  2191. /**
  2192. * 凹印版距修改
  2193. * @return void
  2194. * @throws \think\Exception
  2195. * @throws \think\db\exception\BindParamException
  2196. * @throws \think\exception\PDOException
  2197. */
  2198. public function PrintingModeDataEdit()
  2199. {
  2200. if (Request::instance()->isPost() === false){
  2201. $this->error('请求错误');
  2202. }
  2203. $params = Request::instance()->post();
  2204. if (empty($params['id'])){
  2205. $this->error('参数错误');
  2206. }
  2207. $idList = explode(',',$params['id']);
  2208. //获取工单印件工序
  2209. $orderList = \db('设备_产量计酬')
  2210. ->where('UniqId',$idList[0])
  2211. ->field('rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as 印件号,rtrim(sczl_gxh) as 工序号')
  2212. ->find();
  2213. //修改工艺资料
  2214. $sql = \db('工单_工艺资料')
  2215. ->where([
  2216. 'Gy0_gdbh'=>$orderList['工单编号'],
  2217. 'Gy0_yjno'=>$orderList['印件号'],
  2218. 'Gy0_gxh'=>$orderList['工序号']
  2219. ])
  2220. ->fetchSql(true)
  2221. ->update(['版距'=>$params['plate'],'印刷方式'=>$params['mode']]);
  2222. $res = \db()->query($sql);
  2223. if ($res === false){
  2224. $this->error('修改失败');
  2225. }else{
  2226. $this->success('修改成功');
  2227. }
  2228. }
  2229. /**
  2230. * 废品率系数批量修改
  2231. * @return void
  2232. * @throws \think\Exception
  2233. * @throws \think\db\exception\BindParamException
  2234. * @throws \think\exception\PDOException
  2235. */
  2236. public function RejectionEdit()
  2237. {
  2238. if (Request::instance()->isPost() === false){
  2239. $this->error('请求错误');
  2240. }
  2241. $params = Request::instance()->post();
  2242. if (empty($params['id'])){
  2243. $this->error('参数错误');
  2244. }
  2245. $idList = explode(',',$params['id']);
  2246. $i=0;
  2247. foreach ($idList as $key=>$value){
  2248. $sql = \db('设备_产量计酬')
  2249. ->where('UniqId',$value)
  2250. ->fetchSql(true)
  2251. ->update(['sczl_废品率系数'=>$params['rejection']]);
  2252. $res = \db()->query($sql);
  2253. if ($res === false){
  2254. $i++;
  2255. }
  2256. }
  2257. if ($i!==0){
  2258. $this->error('修改失败');
  2259. }else{
  2260. $this->success('修改成功');
  2261. }
  2262. }
  2263. /**
  2264. * 日产量上报班组信息批量修改
  2265. * @return void
  2266. * @throws \think\Exception
  2267. * @throws \think\db\exception\BindParamException
  2268. * @throws \think\db\exception\DataNotFoundException
  2269. * @throws \think\db\exception\ModelNotFoundException
  2270. * @throws \think\exception\DbException
  2271. * @throws \think\exception\PDOException
  2272. */
  2273. public function YieldTeamEdit()
  2274. {
  2275. if ($this->request->isGet() === false){
  2276. $this->error('请求错误');
  2277. }
  2278. $param = $this->request->param();
  2279. if (empty($param['Uniqid']) || empty($param['teamID'])){
  2280. $this->error('参数错误');
  2281. }
  2282. $idList = explode(',',$param['Uniqid']);
  2283. $teamList = \db('设备_班组资料')->where('UniqId',$param['teamID'])->find();
  2284. $data = [];
  2285. for ($i=1;$i<11;$i++){
  2286. $data['sczl_bh'.$i] = $teamList['sczl_bh'.$i];
  2287. $data['sczl_rate'.$i] = $teamList['sczl_rate'.$i];
  2288. $data['sczl_bzdh'] = $teamList['sczl_bzdh'];
  2289. }
  2290. $j = 0;
  2291. foreach ($idList as $key => $value){
  2292. $sql = \db('设备_产量计酬')
  2293. ->where('UniqId',$value)
  2294. ->fetchSql(true)
  2295. ->update($data);
  2296. $res = \db()->query($sql);
  2297. if ($res === false){
  2298. $j++;
  2299. }
  2300. }
  2301. if ($j === 0){
  2302. $this->success('修改成功');
  2303. }else{
  2304. $this->error('修改失败');
  2305. }
  2306. }
  2307. /**
  2308. * 检品机日产量上报数据修改
  2309. * @return void
  2310. * @throws \think\Exception
  2311. * @throws \think\db\exception\BindParamException
  2312. * @throws \think\exception\PDOException
  2313. */
  2314. public function JpChanliangEdit()
  2315. {
  2316. if (Request::instance()->isPost() == false){
  2317. $this->error('非法请求');
  2318. }
  2319. $params = Request::instance()->post();
  2320. if (empty($params['UniqId'])){
  2321. $this->error('参数错误');
  2322. }
  2323. $params['mod_rq'] = date('Y-m-d H:i:s');
  2324. $data = $params;
  2325. $data['sczl_装版总工时'] = $params['sczl_装版工时'];
  2326. unset($data['UniqId']);
  2327. $sql = \db('设备_产量计酬')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
  2328. $res = \db()->query($sql);
  2329. if ($res === false){
  2330. $this->error('修改失败');
  2331. }else{
  2332. $this->success('成功');
  2333. }
  2334. }
  2335. /**
  2336. * 检品机日产量上报数据列表
  2337. * @return void
  2338. * @throws \think\db\exception\DataNotFoundException
  2339. * @throws \think\db\exception\ModelNotFoundException
  2340. * @throws \think\exception\DbException
  2341. */
  2342. public function JPmachineDetail()
  2343. {
  2344. if ($this->request->isGet() === false){
  2345. $this->error('请求错误');
  2346. }
  2347. $machine = input('machine');
  2348. $date = input('date');
  2349. $where = [
  2350. 'sczl_jtbh' => $machine,
  2351. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  2352. ];
  2353. $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_type) as 检验类型,rtrim(sczl_num) as num,rtrim(sczl_cl) as 计件箱数,
  2354. rtrim(sczl_Pgcl) as 每箱数量,rtrim(sczl_bzdh) as bzdh,IF(sczl_废品率系数 = 0, "",sczl_废品率系数) as 废品率系数,IF(sczl_装版工时 = 0, "",sczl_装版工时) as 换膜补时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
  2355. rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  2356. 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,
  2357. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,rtrim(sczl_dedh) as 定额代号,sczl_rq,sczl_装版总工时 as 换膜总工时';
  2358. //机台信息
  2359. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  2360. //组员信息
  2361. $list = \db('设备_产量计酬')->where($where)->field($field)->select();
  2362. $totalA = \db('设备_产量计酬')
  2363. ->where($where)
  2364. ->where('sczl_bzdh','like','A%')
  2365. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数')
  2366. ->group('检验类型')
  2367. ->select();
  2368. $totalB = \db('设备_产量计酬')
  2369. ->where($where)
  2370. ->where('sczl_bzdh','like','B%')
  2371. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数')
  2372. ->group('检验类型')
  2373. ->select();
  2374. if (empty($list)){
  2375. $this->success('',[]);
  2376. }
  2377. foreach ($list as $key=>$value){
  2378. //产品名称
  2379. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  2380. if (!empty($productName)){
  2381. if (!empty($productName['成品名称'])){
  2382. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
  2383. $list[$key]['cpmc'] = $productName['成品名称'];
  2384. }else{
  2385. $list[$key]['产品名称'] = $value['工单编号'];
  2386. $list[$key]['cpmc'] = '';
  2387. }
  2388. }else{
  2389. $list[$key]['产品名称'] = $value['工单编号'];
  2390. $list[$key]['cpmc'] = '';
  2391. }
  2392. if (empty($value['定额代号'])){
  2393. $list[$key]['千件工价'] = '';
  2394. $list[$key]['日定额'] = '';
  2395. $list[$key]['补产标准'] = '';
  2396. }else{
  2397. $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
  2398. $list[$key]['千件工价'] = $row['千件工价'];
  2399. $list[$key]['日定额'] = $row['日定额'];
  2400. $list[$key]['补产标准'] = $row['补产标准'];
  2401. }
  2402. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
  2403. for ($i=1;$i<11;$i++){
  2404. if (isset($value['sczl_bh'.$i])){
  2405. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('员工姓名 as name')->find();
  2406. if (isset($name['name'])){
  2407. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  2408. $list[$key]['sczl_name'.$i] = $name['name'];
  2409. }else{
  2410. $list[$key]['sczl_name'.$i] = '';
  2411. }
  2412. }
  2413. }
  2414. }
  2415. $list['totalA'] = $totalA;
  2416. $list['totalB'] = $totalB;
  2417. $this->success('成功',$list);
  2418. }
  2419. }