WorkOrderVerification.php 42 KB

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