WorkOrderVerification.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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. rtrim(sys_id) as sys_id,UniqId')
  135. ->where($where)
  136. ->order('UniqId desc')
  137. ->page($page,$limit)
  138. ->select();
  139. $total = db()->table('db_qczl')->where($where)->count();
  140. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  141. foreach ($rows as $key=>$value){
  142. $rows[$key]['Gd_cpmc'] = array_key_exists($value['qczl_gdbh'],$gd) ? sprintf("%02d", $value['qczl_yjno']).'-'.trim($gd[$value['qczl_gdbh']]) : '';
  143. for ($i=1;$i<=17;$i++){
  144. if ($value['fp_sl'.$i]==0){
  145. $rows[$key]['sl_lb'.$i] = '';
  146. }else{
  147. $rows[$key]['sl_lb'.$i] = trim($value['fp_sl'.$i].'-->'.$value['fp_lb'.$i]);
  148. }
  149. unset($rows[$key]['fp_sl'.$i]);
  150. unset($rows[$key]['fp_lb'.$i]);
  151. }
  152. }
  153. $data = [
  154. 'total' => $total,
  155. 'rows' => $rows,
  156. ];
  157. $this->success('成功',$data);
  158. }
  159. /**
  160. * 获取工单核验单信息
  161. * @ApiMethod (GET)
  162. * @param string $UniqId UniqId
  163. */
  164. public function getInfo()
  165. {
  166. //get请求
  167. if(!$this->request->isGet()){
  168. $this->error('请求方式错误');
  169. }
  170. $req = $this->request->param();
  171. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  172. $UniqId = $req['UniqId'];
  173. }else{
  174. $this->error('参数错误');
  175. }
  176. $rows = db()->table('db_qczl')->alias('d')
  177. ->field('d.*, ')
  178. ->join('工单_基本资料 g', 'd.')
  179. ->where('d.UniqId',$UniqId)
  180. ->select();
  181. $this->success('成功',$rows);
  182. }
  183. /**
  184. * 获取单个工单核检单信息
  185. * @ApiMethod GET
  186. * @params string UniqId
  187. */
  188. public function getOneWorkOrder(){
  189. if (Request::instance()->isGet() == false){
  190. $this->error('非法请求');
  191. }
  192. $params = Request::instance()->param();
  193. if (!isset($params['UniqId']) || empty($params['UniqId'])){
  194. $this->error('参数错误');
  195. }
  196. $field = 'qczl_gdbh,qczl_Pygd,qczl_yjno,qczl_gxh,qczl_gxmc,qczl_type,qczl_rq,qczl_num,qczl_fp,
  197. qczl_NumDesc,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8,
  198. 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,
  199. 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,
  200. 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,
  201. 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,
  202. 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,
  203. sys_id,rtrim(sys_rq) as sys_rq,UniqId';
  204. $list = db('db_qczl')->where('UniqId',$params['UniqId'])->field($field)->find();
  205. $list['fp_name1'] = '';
  206. if (!empty($list['fp_bh1'])){
  207. $list['fp_name1'] = db('人事_基本资料')->where('员工编号',$list['fp_bh1'])->value('rtrim(员工姓名)');
  208. }
  209. $list['fp_name2'] = '';
  210. if (!empty($list['fp_bh2'])){
  211. $list['fp_name2'] = db('人事_基本资料')->where('员工编号',$list['fp_bh2'])->value('rtrim(员工姓名)');
  212. }
  213. $list['fp_name3'] = '';
  214. if (!empty($list['fp_bh3'])){
  215. $list['fp_name3'] = db('人事_基本资料')->where('员工编号',$list['fp_bh3'])->value('rtrim(员工姓名)');
  216. }
  217. $list['fp_name4'] = '';
  218. if (!empty($list['fp_bh4'])){
  219. $list['fp_name4'] = db('人事_基本资料')->where('员工编号',$list['fp_bh4'])->value('rtrim(员工姓名)');
  220. }
  221. $list['fp_name5'] = '';
  222. if (!empty($list['fp_bh5'])){
  223. $list['fp_name5'] = db('人事_基本资料')->where('员工编号',$list['fp_bh5'])->value('rtrim(员工姓名)');
  224. }
  225. $list['fp_name6'] = '';
  226. if (!empty($list['fp_bh6'])){
  227. $list['fp_name6'] = db('人事_基本资料')->where('员工编号',$list['fp_bh6'])->value('rtrim(员工姓名)');
  228. }
  229. $list['fp_name7'] = '';
  230. if (!empty($list['fp_bh7'])){
  231. $list['fp_name7'] = db('人事_基本资料')->where('员工编号',$list['fp_bh7'])->value('rtrim(员工姓名)');
  232. }
  233. $list['fp_name8'] = '';
  234. if (!empty($list['fp_bh8'])){
  235. $list['fp_name8'] = db('人事_基本资料')->where('员工编号',$list['fp_bh8'])->value('rtrim(员工姓名)');
  236. }
  237. $list['fp_name9'] = '';
  238. if (!empty($list['fp_bh9'])){
  239. $list['fp_name9'] = db('人事_基本资料')->where('员工编号',$list['fp_bh9'])->value('rtrim(员工姓名)');
  240. }
  241. $list['fp_name10'] = '';
  242. if (!empty($list['fp_bh10'])){
  243. $list['fp_name10'] = db('人事_基本资料')->where('员工编号',$list['fp_bh10'])->value('rtrim(员工姓名)');
  244. }
  245. $list['fp_name11'] = '';
  246. if (!empty($list['fp_bh11'])){
  247. $list['fp_name11'] = db('人事_基本资料')->where('员工编号',$list['fp_bh11'])->value('rtrim(员工姓名)');
  248. }
  249. $list['fp_name12'] = '';
  250. if (!empty($list['fp_bh12'])){
  251. $list['fp_name12'] = db('人事_基本资料')->where('员工编号',$list['fp_bh12'])->value('rtrim(员工姓名)');
  252. }
  253. $list['fp_name13'] = '';
  254. if (!empty($list['fp_bh13'])){
  255. $list['fp_name13'] = db('人事_基本资料')->where('员工编号',$list['fp_bh13'])->value('rtrim(员工姓名)');
  256. }
  257. $max = db('设备_产量计酬')->where('sczl_gdbh',$list['qczl_gdbh'])->field('MAX(sczl_num) as sczl_num')->find();
  258. $list['total_liucheng'] = $max['sczl_num'];
  259. $this->success('请求成功',$list);
  260. }
  261. /**
  262. * 获取工单基本信息
  263. * @ApiMethod GET
  264. * @params string order
  265. */
  266. public function getOrderInfo(){
  267. if (Request::instance()->isGet() == false){
  268. $this->error('非法请求');
  269. }
  270. $params = Request::instance()->param();
  271. if (!isset($params['order']) || empty($params['order'])){
  272. $this->error('参数错误');
  273. }
  274. $list = db('工单_基本资料')->alias('a')
  275. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  276. ->where('a.Gd_gdbh',$params['order'])
  277. ->where('a.行号',1)
  278. ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc')
  279. ->select();
  280. $this->success('请求成功',$list);
  281. }
  282. /**
  283. * 获取印件名称及工序
  284. * @ApiMethod GET
  285. * @params string order
  286. * @params string yj_no
  287. */
  288. public function getYjInfo(){
  289. if (Request::instance()->isGet() == false){
  290. $this->error('非法请求');
  291. }
  292. $params = Request::instance()->param();
  293. if (!isset($params['order']) || empty($params['order'])){
  294. $this->error('参数错误');
  295. }
  296. if (!isset($params['yj_no']) || empty($params['yj_no'])){
  297. $this->error('参数错误');
  298. }
  299. $where['Yj_Gdbh'] = $params['order'];
  300. $where['yj_Yjno'] = $params['yj_no'];
  301. $list = db('工单_印件资料')->where($where)->field('yj_yjmc')->find();
  302. $option['Gy0_gdbh'] = $params['order'];
  303. $option['Gy0_yjno'] = $params['yj_no'];
  304. $option['Gy0_gxmc|Add_gxmc'] = ['like','%'.'核检'.'%'];
  305. // $option['Gy0_site'] = '印后车间';
  306. // $option['Gy0_gxmc'] = array('not in',['包装','外发加工','废挑正','成品防护']);
  307. $gxList = db('工单_工艺资料')->where($option)->field('Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')->select();
  308. $max = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yj_no'])->field('MAX(sczl_num) as sczl_num')->value('sczl_num');
  309. $list['gx_data'] = $gxList;
  310. $list['max_num'] = $max;
  311. $this->success('请求成功',$list);
  312. }
  313. /**
  314. * 获取废品分类
  315. * @ApiMethod GET
  316. * @params string search
  317. */
  318. public function getWastInfo(){
  319. if (Request::instance()->isGet() == false){
  320. $this->error('非法请求');
  321. }
  322. $params = Request::instance()->param();
  323. $where['分类'] = '废品分类';
  324. if (!empty($params['search'])){
  325. $where['名称'] = array('like','%'.$params['search'].'%');
  326. }
  327. $data = db('erp_常用字典')->where($where)->column('名称');
  328. // 分割字符串并合并相同项
  329. $resultArray = [];
  330. foreach ($data as $item) {
  331. $parts = explode('_', $item);
  332. // 使用第一个部分作为一级键,第二个部分作为二级键
  333. $firstKey = $parts[0];
  334. $secondKey = $parts[1];
  335. $thirdValue = $parts[2];
  336. $resultArray[$firstKey][$secondKey][] = $thirdValue;
  337. }
  338. // 对废品分类下的数组进行升序排序
  339. if (isset($resultArray['data']['废品分类'])) {
  340. foreach ($resultArray['data']['废品分类'] as &$category) {
  341. // 判断是关联数组(单凹等)还是索引数组(分切等)
  342. if (is_array($category) && !empty($category) && is_array(current($category))) {
  343. foreach ($category as &$subCategory) {
  344. ksort($subCategory);
  345. }
  346. } else {
  347. ksort($category);
  348. }
  349. }
  350. }
  351. $this->success('请求成功',$resultArray);
  352. }
  353. /**
  354. *获取工序及责任组长
  355. * @ApiMethod GET
  356. * @params string type
  357. * @params string order
  358. */
  359. public function getGxAndLeader(){
  360. if (Request::instance()->isGet() == false){
  361. $this->error('非法请求');
  362. }
  363. $params = Request::instance()->param();
  364. if (!isset($params['type']) || empty($params['type'])){
  365. $this->error('参数错误');
  366. }
  367. if (!isset($params['order']) || empty($params['order'])){
  368. $this->error('参数错误');
  369. }
  370. if (!isset($params['yjno']) || empty($params['yjno'])){
  371. $this->error('参数错误');
  372. }
  373. $type = trim($params['type']);
  374. $waste = db('erp_常用字典')->where('名称','like','%'.$type.'%')->find();
  375. if (empty($waste)){
  376. $this->error('未查询到废品分类');
  377. }
  378. $wasteType = explode('_',substr($waste['名称'],0,-1));
  379. $searchArr = explode('-',$wasteType[1]);
  380. $where['a.sczl_gdbh'] = $params['order'];
  381. $where['a.sczl_yjno'] = $params['yjno'];
  382. //模切和凹凸的废品类型相同
  383. if ($searchArr[1] === '模切凹凸'){
  384. $list = db('设备_产量计酬')->alias('a')
  385. ->join('人事_基本资料 b', 'a.sczl_bh1 = b.员工编号', 'left')
  386. ->where($where)
  387. ->where(function($query) {
  388. $query->where('a.sczl_type', 'like', '%模切%')
  389. ->whereOr('a.sczl_type', 'like', '%凹凸%');
  390. })
  391. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  392. ->select();
  393. }else{
  394. $search = substr($searchArr[1],0,6);
  395. $where['a.sczl_type'] = array('like','%'.$search.'%');
  396. $list = db('设备_产量计酬')->alias('a')
  397. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  398. ->where($where)->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  399. ->select();
  400. }
  401. $count = count($list);
  402. $list[$count]['sczl_gxmc'] = '99-外发加工';
  403. $list[$count]['sczl_bzdh'] = 'A班';
  404. $list[$count]['sczl_jtbh'] = '';
  405. $list[$count]['sczl_bh1'] = '000000';
  406. $list[$count]['name'] = '计时工';
  407. $this->success('请求成功',$list);
  408. }
  409. /**
  410. * 修改工单核检单
  411. * @ApiMethod POST
  412. * @params array data
  413. */
  414. public function edit(){
  415. if (Request::instance()->isPost() == false){
  416. $this->error('非法请求');
  417. }
  418. $params = Request::instance()->post();
  419. if (!isset($params['UniqId'])){
  420. $this->error('参数不能为空');
  421. }
  422. $id = $params['UniqId'];
  423. unset($params['UniqId']);
  424. $sql = db('db_qczl')->where('UniqId',$id)->fetchSql(true)->update($params);
  425. $res = Db::query($sql);
  426. if ($res !== 0){
  427. cache('WorkOrderVerification-getTable',null);
  428. $this->success('更新成功');
  429. }else{
  430. $this->error('更新失败');
  431. }
  432. }
  433. /**
  434. * 新增工单核检单
  435. * @ApiMethod POST
  436. * @params array data
  437. */
  438. public function add(){
  439. if (Request::instance()->isPost() == false){
  440. $this->error('非法请求');
  441. }
  442. $params = Request::instance()->post();
  443. $UniqId = db('db_qczl')->order('UniqId desc')->value('UniqId');
  444. if ($UniqId < 10000000){
  445. $UniqId = 10000000;
  446. }else{
  447. $UniqId = $UniqId + 1;
  448. }
  449. $params['UniqId'] = $UniqId;
  450. $params['sys_rq'] = date('Y-m-d H:i:s');
  451. $res = \db('db_qczl')->insert($params);
  452. if ($res !== false){
  453. cache('WorkOrderVerification-getTable',null);
  454. $this->success('新增成功');
  455. }else{
  456. $this->error('新增失败');
  457. }
  458. }
  459. /**
  460. * 工单核检废品分布
  461. * @ApiMethod GET
  462. * @params string order
  463. */
  464. public function wasteDistribution(){
  465. if (Request::instance()->isGet() == false){
  466. $this->error('非法请求');
  467. }
  468. $params = Request::instance()->param();
  469. if (!isset($params['order']) || empty($params['order'])){
  470. $this->error('参数错误');
  471. }
  472. if (!isset($params['yjno']) || empty($params['yjno'])){
  473. $this->error('参数错误');
  474. }
  475. $field = '
  476. 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,
  477. 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,
  478. 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
  479. ';
  480. // $data = db('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select();
  481. $data = db('db_qczl')->name('db_qczl')
  482. ->where('qczl_gdbh',$params['order'])
  483. ->where('qczl_yjno', $params['yjno'])
  484. ->field($field)->select();
  485. if (empty($data)){
  486. $this->error('暂无废品数据');
  487. }
  488. // 用于存储废品类别和对应废品数量的数组
  489. $categories = array();
  490. // 循环遍历原始数组
  491. foreach ($data as $item) {
  492. // 提取废品类别和对应废品数量
  493. foreach ($item as $key => $value) {
  494. if (strpos($key, "fp_lb") === 0) {
  495. $categoryKey = $key;
  496. $quantityKey = str_replace("fp_lb", "fp_sl", $key);
  497. $quantityValue = $item[$quantityKey];
  498. if (!isset($categories[$value])) {
  499. $categories[$value] = 0;
  500. }
  501. $categories[$value] += (int)$quantityValue;
  502. }
  503. }
  504. }
  505. ksort($categories);
  506. $wasteTotal = db('db_qczl')->where('qczl_gdbh',$params['order'])->sum('qczl_fp');
  507. if (empty($wasteTotal)){
  508. $wasteTotal = 0;
  509. }
  510. $where['a.Gd_gdbh'] = $params['order'];
  511. $where['a.行号'] = 1;
  512. $gdInfo = db('工单_基本资料')->alias('a')
  513. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  514. ->where($where)->field('a.Gd_gdbh,a.实际投料,b.yj_Yjno,b.yj_yjmc')->find();
  515. $gdInfo['yj_Yjno'] = $gdInfo['yj_Yjno'] > 10 ? $gdInfo['yj_Yjno']:'0'.$gdInfo['yj_Yjno'];
  516. $gdInfo['实际投料'] = (int)($gdInfo['实际投料'] * 10000);
  517. $gdInfo['wasteTotal'] = $wasteTotal;
  518. $finishNum = db('成品入仓')->where('jjcp_gdbh',$params['order'])->sum('jjcp_sl');
  519. $gdInfo['passRate'] = '';
  520. if (!empty($finishNum)){
  521. $gdInfo['passRate'] = number_format((int)$finishNum/$gdInfo['实际投料']*100,2).'%';
  522. }
  523. //左侧废品数据
  524. $wasteData = array();
  525. $i = 0;
  526. foreach ($categories as $key=>$value){
  527. if ($value != 0){
  528. $wasteData[$i]['type'] = $key;
  529. $wasteData[$i]['num'] = $value;
  530. $wasteData[$i]['lossesRate'] = number_format($value/$gdInfo['实际投料']*100,4).'%';
  531. $wasteData[$i]['wasteRate'] = number_format($value/$wasteTotal*100,2).'%';
  532. $i++;
  533. }
  534. }
  535. // 按首字母相同的键将值相加
  536. $newArray = array();
  537. foreach ($categories as $key => $value) {
  538. $firstLetter = strtoupper(substr($key, 0, 1)); // 获取首字母并转换为大写
  539. if (!isset($newArray[$firstLetter])) {
  540. $newArray[$firstLetter] = 0;
  541. }
  542. $newArray[$firstLetter] += $value;
  543. }
  544. // 去掉值为零的项
  545. $newArray = array_filter($newArray, function($value) {
  546. return $value !== 0;
  547. });
  548. //右侧废品数据
  549. $rightData = array();
  550. $i = 0;
  551. $name = array();
  552. foreach ($newArray as $key=>$value){
  553. $item = db('erp_常用字典')->where('名称','like','%'.$key.'%')->value('名称');
  554. $item = explode('_',substr($item,0,-1));
  555. $rightData[$i]['type'] = $item[1];
  556. $rightData[$i]['rate'] = number_format($value/$wasteTotal*100,0).'%';
  557. $name[$i] = $item[1];
  558. $i++;
  559. }
  560. $gdInfo['wasteData'] = $wasteData;
  561. $gdInfo['rightData'] = $rightData;
  562. $gdInfo['rightTitle'] = $name;
  563. $this->success('请求成功',$gdInfo);
  564. }
  565. /**
  566. * 获取工单工序状态
  567. * @ApiMethod GET
  568. * @params string order
  569. * 计划产量计算方式:上个工序计划产量-(基础损耗+损耗率*上个工序计划产量)*损耗系数*计损色数)
  570. * lastNum - (Gy0_Rate0 + Gy0_Rate1 * lastNum )* 损耗系数(Gy0_Rate3) * Gy0_Ms
  571. */
  572. public function getOrderDate(){
  573. if (Request::instance()->isGet() == false){
  574. $this->error('非法请求');
  575. }
  576. $params = Request::instance()->param();
  577. if (!isset($params['order']) || empty($params['order'])){
  578. $this->error('参数错误');
  579. }
  580. $where['a.Gy0_gdbh'] = $params['order'];
  581. $where['a.Gy0_sbbh'] = array('neq',' ');
  582. $productNum = db('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料');
  583. $gyData = db('工单_工艺资料')->alias('a')
  584. ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh and a.Gy0_gxh = b.sczl_gxh','left')
  585. ->where($where)
  586. ->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,
  587. a.UniqId,sum(b.sczl_cl) as cl')
  588. ->group('a.Gy0_gxh')
  589. ->select();
  590. $lastNum = $productNum;
  591. $res = [];
  592. foreach ($gyData as $key=> $process) {
  593. $res[$key]['UniqId'] = $process['UniqId'];
  594. $res[$key]['Gy0_yjno'] = $process['Gy0_yjno'] > 10 ? $process['Gy0_yjno'] : '0'.$process['Gy0_yjno'];
  595. $res[$key]['Gy0_gxh'] = $process['Gy0_gxh'] > 10 ? $process['Gy0_gxh'] : '0'.$process['Gy0_gxh'];
  596. $res[$key]['Gy0_gxmc'] = $process['Gy0_gxmc'];
  597. $res[$key]['Gy0_sbbh'] = rtrim($process['Gy0_sbbh']);
  598. $res[$key]['PD_WG'] = $process['PD_WG'];
  599. $res[$key]['finish'] = empty($process['cl']) ? 0: (int)$process['cl'];
  600. // 计算工序计划产量
  601. if ($process["Gy0_gxh"] == "1") {
  602. // 第一道工序直接使用初始计划产量
  603. $Num = $lastNum;
  604. } else {
  605. $Gy0_Ms = $gyData[$key-1]['Gy0_Ms'];
  606. $Gy0_Rate0 = $gyData[$key-1]['Gy0_Rate0'];
  607. $Gy0_Rate1 = $gyData[$key-1]['Gy0_Rate1'];
  608. $Gy0_Rate3 = $gyData[$key-1]['Gy0_Rate3'];
  609. // 大于第一道工序,使用上一道工序的计划产量
  610. // 根据公式计算工序计划产量
  611. if ($Gy0_Ms != "0.00") {
  612. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3 * $Gy0_Ms;
  613. } else {
  614. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3;
  615. }
  616. }
  617. if (trim($process['Gy0_SITE']) == '检验车间'){
  618. $res[$key]['plan'] = (int)$process['Gy0_计划接货数'];
  619. }else{
  620. $res[$key]['plan'] = (int)round($Num);
  621. }
  622. $finish_rate = $res[$key]['finish']/$res[$key]['plan'];
  623. $res[$key]['finish_rate'] = '';
  624. if ($finish_rate != 0){
  625. $res[$key]['finish_rate'] = number_format($finish_rate*100,2).'%';
  626. }
  627. // 更新 $lastNum 为当前工序的计划产量
  628. $lastNum = $Num;
  629. }
  630. $this->success('请求成功',$res);
  631. }
  632. /**
  633. * 工单工序状态更正
  634. * @ApiMethod POST
  635. * @params string UniqId
  636. * @params string date
  637. */
  638. public function editOrderFinishDate(){
  639. if (Request::instance()->isPost() == false){
  640. $this->error('非法请求');
  641. }
  642. $params = Request::instance()->post();
  643. if (!isset($params['UniqId']) || !isset($params['date'])){
  644. $this->error('参数错误');
  645. }
  646. if (empty($params['UniqId'])){
  647. $this->error('参数不能为空');
  648. }
  649. if (empty($params['date'])){
  650. $params['date'] = '1900-01-01 00:00:00';
  651. }
  652. $res = db('工单_工艺资料')->where('UniqId',$params['UniqId'])->setField('PD_WG',$params['date']);
  653. if ($res != false){
  654. $this->success('更新成功');
  655. }else{
  656. $this->error('更新失败');
  657. }
  658. }
  659. /**
  660. * 工单工序生产进程菜单栏
  661. * @ApiMethod GET
  662. * @params string order
  663. */
  664. public function getOrderProcessLeft(){
  665. if (Request::instance()->isGet() == false){
  666. $this->error('非法请求');
  667. }
  668. $params = Request::instance()->param();
  669. if (!isset($params['order']) || empty($params['order'])){
  670. $this->error('参数错误');
  671. }
  672. if (!isset($params['yjno']) || empty($params['yjno'])){
  673. $this->error('参数错误');
  674. }
  675. $where['Gd_gdbh'] = $params['order'];
  676. $where['行号'] = 1;
  677. //工单基本资料
  678. $info = db('工单_基本资料')->where($where)->field('rtrim(成品代号) as code,rtrim(成品名称) as name')->find();
  679. //工艺资料
  680. $option['Gy0_gdbh'] = $params['order'];
  681. $option['Gy0_yjno'] = $params['yjno'];
  682. $gyInfo = db('工单_工艺资料')
  683. ->where($option)
  684. ->where(function ($query) {
  685. $query->where('Gy0_sbbh', '<>', '')
  686. ->whereOr('Gy0_gxmc', '核检')
  687. ->whereOr('Gy0_gxmc', '成品防护');
  688. })
  689. ->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc')
  690. ->select();
  691. foreach ($gyInfo as $key=>$value){
  692. $gyInfo[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
  693. $gyInfo[$key]['Gy0_gxh'] = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
  694. }
  695. $res['Gd_info'] = $info;
  696. $res['Gy_info'] = $gyInfo;
  697. $this->success('请求成功',$res);
  698. }
  699. /**
  700. * 工单工序生产进程右侧
  701. * @ApiMethod GET
  702. * @params string order
  703. * @params string gxNo
  704. */
  705. public function getOrderProcessRight(){
  706. if (Request::instance()->isGet() == false){
  707. $this->error('非法请求');
  708. }
  709. $params = Request::instance()->param();
  710. if (!isset($params['order']) || empty($params['order'])){
  711. $this->error('参数错误');
  712. }
  713. if (!isset($params['yjno']) || empty($params['yjno'])){
  714. $this->error('参数错误');
  715. }
  716. if (!isset($params['gxNo']) || empty($params['gxNo'])){
  717. $this->error('参数错误');
  718. }
  719. $total = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_gdbh',$params['yjno'])->order('sczl_num')->column('distinct(sczl_num)');
  720. $where['sczl_gxh'] = (int)$params['gxNo'];
  721. $where['sczl_gdbh'] = $params['order'];
  722. $where['sczl_yjno'] = $params['yjno'];
  723. //机器设备数据
  724. $process = db('设备_产量计酬')->where($where)->order('sczl_num')->column('distinct(sczl_num)');
  725. //手工数据
  726. $option['qczl_gdbh'] = $params['order'];
  727. $option['qczl_gxh'] = (int)$params['gxNo'];
  728. $option['qczl_yjno'] = $params['yjno'];
  729. $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();
  730. // 提取数据
  731. $result = array();
  732. foreach ($handProcess as $subArray) {
  733. $qczl_num = $subArray["qczl_num"];
  734. $result[] = $qczl_num;
  735. // 提取以qczl_NumDesc开头的键对应的值
  736. for ($i = 1; $i <= 8; $i++) {
  737. $key = "qczl_NumDesc" . $i;
  738. if ($subArray[$key] != 0){
  739. $result[] = $subArray[$key];
  740. }
  741. }
  742. }
  743. // 去重
  744. $result = array_unique($result);
  745. // 对结果进行排序
  746. sort($result);
  747. $res['total_process'] = $total;
  748. $res['process'] = $process;
  749. if (empty($process)){
  750. $res['process'] = $result;
  751. }
  752. $this->success('请求成功',$res);
  753. }
  754. /**
  755. * 核检废品日统计
  756. * @ApiMethod GET
  757. * @params date start_date
  758. * @params date end_date
  759. */
  760. public function getDaysWast()
  761. {
  762. if (Request::instance()->isGet() == false) {
  763. $this->error('非法请求');
  764. }
  765. $params = Request::instance()->param();
  766. if (!isset($params['start_date']) || empty($params['start_date'])) {
  767. $this->error('参数错误');
  768. }
  769. if (!isset($params['end_date']) || empty($params['end_date'])) {
  770. $this->error('参数错误');
  771. }
  772. $where['qczl_rq'] = array('between time', [$params['start_date'], $params['end_date']]);
  773. $field = '
  774. 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,
  775. 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,
  776. 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,
  777. 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,
  778. 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,
  779. 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,
  780. qczl_rq
  781. ';
  782. $resultArray = array();
  783. $key = 'getDaysWast'.$params['start_date'].'/'.$params['end_date'];
  784. $is_have_cache = Cache::has($key);
  785. if ($is_have_cache === false){
  786. $data = db('db_qczl')
  787. ->where($where)
  788. ->where(function ($query) {
  789. for ($i = 1; $i <= 13; $i++) {
  790. $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
  791. }
  792. })
  793. ->field($field)->select();
  794. $list = [];
  795. $j = 0;
  796. foreach ($data as $entry) {
  797. for ($i = 1; $i <= 13; $i++) {
  798. $labelKey = "fp_lb" . $i;
  799. $slKey = "fp_sl" . $i;
  800. $bhKey = "fp_bh" . $i;
  801. $bzKey = "fp_bz" . $i;
  802. if (!empty($entry[$labelKey])) {
  803. if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
  804. $list[$j]['fp_lb'] = $entry[$labelKey];
  805. $list[$j]['fp_sl'] = $entry[$slKey];
  806. $list[$j]['fp_bh'] = $entry[$bhKey];
  807. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  808. $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
  809. $list[$j]['fp_bz'] = $entry[$bzKey];
  810. $list[$j]['qczl_rq'] = $entry['qczl_rq'];
  811. $j++;
  812. }
  813. }
  814. }
  815. }
  816. foreach ($list as $item) {
  817. $found = false;
  818. foreach ($resultArray as &$resultItem) {
  819. if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
  820. $resultItem["fp_sl"] += (int)$item["fp_sl"];
  821. $found = true;
  822. break;
  823. }
  824. }
  825. if (!$found) {
  826. $resultArray[] = $item;
  827. }
  828. }
  829. // 使用usort进行排序
  830. usort($resultArray, function($a, $b) {
  831. // First, sort by fp_lb (K01/K02)
  832. $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
  833. if ($compareLb !== 0) {
  834. return $compareLb;
  835. }
  836. // If fp_lb is the same, prioritize B班 over A班
  837. $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
  838. if ($compareBz !== 0) {
  839. return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
  840. }
  841. // If fp_bz is the same, sort by fp_bh
  842. $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
  843. return $compareBh;
  844. });
  845. Cache::set($key,$resultArray,86400);
  846. }else{
  847. $resultArray = Cache::get($key);
  848. }
  849. $this->success('请求成功',$resultArray);
  850. }
  851. /**
  852. * 月度核检废品责任人统计
  853. * @ApiMethod GET
  854. * @params string date
  855. */
  856. public function getMonthPeopleTotal(){
  857. if (Request::instance()->isGet() == false) {
  858. $this->error('非法请求');
  859. }
  860. $params = Request::instance()->param();
  861. if (!isset($params['date']) || empty($params['date'])) {
  862. $this->error('参数错误');
  863. }
  864. }
  865. /**
  866. * 工单质检废品统计
  867. * @ApiMethod GET
  868. * @params string order
  869. */
  870. public function getOrderWasteTotal(){
  871. if (Request::instance()->isGet() == false) {
  872. $this->error('非法请求');
  873. }
  874. $params = Request::instance()->param();
  875. if (!isset($params['order']) || empty($params['order'])) {
  876. $this->error('参数错误');
  877. }
  878. $field = '
  879. 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,
  880. 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,
  881. 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,
  882. 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,
  883. 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,
  884. 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,
  885. 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.交货日期,
  886. c.yj_ls,d.jjcp_sl,d.jjcp_sj
  887. ';
  888. $where['a.qczl_gdbh'] = $params['order'];
  889. $where['a.qczl_yjno'] = $params['yjno'];
  890. $where['b.行号'] = 1;
  891. $data = db('db_qczl')->alias('a')
  892. ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh','left')
  893. ->join('工单_印件资料 c','a.qczl_gdbh = c.Yj_Gdbh','left')
  894. ->join('成品入仓 d','a.qczl_gdbh = d.jjcp_gdbh','left')
  895. ->where($where)
  896. ->field($field)
  897. // ->where('a.qczl_yjno','1')
  898. ->group('qczl_yjno,qczl_num')
  899. ->select();
  900. $list = [];
  901. $j = 0;
  902. foreach ($data as $entry) {
  903. for ($i = 1; $i <= 13; $i++) {
  904. $labelKey = "fp_lb" . $i;
  905. $slKey = "fp_sl" . $i;
  906. $bhKey = "fp_bh" . $i;
  907. $gxhKey = "fp_gxmc". $i;
  908. if (!empty($entry[$labelKey]) && $entry[$slKey] > 0) {
  909. $list[$j]['fp_lb'] = $entry[$labelKey];
  910. $list[$j]['fp_sl'] = $entry[$slKey];
  911. $list[$j]['fp_bh'] = $entry[$bhKey];
  912. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  913. $list[$j]['fp_name'] = $name;
  914. $list[$j]['fp_gxh'] = empty(substr($entry[$gxhKey],0,2)) ? "0" : substr($entry[$gxhKey],0,2);
  915. $list[$j]['qczl_num'] = $entry['qczl_num'];
  916. $list[$j]['qczl_yjno'] = $entry['qczl_yjno'];
  917. $list[$j]['product_code'] = $entry['product_code'];
  918. $list[$j]['product_name'] = $entry['product_name'];
  919. $list[$j]['订单数量'] = $entry['订单数量'];
  920. $list[$j]['计量单位'] = $entry['计量单位'];
  921. $list[$j]['交货日期'] = substr($entry['交货日期'],0,10);
  922. $list[$j]['yj_ls'] = $entry['yj_ls'];
  923. $list[$j]['jjcp_sl'] = $entry['jjcp_sl'];
  924. $list[$j]['jjcp_sj'] = substr($entry['jjcp_sj'],0,10);
  925. $j++;
  926. }
  927. }
  928. }
  929. $summedData = [];
  930. foreach ($list as $item) {
  931. $key = $item['qczl_num'] . $item['fp_lb'];
  932. if (!isset($summedData[$key])) {
  933. $summedData[$key] = $item;
  934. } else {
  935. $summedData[$key]['fp_sl'] += $item['fp_sl'];
  936. }
  937. }
  938. $fpGxhColumn = array_column($summedData, 'fp_gxh');
  939. $qczlNumColumn = array_column($summedData, 'qczl_num');
  940. $fpLbColumn = array_column($summedData, 'fp_lb');
  941. array_multisort($fpGxhColumn, SORT_ASC, $qczlNumColumn, SORT_ASC, $fpLbColumn, SORT_ASC, $summedData);
  942. $summedData = array_values($summedData);
  943. $this->success('请求成功',$summedData);
  944. }
  945. /**
  946. * 工单核检单删除
  947. * @return void
  948. * @throws \think\Exception
  949. * @throws \think\exception\PDOException
  950. */
  951. public function del()
  952. {
  953. if ($this->request->isGet() === false){
  954. $this->error('请求错误');
  955. }
  956. $param = $this->request->param();
  957. if (empty($param['UniqId'])){
  958. $this->error('参数错误');
  959. }
  960. $res = \db('db_qczl')
  961. ->where('UniqId',$param['UniqId'])
  962. ->delete();
  963. if ($res !== false){
  964. $this->success('删除成功');
  965. }else{
  966. $this->error('产出失败');
  967. }
  968. }
  969. }