WorkOrderVerification.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Request;
  5. use \think\Db;
  6. use \think\cache;
  7. /**
  8. * 工单核验单维护接口
  9. */
  10. class WorkOrderVerification extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * 首页
  16. *
  17. */
  18. public function index()
  19. {
  20. $this->success('请求成功');
  21. }
  22. /**
  23. * 获取工单核验单侧边栏
  24. * @ApiMethod (GET)
  25. */
  26. public function getTab()
  27. {
  28. //get请求
  29. if(!$this->request->isGet()){
  30. $this->error('请求方式错误');
  31. }
  32. if(!cache('WorkOrderVerification-getTable')){
  33. $time = date('Y-m-d',time()-8640000);
  34. $rows = db()->table('db_qczl')
  35. ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  36. ->where('sys_rq','>=',$time)
  37. ->group('date')
  38. ->order('date desc')
  39. ->limit(30)
  40. ->select();
  41. $arr = db()->table('db_qczl')
  42. ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count')
  43. ->where('sys_rq','>=',$rows[count($rows)-1]['date'])
  44. ->group('date, sys_id')
  45. ->select();
  46. foreach($rows as $key=>$value){
  47. $rows[$key]['sys'] = [];
  48. foreach($arr as $k=>$v){
  49. if($value['date'] == $v['date']){
  50. unset($v['date']);
  51. array_push($rows[$key]['sys'],$v);
  52. unset($arr[$k]);
  53. }
  54. }
  55. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  56. }
  57. //设置缓存
  58. cache('WorkOrderVerification-getTable',$rows,3600);
  59. }else{
  60. $rows = cache('WorkOrderVerification-getTable');
  61. }
  62. $this->success('成功',$rows);
  63. }
  64. /**
  65. * 获取工单核验单侧边栏通过工单编号
  66. * @ApiMethod (GET)
  67. */
  68. public function getTabByGdbh()
  69. {
  70. //get请求
  71. if(!$this->request->isGet()){
  72. $this->error('请求方式错误');
  73. }
  74. $date = date('Y-m-d',strtotime("-1 year"));
  75. $rows = db()->table('db_qczl')->alias('d')
  76. ->field('d.qczl_gdbh, rtrim(y.Gd_cpmc) as Gd_cpmc')
  77. ->join('工单_基本资料 y','y.Gd_gdbh = d.qczl_gdbh','left')
  78. ->where('d.sys_rq','>=',$date)
  79. ->group('d.qczl_gdbh')
  80. ->order('d.qczl_gdbh desc')
  81. ->limit(65)
  82. ->select();
  83. $arr = db()->table('db_qczl')
  84. ->field('qczl_gdbh, rtrim(sys_id) as sys_id, COUNT(*) as count')
  85. ->where('qczl_gdbh','>=',$rows[count($rows)-1]['qczl_gdbh'])
  86. ->group('qczl_gdbh, sys_id')
  87. ->select();
  88. foreach($rows as $key=>$value){
  89. $rows[$key]['sys'] = [];
  90. foreach($arr as $k=>$v){
  91. if($value['qczl_gdbh'] == $v['qczl_gdbh']){
  92. unset($v['qczl_gdbh']);
  93. array_push($rows[$key]['sys'],$v);
  94. unset($arr[$k]);
  95. }
  96. }
  97. }
  98. $this->success('成功',$rows);
  99. }
  100. /**
  101. * 获取工单核验单列表
  102. * @ApiMethod (GET)
  103. * @param string $date 时间
  104. * @param string $sys_id 用户
  105. */
  106. public function getList()
  107. {
  108. //get请求
  109. if(!$this->request->isGet()){
  110. $this->error('请求方式错误');
  111. }
  112. $req = $this->request->param();
  113. $page = 1;
  114. $limit = 15;
  115. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  116. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  117. $where = [];
  118. if (isset($req['date']) && !empty($req['date'])){
  119. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  120. }
  121. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE',$req['sys_id'].'%'];
  122. if (isset($req['order']) && !empty($req['order'])) $where['qczl_gdbh'] = $req['order'];
  123. if (isset($req['cpmc']) && !empty($req['cpmc'])){
  124. //查询工单表
  125. $gd = db('工单_基本资料')
  126. ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
  127. ->column('Gd_gdbh');
  128. $where['qczl_gdbh'] = ['in', $gd];
  129. }
  130. $rows = db()->table('db_qczl')
  131. ->field('qczl_gdbh, qczl_yjno, LEFT(qczl_rq, 10) as qczl_rq, qczl_num, rtrim(qczl_NumDesc) as qczl_NumDesc, qczl_fp,
  132. fp_lb1, fp_lb2, fp_lb3, fp_lb4, fp_lb5, fp_lb6, fp_lb7, fp_lb8, fp_lb9, fp_lb10, fp_lb11, fp_lb12, fp_lb13, fp_lb14, fp_lb15, fp_lb16, fp_lb17,
  133. fp_sl1, fp_sl2, fp_sl3, fp_sl4, fp_sl5, fp_sl6, fp_sl7, fp_sl8, fp_sl9, fp_sl10, fp_sl11, fp_sl12, fp_sl13, fp_sl14, fp_sl15, fp_sl16, fp_sl17,
  134. fp_bh1, fp_bh2, fp_bh3, fp_bh4, fp_bh5, fp_bh6, fp_bh7, fp_bh8, fp_bh9, fp_bh10, fp_bh11, fp_bh12, fp_bh13,
  135. rtrim(sys_id) as sys_id,UniqId')
  136. ->where($where)
  137. ->order('qczl_gdbh,qczl_yjno,qczl_num')
  138. ->page($page,$limit)
  139. ->select();
  140. $total = db()->table('db_qczl')->where($where)->count();
  141. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  142. foreach ($rows as $key=>$value){
  143. $rows[$key]['Gd_cpmc'] = array_key_exists($value['qczl_gdbh'],$gd) ? sprintf("%02d", $value['qczl_yjno']).'-'.trim($gd[$value['qczl_gdbh']]) : '';
  144. for ($i=1;$i<=17;$i++){
  145. if ($value['fp_sl'.$i]==0){
  146. $rows[$key]['sl_lb'.$i] = '';
  147. }else{
  148. $rows[$key]['sl_lb'.$i] = trim($value['fp_sl'.$i].'-->'.$value['fp_lb'.$i].'('.$value['fp_bh'.$i].')');
  149. }
  150. unset($rows[$key]['fp_sl'.$i]);
  151. unset($rows[$key]['fp_lb'.$i]);
  152. }
  153. }
  154. $data = [
  155. 'total' => $total,
  156. 'rows' => $rows,
  157. ];
  158. $this->success('成功',$data);
  159. }
  160. /**
  161. * 获取工单核验单信息
  162. * @ApiMethod (GET)
  163. * @param string $UniqId UniqId
  164. */
  165. public function getInfo()
  166. {
  167. //get请求
  168. if(!$this->request->isGet()){
  169. $this->error('请求方式错误');
  170. }
  171. $req = $this->request->param();
  172. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  173. $UniqId = $req['UniqId'];
  174. }else{
  175. $this->error('参数错误');
  176. }
  177. $rows = db()->table('db_qczl')->alias('d')
  178. ->field('d.*, ')
  179. ->join('工单_基本资料 g', 'd.')
  180. ->where('d.UniqId',$UniqId)
  181. ->select();
  182. $this->success('成功',$rows);
  183. }
  184. /**
  185. * 获取单个工单核检单信息
  186. * @ApiMethod GET
  187. * @params string UniqId
  188. */
  189. public function getOneWorkOrder(){
  190. if (Request::instance()->isGet() == false){
  191. $this->error('非法请求');
  192. }
  193. $params = Request::instance()->param();
  194. if (!isset($params['UniqId']) || empty($params['UniqId'])){
  195. $this->error('参数错误');
  196. }
  197. $field = 'qczl_gdbh,qczl_Pygd,qczl_yjno,qczl_gxh,qczl_gxmc,qczl_type,qczl_rq,qczl_num,qczl_fp,
  198. qczl_NumDesc,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8,
  199. fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13,trim(fp_lb14) as fp_lb14,trim(fp_lb15) as fp_lb15,trim(fp_lb16) as fp_lb16,trim(fp_lb17) as fp_lb17,
  200. fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,fp_sl14,fp_sl15,fp_sl16,fp_sl17,
  201. fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
  202. fp_bz1,fp_bz2,fp_bz3,fp_bz4,fp_bz5,fp_bz6,fp_bz7,fp_bz8,fp_bz9,fp_bz10,fp_bz11,fp_bz12,fp_bz13,
  203. fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13,
  204. sys_id,rtrim(sys_rq) as sys_rq,UniqId';
  205. $list = db('db_qczl')->where('UniqId',$params['UniqId'])->field($field)->find();
  206. $list['fp_name1'] = '';
  207. if (!empty($list['fp_bh1'])){
  208. $list['fp_name1'] = db('人事_基本资料')->where('员工编号',$list['fp_bh1'])->value('rtrim(员工姓名)');
  209. }
  210. $list['fp_name2'] = '';
  211. if (!empty($list['fp_bh2'])){
  212. $list['fp_name2'] = db('人事_基本资料')->where('员工编号',$list['fp_bh2'])->value('rtrim(员工姓名)');
  213. }
  214. $list['fp_name3'] = '';
  215. if (!empty($list['fp_bh3'])){
  216. $list['fp_name3'] = db('人事_基本资料')->where('员工编号',$list['fp_bh3'])->value('rtrim(员工姓名)');
  217. }
  218. $list['fp_name4'] = '';
  219. if (!empty($list['fp_bh4'])){
  220. $list['fp_name4'] = db('人事_基本资料')->where('员工编号',$list['fp_bh4'])->value('rtrim(员工姓名)');
  221. }
  222. $list['fp_name5'] = '';
  223. if (!empty($list['fp_bh5'])){
  224. $list['fp_name5'] = db('人事_基本资料')->where('员工编号',$list['fp_bh5'])->value('rtrim(员工姓名)');
  225. }
  226. $list['fp_name6'] = '';
  227. if (!empty($list['fp_bh6'])){
  228. $list['fp_name6'] = db('人事_基本资料')->where('员工编号',$list['fp_bh6'])->value('rtrim(员工姓名)');
  229. }
  230. $list['fp_name7'] = '';
  231. if (!empty($list['fp_bh7'])){
  232. $list['fp_name7'] = db('人事_基本资料')->where('员工编号',$list['fp_bh7'])->value('rtrim(员工姓名)');
  233. }
  234. $list['fp_name8'] = '';
  235. if (!empty($list['fp_bh8'])){
  236. $list['fp_name8'] = db('人事_基本资料')->where('员工编号',$list['fp_bh8'])->value('rtrim(员工姓名)');
  237. }
  238. $list['fp_name9'] = '';
  239. if (!empty($list['fp_bh9'])){
  240. $list['fp_name9'] = db('人事_基本资料')->where('员工编号',$list['fp_bh9'])->value('rtrim(员工姓名)');
  241. }
  242. $list['fp_name10'] = '';
  243. if (!empty($list['fp_bh10'])){
  244. $list['fp_name10'] = db('人事_基本资料')->where('员工编号',$list['fp_bh10'])->value('rtrim(员工姓名)');
  245. }
  246. $list['fp_name11'] = '';
  247. if (!empty($list['fp_bh11'])){
  248. $list['fp_name11'] = db('人事_基本资料')->where('员工编号',$list['fp_bh11'])->value('rtrim(员工姓名)');
  249. }
  250. $list['fp_name12'] = '';
  251. if (!empty($list['fp_bh12'])){
  252. $list['fp_name12'] = db('人事_基本资料')->where('员工编号',$list['fp_bh12'])->value('rtrim(员工姓名)');
  253. }
  254. $list['fp_name13'] = '';
  255. if (!empty($list['fp_bh13'])){
  256. $list['fp_name13'] = db('人事_基本资料')->where('员工编号',$list['fp_bh13'])->value('rtrim(员工姓名)');
  257. }
  258. $max = db('设备_产量计酬')->where('sczl_gdbh',$list['qczl_gdbh'])->field('MAX(sczl_num) as sczl_num')->find();
  259. $list['total_liucheng'] = $max['sczl_num'];
  260. $this->success('请求成功',$list);
  261. }
  262. /**
  263. * 获取工单基本信息
  264. * @ApiMethod GET
  265. * @params string order
  266. */
  267. public function getOrderInfo(){
  268. if (Request::instance()->isGet() == false){
  269. $this->error('非法请求');
  270. }
  271. $params = Request::instance()->param();
  272. if (!isset($params['order']) || empty($params['order'])){
  273. $this->error('参数错误');
  274. }
  275. $list = db('工单_基本资料')->alias('a')
  276. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  277. ->where('a.Gd_gdbh',$params['order'])
  278. // ->where('a.行号',1)
  279. ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc')
  280. ->select();
  281. $this->success('请求成功',$list);
  282. }
  283. /**
  284. * 获取印件名称及工序
  285. * @ApiMethod GET
  286. * @params string order
  287. * @params string yj_no
  288. */
  289. public function getYjInfo(){
  290. if (Request::instance()->isGet() == false){
  291. $this->error('非法请求');
  292. }
  293. $params = Request::instance()->param();
  294. if (!isset($params['order']) || empty($params['order'])){
  295. $this->error('参数错误');
  296. }
  297. if (!isset($params['yj_no']) || empty($params['yj_no'])){
  298. $this->error('参数错误');
  299. }
  300. $where['Yj_Gdbh'] = $params['order'];
  301. $where['yj_Yjno'] = $params['yj_no'];
  302. $list = db('工单_印件资料')->where($where)->field('yj_yjmc')->find();
  303. $option['Gy0_gdbh'] = $params['order'];
  304. $option['Gy0_yjno'] = $params['yj_no'];
  305. $option['Gy0_gxmc|Add_gxmc'] = ['like','%'.'核检'.'%'];
  306. // $option['Gy0_site'] = '印后车间';
  307. // $option['Gy0_gxmc'] = array('not in',['包装','外发加工','废挑正','成品防护']);
  308. $gxList = db('工单_工艺资料')->where($option)->field('Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')->select();
  309. $max = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yj_no'])->field('MAX(sczl_num) as sczl_num')->value('sczl_num');
  310. $list['gx_data'] = $gxList;
  311. $list['max_num'] = $max;
  312. $this->success('请求成功',$list);
  313. }
  314. /**
  315. * 获取废品分类
  316. * @ApiMethod GET
  317. * @params string search
  318. */
  319. public function getWastInfo(){
  320. if (Request::instance()->isGet() == false){
  321. $this->error('非法请求');
  322. }
  323. $params = Request::instance()->param();
  324. $where['分类'] = '废品分类';
  325. if (!empty($params['search'])){
  326. $where['名称'] = array('like','%'.$params['search'].'%');
  327. }
  328. $data = db('erp_常用字典')->where($where)->order('次序 desc')->column('名称');
  329. // 分割字符串并合并相同项
  330. $resultArray = [];
  331. foreach ($data as $item) {
  332. $parts = explode('_', $item);
  333. // 使用第一个部分作为一级键,第二个部分作为二级键
  334. $firstKey = $parts[0];
  335. $secondKey = $parts[1];
  336. $thirdValue = $parts[2];
  337. $resultArray[$firstKey][$secondKey][] = $thirdValue;
  338. }
  339. // 对废品分类下的数组进行升序排序
  340. if (isset($resultArray['data']['废品分类'])) {
  341. foreach ($resultArray['data']['废品分类'] as &$category) {
  342. // 判断是关联数组(单凹等)还是索引数组(分切等)
  343. if (is_array($category) && !empty($category) && is_array(current($category))) {
  344. foreach ($category as &$subCategory) {
  345. ksort($subCategory);
  346. }
  347. } else {
  348. ksort($category);
  349. }
  350. }
  351. }
  352. $this->success('请求成功',$resultArray);
  353. }
  354. /**
  355. *获取工序及责任组长
  356. * @ApiMethod GET
  357. * @params string type
  358. * @params string order
  359. */
  360. public function getGxAndLeader(){
  361. if (Request::instance()->isGet() == false){
  362. $this->error('非法请求');
  363. }
  364. $params = Request::instance()->param();
  365. if (!isset($params['type']) || empty($params['type'])){
  366. $this->error('参数错误');
  367. }
  368. if (!isset($params['order']) || empty($params['order'])){
  369. $this->error('参数错误');
  370. }
  371. if (!isset($params['yjno']) || empty($params['yjno'])){
  372. $this->error('参数错误');
  373. }
  374. $type = trim($params['type']);
  375. $waste = db('erp_常用字典')->where('名称','like','%'.$type.'%')->find();
  376. if (empty($waste)){
  377. $this->error('未查询到废品分类');
  378. }
  379. $wasteType = explode('_',substr($waste['名称'],0,-1));
  380. $searchArr = explode('-',$wasteType[1]);
  381. $where['a.sczl_gdbh'] = $params['order'];
  382. $where['a.sczl_yjno'] = $params['yjno'];
  383. //模切和凹凸的废品类型相同
  384. if ($searchArr[1] === '模切凹凸'){
  385. $list = db('设备_产量计酬')->alias('a')
  386. ->join('人事_基本资料 b', 'a.sczl_bh1 = b.员工编号', 'left')
  387. ->where($where)
  388. ->where(function($query) {
  389. $query->where('a.sczl_type', 'like', '%模切%')
  390. ->whereOr('a.sczl_type', 'like', '%凹凸%');
  391. })
  392. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  393. ->select();
  394. }elseif ($searchArr[1] === '拆片'){
  395. $search = substr($searchArr[1],0,6);
  396. $where['a.sczl_type'] = array('like','%'.$search.'%');
  397. $list = db('db_sczl')->alias('a')
  398. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  399. ->where($where)
  400. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  401. ->select();
  402. }elseif($searchArr[1] === '检验'){
  403. $where['a.sczl_gxmc'] = ['like','%'.'检'.'%'];
  404. $list = db('设备_产量计酬')->alias('a')
  405. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  406. ->where($where)
  407. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  408. ->select();
  409. }else{
  410. $search = substr($searchArr[1],0,6);
  411. $where['a.sczl_type'] = array('like','%'.$search.'%');
  412. $list = db('设备_产量计酬')->alias('a')
  413. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  414. ->where($where)
  415. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  416. ->select();
  417. }
  418. $count = count($list);
  419. $list[$count]['sczl_gxmc'] = '99-外发加工';
  420. $list[$count]['sczl_bzdh'] = 'A班';
  421. $list[$count]['sczl_jtbh'] = '';
  422. $list[$count]['sczl_bh1'] = '000000';
  423. $list[$count]['name'] = '计时工';
  424. $this->success('请求成功',$list);
  425. }
  426. /**
  427. * 修改工单核检单
  428. * @ApiMethod POST
  429. * @params array data
  430. */
  431. public function edit(){
  432. if (Request::instance()->isPost() == false){
  433. $this->error('非法请求');
  434. }
  435. $params = Request::instance()->post();
  436. if (!isset($params['UniqId'])){
  437. $this->error('参数不能为空');
  438. }
  439. $id = $params['UniqId'];
  440. unset($params['UniqId']);
  441. $sql = db('db_qczl')->where('UniqId',$id)->fetchSql(true)->update($params);
  442. $res = Db::query($sql);
  443. if ($res !== 0){
  444. cache('WorkOrderVerification-getTable',null);
  445. $this->success('更新成功');
  446. }else{
  447. $this->error('更新失败');
  448. }
  449. }
  450. /**
  451. * 新增工单核检单
  452. * @ApiMethod POST
  453. * @params array data
  454. */
  455. public function add(){
  456. if (Request::instance()->isPost() == false){
  457. $this->error('非法请求');
  458. }
  459. $params = Request::instance()->post();
  460. $UniqId = db('db_qczl')->order('UniqId desc')->value('UniqId');
  461. if ($UniqId < 10000000){
  462. $UniqId = 10000000;
  463. }else{
  464. $UniqId = $UniqId + 1;
  465. }
  466. $params['UniqId'] = $UniqId;
  467. $params['sys_rq'] = date('Y-m-d H:i:s');
  468. $res = \db('db_qczl')->insert($params);
  469. if ($res !== false){
  470. cache('WorkOrderVerification-getTable',null);
  471. $this->success('新增成功');
  472. }else{
  473. $this->error('新增失败');
  474. }
  475. }
  476. /**
  477. * 工单核检废品分布
  478. * @ApiMethod GET
  479. * @params string order
  480. */
  481. public function wasteDistribution(){
  482. if (Request::instance()->isGet() == false){
  483. $this->error('非法请求');
  484. }
  485. $params = Request::instance()->param();
  486. if (!isset($params['order']) || empty($params['order'])){
  487. $this->error('参数错误');
  488. }
  489. if (!isset($params['yjno']) || empty($params['yjno'])){
  490. $this->error('参数错误');
  491. }
  492. $field = '
  493. rtrim(fp_lb1) as fp_lb1,rtrim(fp_lb2) as fp_lb2,rtrim(fp_lb3) as fp_lb3,rtrim(fp_lb4) as fp_lb4,rtrim(fp_lb5) as fp_lb5,rtrim(fp_lb6) as fp_lb6,rtrim(fp_lb7) as fp_lb7,
  494. rtrim(fp_lb8) as fp_lb8,rtrim(fp_lb9) as fp_lb9,rtrim(fp_lb10) as fp_lb10,rtrim(fp_lb11) as fp_lb11,rtrim(fp_lb12) as fp_lb12,rtrim(fp_lb13) as fp_lb13,
  495. fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,qczl_yjno
  496. ';
  497. // $data = db('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select();
  498. $data = db('db_qczl')->name('db_qczl')
  499. ->where('qczl_gdbh',$params['order'])
  500. ->where('qczl_yjno', $params['yjno'])
  501. ->field($field)->select();
  502. if (empty($data)){
  503. $this->error('暂无废品数据');
  504. }
  505. // 用于存储废品类别和对应废品数量的数组
  506. $categories = array();
  507. // 循环遍历原始数组
  508. foreach ($data as $item) {
  509. // 提取废品类别和对应废品数量
  510. foreach ($item as $key => $value) {
  511. if (strpos($key, "fp_lb") === 0) {
  512. $categoryKey = $key;
  513. $quantityKey = str_replace("fp_lb", "fp_sl", $key);
  514. $quantityValue = $item[$quantityKey];
  515. if (!isset($categories[$value])) {
  516. $categories[$value] = 0;
  517. }
  518. $categories[$value] += (int)$quantityValue;
  519. }
  520. }
  521. }
  522. ksort($categories);
  523. $wasteTotal = db('db_qczl')->where('qczl_gdbh',$params['order'])->sum('qczl_fp');
  524. if (empty($wasteTotal)){
  525. $wasteTotal = 0;
  526. }
  527. $where['a.Gd_gdbh'] = $params['order'];
  528. $where['a.行号'] = $params['yjno'];
  529. $gdInfo = db('工单_基本资料')->alias('a')
  530. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  531. ->where($where)->field('a.Gd_gdbh,a.实际投料,b.yj_Yjno,b.yj_yjmc')->find();
  532. $gdInfo['yj_Yjno'] = $gdInfo['yj_Yjno'] > 10 ? $gdInfo['yj_Yjno']:'0'.$gdInfo['yj_Yjno'];
  533. $gdInfo['实际投料'] = (int)($gdInfo['实际投料'] * 10000);
  534. $gdInfo['wasteTotal'] = $wasteTotal;
  535. $finishNum = db('成品入仓')->where('jjcp_gdbh',$params['order'])->sum('jjcp_sl');
  536. $gdInfo['passRate'] = '';
  537. if (!empty($finishNum)){
  538. $gdInfo['passRate'] = number_format((int)$finishNum/$gdInfo['实际投料']*100,2).'%';
  539. }
  540. //左侧废品数据
  541. $wasteData = array();
  542. $i = 0;
  543. foreach ($categories as $key=>$value){
  544. if ($value != 0){
  545. $wasteData[$i]['type'] = $key;
  546. $wasteData[$i]['num'] = $value;
  547. $wasteData[$i]['lossesRate'] = number_format($value/$gdInfo['实际投料']*100,4).'%';
  548. $wasteData[$i]['wasteRate'] = number_format($value/$wasteTotal*100,2).'%';
  549. $i++;
  550. }
  551. }
  552. // 按首字母相同的键将值相加
  553. $newArray = array();
  554. foreach ($categories as $key => $value) {
  555. $firstLetter = strtoupper(substr($key, 0, 1)); // 获取首字母并转换为大写
  556. if (!isset($newArray[$firstLetter])) {
  557. $newArray[$firstLetter] = 0;
  558. }
  559. $newArray[$firstLetter] += $value;
  560. }
  561. // 去掉值为零的项
  562. $newArray = array_filter($newArray, function($value) {
  563. return $value !== 0;
  564. });
  565. //右侧废品数据
  566. $rightData = array();
  567. $i = 0;
  568. $name = array();
  569. foreach ($newArray as $key=>$value){
  570. $item = db('erp_常用字典')->where('名称','like','%'.$key.'%')->value('名称');
  571. $item = explode('_',substr($item,0,-1));
  572. $rightData[$i]['type'] = $item[1];
  573. $rightData[$i]['rate'] = number_format($value/$wasteTotal*100,0).'%';
  574. $name[$i] = $item[1];
  575. $i++;
  576. }
  577. $gdInfo['wasteData'] = $wasteData;
  578. $gdInfo['rightData'] = $rightData;
  579. $gdInfo['rightTitle'] = $name;
  580. $this->success('请求成功',$gdInfo);
  581. }
  582. /**
  583. * 获取工单工序状态
  584. * @ApiMethod GET
  585. * @params string order
  586. * 计划产量计算方式:上个工序计划产量-(基础损耗+损耗率*上个工序计划产量)*损耗系数*计损色数)
  587. * lastNum - (Gy0_Rate0 + Gy0_Rate1 * lastNum )* 损耗系数(Gy0_Rate3) * Gy0_Ms
  588. */
  589. public function getOrderDate(){
  590. if (Request::instance()->isGet() == false){
  591. $this->error('非法请求');
  592. }
  593. $params = Request::instance()->param();
  594. if (!isset($params['order']) || empty($params['order'])){
  595. $this->error('参数错误');
  596. }
  597. $where['a.Gy0_gdbh'] = $params['order'];
  598. $where['a.Gy0_sbbh'] = array('neq',' ');
  599. $productNum = db('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料');
  600. $gyData = db('工单_工艺资料')->alias('a')
  601. ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh and a.Gy0_gxh = b.sczl_gxh','left')
  602. ->where($where)
  603. ->field('a.Gy0_yjno,a.Gy0_gxh,rtrim(a.Gy0_gxmc) as Gy0_gxmc,a.Gy0_sbbh,a.Gy0_Rate0,a.Gy0_Rate1,a.损耗系数 as Gy0_Rate3,a.Gy0_Ms,a.Gy0_SITE,a.Gy0_计划接货数,a.PD_WG,
  604. a.UniqId,sum(b.sczl_cl) as cl')
  605. ->group('a.Gy0_gxh')
  606. ->select();
  607. $lastNum = $productNum;
  608. $res = [];
  609. foreach ($gyData as $key=> $process) {
  610. $res[$key]['UniqId'] = $process['UniqId'];
  611. $res[$key]['Gy0_yjno'] = $process['Gy0_yjno'] > 10 ? $process['Gy0_yjno'] : '0'.$process['Gy0_yjno'];
  612. $res[$key]['Gy0_gxh'] = $process['Gy0_gxh'] > 10 ? $process['Gy0_gxh'] : '0'.$process['Gy0_gxh'];
  613. $res[$key]['Gy0_gxmc'] = $process['Gy0_gxmc'];
  614. $res[$key]['Gy0_sbbh'] = rtrim($process['Gy0_sbbh']);
  615. $res[$key]['PD_WG'] = $process['PD_WG'];
  616. $res[$key]['finish'] = empty($process['cl']) ? 0: (int)$process['cl'];
  617. // 计算工序计划产量
  618. if ($process["Gy0_gxh"] == "1") {
  619. // 第一道工序直接使用初始计划产量
  620. $Num = $lastNum;
  621. } else {
  622. $Gy0_Ms = $gyData[$key-1]['Gy0_Ms'];
  623. $Gy0_Rate0 = $gyData[$key-1]['Gy0_Rate0'];
  624. $Gy0_Rate1 = $gyData[$key-1]['Gy0_Rate1'];
  625. $Gy0_Rate3 = $gyData[$key-1]['Gy0_Rate3'];
  626. // 大于第一道工序,使用上一道工序的计划产量
  627. // 根据公式计算工序计划产量
  628. if ($Gy0_Ms != "0.00") {
  629. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3 * $Gy0_Ms;
  630. } else {
  631. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3;
  632. }
  633. }
  634. if (trim($process['Gy0_SITE']) == '检验车间'){
  635. $res[$key]['plan'] = (int)$process['Gy0_计划接货数'];
  636. }else{
  637. $res[$key]['plan'] = (int)round($Num);
  638. }
  639. $finish_rate = $res[$key]['finish']/$res[$key]['plan'];
  640. $res[$key]['finish_rate'] = '';
  641. if ($finish_rate != 0){
  642. $res[$key]['finish_rate'] = number_format($finish_rate*100,2).'%';
  643. }
  644. // 更新 $lastNum 为当前工序的计划产量
  645. $lastNum = $Num;
  646. }
  647. $this->success('请求成功',$res);
  648. }
  649. /**
  650. * 工单工序状态更正
  651. * @ApiMethod POST
  652. * @params string UniqId
  653. * @params string date
  654. */
  655. public function editOrderFinishDate(){
  656. if (Request::instance()->isPost() == false){
  657. $this->error('非法请求');
  658. }
  659. $params = Request::instance()->post();
  660. if (!isset($params['UniqId']) || !isset($params['date'])){
  661. $this->error('参数错误');
  662. }
  663. if (empty($params['UniqId'])){
  664. $this->error('参数不能为空');
  665. }
  666. if (empty($params['date'])){
  667. $params['date'] = '1900-01-01 00:00:00';
  668. }
  669. $res = db('工单_工艺资料')->where('UniqId',$params['UniqId'])->setField('PD_WG',$params['date']);
  670. if ($res != false){
  671. $this->success('更新成功');
  672. }else{
  673. $this->error('更新失败');
  674. }
  675. }
  676. /**
  677. * 工单工序生产进程菜单栏
  678. * @ApiMethod GET
  679. * @params string order
  680. */
  681. public function getOrderProcessLeft(){
  682. if (Request::instance()->isGet() == false){
  683. $this->error('非法请求');
  684. }
  685. $params = Request::instance()->param();
  686. if (!isset($params['order']) || empty($params['order'])){
  687. $this->error('参数错误');
  688. }
  689. if (!isset($params['yjno']) || empty($params['yjno'])){
  690. $this->error('参数错误');
  691. }
  692. $where['Gd_gdbh'] = $params['order'];
  693. // $where['行号'] = 1;
  694. //工单基本资料
  695. $info = db('工单_基本资料')->where($where)->field('rtrim(成品代号) as code,rtrim(成品名称) as name')->find();
  696. //工艺资料
  697. $option['Gy0_gdbh'] = $params['order'];
  698. $option['Gy0_yjno'] = $params['yjno'];
  699. $gyInfo = db('工单_工艺资料')
  700. ->where($option)
  701. ->where(function ($query) {
  702. $query->where('Gy0_sbbh', '<>', '')
  703. ->whereOr('Gy0_gxmc', '核检')
  704. ->whereOr('Gy0_gxmc', '抽检')
  705. ->whereOr('Gy0_gxmc', '成品防护');
  706. })
  707. ->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc')
  708. ->select();
  709. foreach ($gyInfo as $key=>$value){
  710. $gyInfo[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
  711. $gyInfo[$key]['Gy0_gxh'] = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
  712. }
  713. $res['Gd_info'] = $info;
  714. $res['Gy_info'] = $gyInfo;
  715. $this->success('请求成功',$res);
  716. }
  717. /**
  718. * 工单工序生产进程右侧
  719. * @ApiMethod GET
  720. * @params string order
  721. * @params string gxNo
  722. */
  723. public function getOrderProcessRight(){
  724. if (Request::instance()->isGet() == false){
  725. $this->error('非法请求');
  726. }
  727. $params = Request::instance()->param();
  728. if (!isset($params['order']) || empty($params['order'])){
  729. $this->error('参数错误');
  730. }
  731. if (!isset($params['yjno']) || empty($params['yjno'])){
  732. $this->error('参数错误');
  733. }
  734. if (!isset($params['gxNo']) || empty($params['gxNo'])){
  735. $this->error('参数错误');
  736. }
  737. $total = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yjno'])->order('sczl_num')->column('distinct(sczl_num)');
  738. $where['sczl_gxh'] = (int)$params['gxNo'];
  739. $where['sczl_gdbh'] = $params['order'];
  740. $where['sczl_yjno'] = $params['yjno'];
  741. //机器设备数据
  742. $process = db('设备_产量计酬')->where($where)->order('sczl_num')->column('distinct(sczl_num)');
  743. //手工数据
  744. $option['qczl_gdbh'] = $params['order'];
  745. $option['qczl_gxh'] = (int)$params['gxNo'];
  746. $option['qczl_yjno'] = $params['yjno'];
  747. $handProcess = db('db_qczl')->where($option)->field('qczl_num,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8')->select();
  748. // 提取数据
  749. $result = array();
  750. foreach ($handProcess as $subArray) {
  751. $qczl_num = $subArray["qczl_num"];
  752. $result[] = $qczl_num;
  753. // 提取以qczl_NumDesc开头的键对应的值
  754. for ($i = 1; $i <= 8; $i++) {
  755. $key = "qczl_NumDesc" . $i;
  756. if ($subArray[$key] != 0){
  757. $result[] = $subArray[$key];
  758. }
  759. }
  760. }
  761. // 去重
  762. $result = array_unique($result);
  763. // 对结果进行排序
  764. sort($result);
  765. $res['total_process'] = $total;
  766. $res['process'] = $process;
  767. if (empty($process)){
  768. $res['process'] = $result;
  769. }
  770. $this->success('请求成功',$res);
  771. }
  772. /**
  773. * 核检废品日统计
  774. * @ApiMethod GET
  775. * @params date start_date
  776. * @params date end_date
  777. */
  778. public function getDaysWast()
  779. {
  780. if (Request::instance()->isGet() == false) {
  781. $this->error('非法请求');
  782. }
  783. $params = Request::instance()->param();
  784. if (!isset($params['start_date']) || empty($params['start_date'])) {
  785. $this->error('参数错误');
  786. }
  787. if (!isset($params['end_date']) || empty($params['end_date'])) {
  788. $this->error('参数错误');
  789. }
  790. $where['qczl_rq'] = array('between time', [$params['start_date'], $params['end_date']]);
  791. $field = '
  792. rtrim(fp_lb1) as fp_lb1,rtrim(fp_lb2) as fp_lb2,rtrim(fp_lb3) as fp_lb3,rtrim(fp_lb4) as fp_lb4,rtrim(fp_lb5) as fp_lb5,rtrim(fp_lb6) as fp_lb6,rtrim(fp_lb7) as fp_lb7,
  793. rtrim(fp_lb8) as fp_lb8,rtrim(fp_lb9) as fp_lb9,rtrim(fp_lb10) as fp_lb10,rtrim(fp_lb11) as fp_lb11,rtrim(fp_lb12) as fp_lb12,rtrim(fp_lb13) as fp_lb13,
  794. fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,
  795. fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
  796. rtrim(fp_bz1) as fp_bz1, rtrim(fp_bz2) as fp_bz2, rtrim(fp_bz3) as fp_bz3, rtrim(fp_bz4) as fp_bz4, rtrim(fp_bz5) as fp_bz5, rtrim(fp_bz6) as fp_bz6, rtrim(fp_bz7) as fp_bz7,
  797. rtrim(fp_bz8) as fp_bz8, rtrim(fp_bz9) as fp_bz9, rtrim(fp_bz10) as fp_bz10, rtrim(fp_bz11) as fp_bz11, rtrim(fp_bz12) as fp_bz12, rtrim(fp_bz13) as fp_bz13,
  798. qczl_rq
  799. ';
  800. $resultArray = array();
  801. $key = 'getDaysWast'.$params['start_date'].'/'.$params['end_date'];
  802. $is_have_cache = Cache::has($key);
  803. if ($is_have_cache === false){
  804. $data = db('db_qczl')
  805. ->where($where)
  806. ->where(function ($query) {
  807. for ($i = 1; $i <= 13; $i++) {
  808. $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
  809. }
  810. })
  811. ->field($field)->select();
  812. $list = [];
  813. $j = 0;
  814. foreach ($data as $entry) {
  815. for ($i = 1; $i <= 13; $i++) {
  816. $labelKey = "fp_lb" . $i;
  817. $slKey = "fp_sl" . $i;
  818. $bhKey = "fp_bh" . $i;
  819. $bzKey = "fp_bz" . $i;
  820. if (!empty($entry[$labelKey])) {
  821. if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
  822. $list[$j]['fp_lb'] = $entry[$labelKey];
  823. $list[$j]['fp_sl'] = $entry[$slKey];
  824. $list[$j]['fp_bh'] = $entry[$bhKey];
  825. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  826. $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
  827. $list[$j]['fp_bz'] = $entry[$bzKey];
  828. $list[$j]['qczl_rq'] = $entry['qczl_rq'];
  829. $j++;
  830. }
  831. }
  832. }
  833. }
  834. foreach ($list as $item) {
  835. $found = false;
  836. foreach ($resultArray as &$resultItem) {
  837. if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
  838. $resultItem["fp_sl"] += (int)$item["fp_sl"];
  839. $found = true;
  840. break;
  841. }
  842. }
  843. if (!$found) {
  844. $resultArray[] = $item;
  845. }
  846. }
  847. // 使用usort进行排序
  848. usort($resultArray, function($a, $b) {
  849. // First, sort by fp_lb (K01/K02)
  850. $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
  851. if ($compareLb !== 0) {
  852. return $compareLb;
  853. }
  854. // If fp_lb is the same, prioritize B班 over A班
  855. $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
  856. if ($compareBz !== 0) {
  857. return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
  858. }
  859. // If fp_bz is the same, sort by fp_bh
  860. $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
  861. return $compareBh;
  862. });
  863. Cache::set($key,$resultArray,86400);
  864. }else{
  865. $resultArray = Cache::get($key);
  866. }
  867. $this->success('请求成功',$resultArray);
  868. }
  869. /**
  870. * 月度核检废品责任人统计
  871. * @ApiMethod GET
  872. * @params string date
  873. */
  874. public function getMonthPeopleTotal(){
  875. if (Request::instance()->isGet() == false) {
  876. $this->error('非法请求');
  877. }
  878. $params = Request::instance()->param();
  879. if (!isset($params['date']) || empty($params['date'])) {
  880. $this->error('参数错误');
  881. }
  882. }
  883. /**
  884. * 工单质检废品统计
  885. * @ApiMethod GET
  886. * @params string order
  887. */
  888. public function getOrderWasteTotal(){
  889. if (Request::instance()->isGet() == false) {
  890. $this->error('非法请求');
  891. }
  892. $params = Request::instance()->param();
  893. if (!isset($params['order']) || empty($params['order'])) {
  894. $this->error('参数错误');
  895. }
  896. $field = '
  897. rtrim(a.fp_lb1) as fp_lb1,rtrim(a.fp_lb2) as fp_lb2,rtrim(a.fp_lb3) as fp_lb3,rtrim(a.fp_lb4) as fp_lb4,rtrim(a.fp_lb5) as fp_lb5,rtrim(a.fp_lb6) as fp_lb6,rtrim(a.fp_lb7) as fp_lb7,
  898. rtrim(a.fp_lb8) as fp_lb8,rtrim(a.fp_lb9) as fp_lb9,rtrim(a.fp_lb10) as fp_lb10,rtrim(a.fp_lb11) as fp_lb11,rtrim(a.fp_lb12) as fp_lb12,rtrim(a.fp_lb13) as fp_lb13,
  899. a.fp_sl1,a.fp_sl2,a.fp_sl3,a.fp_sl4,a.fp_sl5,a.fp_sl6,a.fp_sl7,a.fp_sl8,a.fp_sl9,a.fp_sl10,a.fp_sl11,a.fp_sl12,a.fp_sl13,
  900. a.fp_bh1,a.fp_bh2,a.fp_bh3,a.fp_bh4,a.fp_bh5,a.fp_bh6,a.fp_bh7,a.fp_bh8,a.fp_bh9,a.fp_bh10,a.fp_bh11,a.fp_bh12,a.fp_bh13,
  901. rtrim(a.fp_gxmc1) as fp_gxmc1, rtrim(a.fp_gxmc2) as fp_gxmc2, rtrim(a.fp_gxmc3) as fp_gxmc3, rtrim(a.fp_gxmc4) as fp_gxmc4, rtrim(a.fp_gxmc5) as fp_gxmc5, rtrim(a.fp_gxmc6) as fp_gxmc6,
  902. rtrim(a.fp_gxmc7) as fp_gxmc7,rtrim(a.fp_gxmc8) as fp_gxmc8, rtrim(a.fp_gxmc9) as fp_gxmc9, rtrim(a.fp_gxmc10) as fp_gxmc10, rtrim(a.fp_gxmc11) as fp_gxmc11, rtrim(a.fp_gxmc12) as fp_gxmc12,
  903. rtrim(a.fp_gxmc13) as fp_gxmc13,a.qczl_num,a.qczl_yjno,rtrim(b.成品代号) as product_code,rtrim(b.成品名称) as product_name,b.订单数量,rtrim(b.计量单位) as 计量单位,b.实际投料,b.交货日期,
  904. c.yj_ls,d.jjcp_sl,d.jjcp_sj
  905. ';
  906. $where['a.qczl_gdbh'] = $params['order'];
  907. $where['a.qczl_yjno'] = $params['yjno'];
  908. $data = db('db_qczl')->alias('a')
  909. ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh AND a.qczl_yjno = b.行号','left')
  910. ->join('工单_印件资料 c','a.qczl_gdbh = c.Yj_Gdbh AND a.qczl_yjno = c.yj_Yjno','left')
  911. ->join('成品入仓 d','a.qczl_gdbh = d.jjcp_gdbh AND a.qczl_yjno = d.jjcp_yjno','left')
  912. ->where($where)
  913. ->field($field)
  914. ->group('a.qczl_yjno,a.sys_rq')
  915. ->select();
  916. $list = [];
  917. $j = 0;
  918. foreach ($data as $entry) {
  919. for ($i = 1; $i <= 13; $i++) {
  920. $labelKey = "fp_lb" . $i;
  921. $slKey = "fp_sl" . $i;
  922. $bhKey = "fp_bh" . $i;
  923. $gxhKey = "fp_gxmc". $i;
  924. if (!empty($entry[$labelKey]) && $entry[$slKey] > 0) {
  925. $list[$j]['fp_lb'] = $entry[$labelKey];
  926. $list[$j]['fp_sl'] = $entry[$slKey];
  927. $list[$j]['fp_bh'] = $entry[$bhKey];
  928. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  929. $list[$j]['fp_name'] = $name;
  930. $list[$j]['fp_gxh'] = empty(substr($entry[$gxhKey],0,2)) ? "0" : substr($entry[$gxhKey],0,2);
  931. $list[$j]['qczl_num'] = $entry['qczl_num'];
  932. $list[$j]['qczl_yjno'] = $entry['qczl_yjno'];
  933. $list[$j]['product_code'] = $entry['product_code'];
  934. $list[$j]['product_name'] = $entry['product_name'];
  935. $list[$j]['订单数量'] = $entry['订单数量'];
  936. $list[$j]['计量单位'] = $entry['计量单位'];
  937. $list[$j]['交货日期'] = substr($entry['交货日期'],0,10);
  938. $list[$j]['yj_ls'] = $entry['yj_ls'];
  939. $list[$j]['jjcp_sl'] = $entry['jjcp_sl'];
  940. $list[$j]['jjcp_sj'] = substr($entry['jjcp_sj'],0,10);
  941. $j++;
  942. }
  943. }
  944. }
  945. $summedData = [];
  946. foreach ($list as $item) {
  947. $key = $item['qczl_num'] . $item['fp_lb'];
  948. if (!isset($summedData[$key])) {
  949. $summedData[$key] = $item;
  950. } else {
  951. $summedData[$key]['fp_sl'] += $item['fp_sl'];
  952. }
  953. }
  954. $fpGxhColumn = array_column($summedData, 'fp_gxh');
  955. $qczlNumColumn = array_column($summedData, 'qczl_num');
  956. $fpLbColumn = array_column($summedData, 'fp_lb');
  957. array_multisort($fpGxhColumn, SORT_ASC, $qczlNumColumn, SORT_ASC, $fpLbColumn, SORT_ASC, $summedData);
  958. $summedData = array_values($summedData);
  959. $this->success('请求成功',$summedData);
  960. }
  961. /**
  962. * 工单核检单删除
  963. * @return void
  964. * @throws \think\Exception
  965. * @throws \think\exception\PDOException
  966. */
  967. public function del()
  968. {
  969. if ($this->request->isGet() === false){
  970. $this->error('请求错误');
  971. }
  972. $param = $this->request->param();
  973. if (empty($param['UniqId'])){
  974. $this->error('参数错误');
  975. }
  976. $res = \db('db_qczl')
  977. ->where('UniqId',$param['UniqId'])
  978. ->delete();
  979. if ($res !== false){
  980. $this->success('删除成功');
  981. }else{
  982. $this->error('产出失败');
  983. }
  984. }
  985. public function getJunkdata()
  986. {
  987. if ($this->request->isGet() === false){
  988. $this->error('请求错误');
  989. }
  990. $param = $this->request->param();
  991. if (empty($param)){
  992. $this->error('参数错误');
  993. }
  994. $sql = "SELECT
  995. a.jjcp_gdbh,
  996. a.jjcp_yjno,
  997. a.jjcp_sj,
  998. a.jjcp_sl,
  999. a.成品名称,
  1000. b.fp_lb1,
  1001. b.fp_lb2,
  1002. b.fp_lb3,
  1003. b.fp_lb4,
  1004. b.fp_lb5,
  1005. b.fp_lb6,
  1006. b.fp_lb7,
  1007. b.fp_lb8,
  1008. b.fp_lb9,
  1009. b.fp_lb10,
  1010. b.fp_lb11,
  1011. b.fp_lb12,
  1012. b.fp_lb13,
  1013. b.fp_gxmc1,
  1014. b.fp_gxmc2,
  1015. b.fp_gxmc3,
  1016. b.fp_gxmc4,
  1017. b.fp_gxmc5,
  1018. b.fp_gxmc6,
  1019. b.fp_gxmc7,
  1020. b.fp_gxmc8,
  1021. b.fp_gxmc9,
  1022. b.fp_gxmc10,
  1023. b.fp_gxmc11,
  1024. b.fp_gxmc12,
  1025. b.fp_gxmc13,
  1026. b.fp_sl1,
  1027. b.fp_sl2,
  1028. b.fp_sl3,
  1029. b.fp_sl4,
  1030. b.fp_sl5,
  1031. b.fp_sl6,
  1032. b.fp_sl7,
  1033. b.fp_sl8,
  1034. b.fp_sl9,
  1035. b.fp_sl10,
  1036. b.fp_sl11,
  1037. b.fp_sl12,
  1038. b.fp_sl13,
  1039. sum(b.qczl_fp) as fp,
  1040. b.UniqId,
  1041. c.实际投料 * 10000
  1042. FROM
  1043. `成品入仓` `a`
  1044. LEFT JOIN db_qczl b ON a.jjcp_gdbh = b.qczl_gdbh AND a.jjcp_yjno = b.qczl_yjno
  1045. JOIN `工单_基本资料` c ON a.jjcp_gdbh = c.Gd_gdbh AND a.jjcp_yjno = c.`行号`
  1046. WHERE
  1047. (a.jjcp_sj LIKE '2024-07%'
  1048. OR a.jjcp_sj LIKE '2024-08%')
  1049. AND (b.qczl_fp <> null or b.qczl_fp > 0)
  1050. AND a.成品编码 like 'J0031%'
  1051. GROUP BY
  1052. b.UniqId";
  1053. $res = \db()->query($sql);
  1054. // halt($res);
  1055. $data = [];
  1056. foreach ($res as $key=>$value){
  1057. if (isset($data[$value['jjcp_gdbh']]) === false){
  1058. if (isset($data[$value['jjcp_gdbh']][$value['jjcp_yjno']]) === false){
  1059. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']] = [];
  1060. }
  1061. }
  1062. if (isset($data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['废品总数']) === false){
  1063. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['废品总数'] = $value['fp'];
  1064. }else{
  1065. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['废品总数'] += $value['fp'];
  1066. }
  1067. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['实际投料'] = $value['c.实际投料 * 10000'];
  1068. for ($i=1;$i<14;$i++){
  1069. if ($value['fp_gxmc'.$i] !== ''){
  1070. if (isset($data[$value['jjcp_gdbh']][$value['jjcp_yjno']][$value['fp_lb'.$i]]) === false){
  1071. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']][$value['fp_lb'.$i]] = $value['fp_sl'.$i];
  1072. }else{
  1073. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']][$value['fp_lb'.$i]] += $value['fp_sl'.$i];
  1074. }
  1075. }
  1076. }
  1077. }
  1078. $list = [];
  1079. foreach ($data as $key=>$value){
  1080. foreach ($value as $k=>$v){
  1081. $i = 0;
  1082. foreach ($v as $kk=>$vv){
  1083. if ($kk !== '废品总数' && $kk !== '实际投料'){
  1084. $list[$key][$k][$i] = [
  1085. '类型' => $kk,
  1086. '数量' => $vv,
  1087. '废品占比' => number_format($vv/$v['废品总数']*100,4).'%',
  1088. '报损占比' => number_format($vv/$v['实际投料']*100,4).'%',
  1089. ];
  1090. $i++;
  1091. $result = [
  1092. '类型' => $kk,
  1093. '数量' => $vv,
  1094. '废品占比' => number_format($vv/$v['废品总数']*100,4).'%',
  1095. '报损占比' => number_format($vv/$v['实际投料']*100,4).'%',
  1096. '工单编号' => $key,
  1097. '印件号' => $k
  1098. ];
  1099. $sql = \db('废品报表')->fetchSql(true)->insert($result);
  1100. $reult = \db()->query($sql);
  1101. }
  1102. }
  1103. }
  1104. }
  1105. // $this->success('成功',$list);
  1106. }
  1107. }