WorkOrderVerification.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  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('qczl_gdbh,qczl_yjno,qczl_num')
  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)->order('次序 desc')->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. }elseif ($searchArr[1] === '拆片'){
  394. $search = substr($searchArr[1],0,6);
  395. $where['a.sczl_type'] = array('like','%'.$search.'%');
  396. $list = db('db_sczl')->alias('a')
  397. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  398. ->where($where)
  399. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  400. ->select();
  401. }elseif($searchArr[1] === '检验'){
  402. $where['a.sczl_gxmc'] = ['like','%'.'检'.'%'];
  403. $list = db('设备_产量计酬')->alias('a')
  404. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  405. ->where($where)
  406. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  407. ->select();
  408. }else{
  409. $search = substr($searchArr[1],0,6);
  410. $where['a.sczl_type'] = array('like','%'.$search.'%');
  411. $list = db('设备_产量计酬')->alias('a')
  412. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  413. ->where($where)
  414. ->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  415. ->select();
  416. }
  417. $count = count($list);
  418. $list[$count]['sczl_gxmc'] = '99-外发加工';
  419. $list[$count]['sczl_bzdh'] = 'A班';
  420. $list[$count]['sczl_jtbh'] = '';
  421. $list[$count]['sczl_bh1'] = '000000';
  422. $list[$count]['name'] = '计时工';
  423. $this->success('请求成功',$list);
  424. }
  425. /**
  426. * 修改工单核检单
  427. * @ApiMethod POST
  428. * @params array data
  429. */
  430. public function edit(){
  431. if (Request::instance()->isPost() == false){
  432. $this->error('非法请求');
  433. }
  434. $params = Request::instance()->post();
  435. if (!isset($params['UniqId'])){
  436. $this->error('参数不能为空');
  437. }
  438. $id = $params['UniqId'];
  439. unset($params['UniqId']);
  440. $sql = db('db_qczl')->where('UniqId',$id)->fetchSql(true)->update($params);
  441. $res = Db::query($sql);
  442. if ($res !== 0){
  443. cache('WorkOrderVerification-getTable',null);
  444. $this->success('更新成功');
  445. }else{
  446. $this->error('更新失败');
  447. }
  448. }
  449. /**
  450. * 新增工单核检单
  451. * @ApiMethod POST
  452. * @params array data
  453. */
  454. public function add(){
  455. if (Request::instance()->isPost() == false){
  456. $this->error('非法请求');
  457. }
  458. $params = Request::instance()->post();
  459. $UniqId = db('db_qczl')->order('UniqId desc')->value('UniqId');
  460. if ($UniqId < 10000000){
  461. $UniqId = 10000000;
  462. }else{
  463. $UniqId = $UniqId + 1;
  464. }
  465. $params['UniqId'] = $UniqId;
  466. $params['sys_rq'] = date('Y-m-d H:i:s');
  467. $res = \db('db_qczl')->insert($params);
  468. if ($res !== false){
  469. cache('WorkOrderVerification-getTable',null);
  470. $this->success('新增成功');
  471. }else{
  472. $this->error('新增失败');
  473. }
  474. }
  475. /**
  476. * 工单核检废品分布
  477. * @ApiMethod GET
  478. * @params string order
  479. */
  480. public function wasteDistribution(){
  481. if (Request::instance()->isGet() == false){
  482. $this->error('非法请求');
  483. }
  484. $params = Request::instance()->param();
  485. if (!isset($params['order']) || empty($params['order'])){
  486. $this->error('参数错误');
  487. }
  488. if (!isset($params['yjno']) || empty($params['yjno'])){
  489. $this->error('参数错误');
  490. }
  491. $field = '
  492. 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,
  493. 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,
  494. 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
  495. ';
  496. // $data = db('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select();
  497. $data = db('db_qczl')->name('db_qczl')
  498. ->where('qczl_gdbh',$params['order'])
  499. ->where('qczl_yjno', $params['yjno'])
  500. ->field($field)->select();
  501. if (empty($data)){
  502. $this->error('暂无废品数据');
  503. }
  504. // 用于存储废品类别和对应废品数量的数组
  505. $categories = array();
  506. // 循环遍历原始数组
  507. foreach ($data as $item) {
  508. // 提取废品类别和对应废品数量
  509. foreach ($item as $key => $value) {
  510. if (strpos($key, "fp_lb") === 0) {
  511. $categoryKey = $key;
  512. $quantityKey = str_replace("fp_lb", "fp_sl", $key);
  513. $quantityValue = $item[$quantityKey];
  514. if (!isset($categories[$value])) {
  515. $categories[$value] = 0;
  516. }
  517. $categories[$value] += (int)$quantityValue;
  518. }
  519. }
  520. }
  521. ksort($categories);
  522. $wasteTotal = db('db_qczl')->where('qczl_gdbh',$params['order'])->sum('qczl_fp');
  523. if (empty($wasteTotal)){
  524. $wasteTotal = 0;
  525. }
  526. $where['a.Gd_gdbh'] = $params['order'];
  527. $where['a.行号'] = 1;
  528. $gdInfo = db('工单_基本资料')->alias('a')
  529. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  530. ->where($where)->field('a.Gd_gdbh,a.实际投料,b.yj_Yjno,b.yj_yjmc')->find();
  531. $gdInfo['yj_Yjno'] = $gdInfo['yj_Yjno'] > 10 ? $gdInfo['yj_Yjno']:'0'.$gdInfo['yj_Yjno'];
  532. $gdInfo['实际投料'] = (int)($gdInfo['实际投料'] * 10000);
  533. $gdInfo['wasteTotal'] = $wasteTotal;
  534. $finishNum = db('成品入仓')->where('jjcp_gdbh',$params['order'])->sum('jjcp_sl');
  535. $gdInfo['passRate'] = '';
  536. if (!empty($finishNum)){
  537. $gdInfo['passRate'] = number_format((int)$finishNum/$gdInfo['实际投料']*100,2).'%';
  538. }
  539. //左侧废品数据
  540. $wasteData = array();
  541. $i = 0;
  542. foreach ($categories as $key=>$value){
  543. if ($value != 0){
  544. $wasteData[$i]['type'] = $key;
  545. $wasteData[$i]['num'] = $value;
  546. $wasteData[$i]['lossesRate'] = number_format($value/$gdInfo['实际投料']*100,4).'%';
  547. $wasteData[$i]['wasteRate'] = number_format($value/$wasteTotal*100,2).'%';
  548. $i++;
  549. }
  550. }
  551. // 按首字母相同的键将值相加
  552. $newArray = array();
  553. foreach ($categories as $key => $value) {
  554. $firstLetter = strtoupper(substr($key, 0, 1)); // 获取首字母并转换为大写
  555. if (!isset($newArray[$firstLetter])) {
  556. $newArray[$firstLetter] = 0;
  557. }
  558. $newArray[$firstLetter] += $value;
  559. }
  560. // 去掉值为零的项
  561. $newArray = array_filter($newArray, function($value) {
  562. return $value !== 0;
  563. });
  564. //右侧废品数据
  565. $rightData = array();
  566. $i = 0;
  567. $name = array();
  568. foreach ($newArray as $key=>$value){
  569. $item = db('erp_常用字典')->where('名称','like','%'.$key.'%')->value('名称');
  570. $item = explode('_',substr($item,0,-1));
  571. $rightData[$i]['type'] = $item[1];
  572. $rightData[$i]['rate'] = number_format($value/$wasteTotal*100,0).'%';
  573. $name[$i] = $item[1];
  574. $i++;
  575. }
  576. $gdInfo['wasteData'] = $wasteData;
  577. $gdInfo['rightData'] = $rightData;
  578. $gdInfo['rightTitle'] = $name;
  579. $this->success('请求成功',$gdInfo);
  580. }
  581. /**
  582. * 获取工单工序状态
  583. * @ApiMethod GET
  584. * @params string order
  585. * 计划产量计算方式:上个工序计划产量-(基础损耗+损耗率*上个工序计划产量)*损耗系数*计损色数)
  586. * lastNum - (Gy0_Rate0 + Gy0_Rate1 * lastNum )* 损耗系数(Gy0_Rate3) * Gy0_Ms
  587. */
  588. public function getOrderDate(){
  589. if (Request::instance()->isGet() == false){
  590. $this->error('非法请求');
  591. }
  592. $params = Request::instance()->param();
  593. if (!isset($params['order']) || empty($params['order'])){
  594. $this->error('参数错误');
  595. }
  596. $where['a.Gy0_gdbh'] = $params['order'];
  597. $where['a.Gy0_sbbh'] = array('neq',' ');
  598. $productNum = db('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料');
  599. $gyData = db('工单_工艺资料')->alias('a')
  600. ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh and a.Gy0_gxh = b.sczl_gxh','left')
  601. ->where($where)
  602. ->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,
  603. a.UniqId,sum(b.sczl_cl) as cl')
  604. ->group('a.Gy0_gxh')
  605. ->select();
  606. $lastNum = $productNum;
  607. $res = [];
  608. foreach ($gyData as $key=> $process) {
  609. $res[$key]['UniqId'] = $process['UniqId'];
  610. $res[$key]['Gy0_yjno'] = $process['Gy0_yjno'] > 10 ? $process['Gy0_yjno'] : '0'.$process['Gy0_yjno'];
  611. $res[$key]['Gy0_gxh'] = $process['Gy0_gxh'] > 10 ? $process['Gy0_gxh'] : '0'.$process['Gy0_gxh'];
  612. $res[$key]['Gy0_gxmc'] = $process['Gy0_gxmc'];
  613. $res[$key]['Gy0_sbbh'] = rtrim($process['Gy0_sbbh']);
  614. $res[$key]['PD_WG'] = $process['PD_WG'];
  615. $res[$key]['finish'] = empty($process['cl']) ? 0: (int)$process['cl'];
  616. // 计算工序计划产量
  617. if ($process["Gy0_gxh"] == "1") {
  618. // 第一道工序直接使用初始计划产量
  619. $Num = $lastNum;
  620. } else {
  621. $Gy0_Ms = $gyData[$key-1]['Gy0_Ms'];
  622. $Gy0_Rate0 = $gyData[$key-1]['Gy0_Rate0'];
  623. $Gy0_Rate1 = $gyData[$key-1]['Gy0_Rate1'];
  624. $Gy0_Rate3 = $gyData[$key-1]['Gy0_Rate3'];
  625. // 大于第一道工序,使用上一道工序的计划产量
  626. // 根据公式计算工序计划产量
  627. if ($Gy0_Ms != "0.00") {
  628. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3 * $Gy0_Ms;
  629. } else {
  630. $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3;
  631. }
  632. }
  633. if (trim($process['Gy0_SITE']) == '检验车间'){
  634. $res[$key]['plan'] = (int)$process['Gy0_计划接货数'];
  635. }else{
  636. $res[$key]['plan'] = (int)round($Num);
  637. }
  638. $finish_rate = $res[$key]['finish']/$res[$key]['plan'];
  639. $res[$key]['finish_rate'] = '';
  640. if ($finish_rate != 0){
  641. $res[$key]['finish_rate'] = number_format($finish_rate*100,2).'%';
  642. }
  643. // 更新 $lastNum 为当前工序的计划产量
  644. $lastNum = $Num;
  645. }
  646. $this->success('请求成功',$res);
  647. }
  648. /**
  649. * 工单工序状态更正
  650. * @ApiMethod POST
  651. * @params string UniqId
  652. * @params string date
  653. */
  654. public function editOrderFinishDate(){
  655. if (Request::instance()->isPost() == false){
  656. $this->error('非法请求');
  657. }
  658. $params = Request::instance()->post();
  659. if (!isset($params['UniqId']) || !isset($params['date'])){
  660. $this->error('参数错误');
  661. }
  662. if (empty($params['UniqId'])){
  663. $this->error('参数不能为空');
  664. }
  665. if (empty($params['date'])){
  666. $params['date'] = '1900-01-01 00:00:00';
  667. }
  668. $res = db('工单_工艺资料')->where('UniqId',$params['UniqId'])->setField('PD_WG',$params['date']);
  669. if ($res != false){
  670. $this->success('更新成功');
  671. }else{
  672. $this->error('更新失败');
  673. }
  674. }
  675. /**
  676. * 工单工序生产进程菜单栏
  677. * @ApiMethod GET
  678. * @params string order
  679. */
  680. public function getOrderProcessLeft(){
  681. if (Request::instance()->isGet() == false){
  682. $this->error('非法请求');
  683. }
  684. $params = Request::instance()->param();
  685. if (!isset($params['order']) || empty($params['order'])){
  686. $this->error('参数错误');
  687. }
  688. if (!isset($params['yjno']) || empty($params['yjno'])){
  689. $this->error('参数错误');
  690. }
  691. $where['Gd_gdbh'] = $params['order'];
  692. // $where['行号'] = 1;
  693. //工单基本资料
  694. $info = db('工单_基本资料')->where($where)->field('rtrim(成品代号) as code,rtrim(成品名称) as name')->find();
  695. //工艺资料
  696. $option['Gy0_gdbh'] = $params['order'];
  697. $option['Gy0_yjno'] = $params['yjno'];
  698. $gyInfo = db('工单_工艺资料')
  699. ->where($option)
  700. ->where(function ($query) {
  701. $query->where('Gy0_sbbh', '<>', '')
  702. ->whereOr('Gy0_gxmc', '核检')
  703. ->whereOr('Gy0_gxmc', '抽检')
  704. ->whereOr('Gy0_gxmc', '成品防护');
  705. })
  706. ->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc')
  707. ->select();
  708. foreach ($gyInfo as $key=>$value){
  709. $gyInfo[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
  710. $gyInfo[$key]['Gy0_gxh'] = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
  711. }
  712. $res['Gd_info'] = $info;
  713. $res['Gy_info'] = $gyInfo;
  714. $this->success('请求成功',$res);
  715. }
  716. /**
  717. * 工单工序生产进程右侧
  718. * @ApiMethod GET
  719. * @params string order
  720. * @params string gxNo
  721. */
  722. public function getOrderProcessRight(){
  723. if (Request::instance()->isGet() == false){
  724. $this->error('非法请求');
  725. }
  726. $params = Request::instance()->param();
  727. if (!isset($params['order']) || empty($params['order'])){
  728. $this->error('参数错误');
  729. }
  730. if (!isset($params['yjno']) || empty($params['yjno'])){
  731. $this->error('参数错误');
  732. }
  733. if (!isset($params['gxNo']) || empty($params['gxNo'])){
  734. $this->error('参数错误');
  735. }
  736. $total = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yjno'])->order('sczl_num')->column('distinct(sczl_num)');
  737. $where['sczl_gxh'] = (int)$params['gxNo'];
  738. $where['sczl_gdbh'] = $params['order'];
  739. $where['sczl_yjno'] = $params['yjno'];
  740. //机器设备数据
  741. $process = db('设备_产量计酬')->where($where)->order('sczl_num')->column('distinct(sczl_num)');
  742. //手工数据
  743. $option['qczl_gdbh'] = $params['order'];
  744. $option['qczl_gxh'] = (int)$params['gxNo'];
  745. $option['qczl_yjno'] = $params['yjno'];
  746. $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();
  747. // 提取数据
  748. $result = array();
  749. foreach ($handProcess as $subArray) {
  750. $qczl_num = $subArray["qczl_num"];
  751. $result[] = $qczl_num;
  752. // 提取以qczl_NumDesc开头的键对应的值
  753. for ($i = 1; $i <= 8; $i++) {
  754. $key = "qczl_NumDesc" . $i;
  755. if ($subArray[$key] != 0){
  756. $result[] = $subArray[$key];
  757. }
  758. }
  759. }
  760. // 去重
  761. $result = array_unique($result);
  762. // 对结果进行排序
  763. sort($result);
  764. $res['total_process'] = $total;
  765. $res['process'] = $process;
  766. if (empty($process)){
  767. $res['process'] = $result;
  768. }
  769. $this->success('请求成功',$res);
  770. }
  771. /**
  772. * 核检废品日统计
  773. * @ApiMethod GET
  774. * @params date start_date
  775. * @params date end_date
  776. */
  777. public function getDaysWast()
  778. {
  779. if (Request::instance()->isGet() == false) {
  780. $this->error('非法请求');
  781. }
  782. $params = Request::instance()->param();
  783. if (!isset($params['start_date']) || empty($params['start_date'])) {
  784. $this->error('参数错误');
  785. }
  786. if (!isset($params['end_date']) || empty($params['end_date'])) {
  787. $this->error('参数错误');
  788. }
  789. $where['qczl_rq'] = array('between time', [$params['start_date'], $params['end_date']]);
  790. $field = '
  791. 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,
  792. 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,
  793. 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,
  794. 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,
  795. 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,
  796. 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,
  797. qczl_rq
  798. ';
  799. $resultArray = array();
  800. $key = 'getDaysWast'.$params['start_date'].'/'.$params['end_date'];
  801. $is_have_cache = Cache::has($key);
  802. if ($is_have_cache === false){
  803. $data = db('db_qczl')
  804. ->where($where)
  805. ->where(function ($query) {
  806. for ($i = 1; $i <= 13; $i++) {
  807. $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
  808. }
  809. })
  810. ->field($field)->select();
  811. $list = [];
  812. $j = 0;
  813. foreach ($data as $entry) {
  814. for ($i = 1; $i <= 13; $i++) {
  815. $labelKey = "fp_lb" . $i;
  816. $slKey = "fp_sl" . $i;
  817. $bhKey = "fp_bh" . $i;
  818. $bzKey = "fp_bz" . $i;
  819. if (!empty($entry[$labelKey])) {
  820. if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
  821. $list[$j]['fp_lb'] = $entry[$labelKey];
  822. $list[$j]['fp_sl'] = $entry[$slKey];
  823. $list[$j]['fp_bh'] = $entry[$bhKey];
  824. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  825. $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
  826. $list[$j]['fp_bz'] = $entry[$bzKey];
  827. $list[$j]['qczl_rq'] = $entry['qczl_rq'];
  828. $j++;
  829. }
  830. }
  831. }
  832. }
  833. foreach ($list as $item) {
  834. $found = false;
  835. foreach ($resultArray as &$resultItem) {
  836. if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
  837. $resultItem["fp_sl"] += (int)$item["fp_sl"];
  838. $found = true;
  839. break;
  840. }
  841. }
  842. if (!$found) {
  843. $resultArray[] = $item;
  844. }
  845. }
  846. // 使用usort进行排序
  847. usort($resultArray, function($a, $b) {
  848. // First, sort by fp_lb (K01/K02)
  849. $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
  850. if ($compareLb !== 0) {
  851. return $compareLb;
  852. }
  853. // If fp_lb is the same, prioritize B班 over A班
  854. $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
  855. if ($compareBz !== 0) {
  856. return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
  857. }
  858. // If fp_bz is the same, sort by fp_bh
  859. $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
  860. return $compareBh;
  861. });
  862. Cache::set($key,$resultArray,86400);
  863. }else{
  864. $resultArray = Cache::get($key);
  865. }
  866. $this->success('请求成功',$resultArray);
  867. }
  868. /**
  869. * 月度核检废品责任人统计
  870. * @ApiMethod GET
  871. * @params string date
  872. */
  873. public function getMonthPeopleTotal(){
  874. if (Request::instance()->isGet() == false) {
  875. $this->error('非法请求');
  876. }
  877. $params = Request::instance()->param();
  878. if (!isset($params['date']) || empty($params['date'])) {
  879. $this->error('参数错误');
  880. }
  881. }
  882. /**
  883. * 工单质检废品统计
  884. * @ApiMethod GET
  885. * @params string order
  886. */
  887. public function getOrderWasteTotal(){
  888. if (Request::instance()->isGet() == false) {
  889. $this->error('非法请求');
  890. }
  891. $params = Request::instance()->param();
  892. if (!isset($params['order']) || empty($params['order'])) {
  893. $this->error('参数错误');
  894. }
  895. $field = '
  896. 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,
  897. 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,
  898. 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,
  899. 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,
  900. 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,
  901. 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,
  902. 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.交货日期,
  903. c.yj_ls,d.jjcp_sl,d.jjcp_sj
  904. ';
  905. $where['a.qczl_gdbh'] = $params['order'];
  906. $where['a.qczl_yjno'] = $params['yjno'];
  907. // $where['b.行号'] = 1;
  908. $data = db('db_qczl')->alias('a')
  909. ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh','left')
  910. ->join('工单_印件资料 c','a.qczl_gdbh = c.Yj_Gdbh','left')
  911. ->join('成品入仓 d','a.qczl_gdbh = d.jjcp_gdbh','left')
  912. ->where($where)
  913. ->field($field)
  914. // ->where('a.qczl_yjno','1')
  915. ->group('qczl_yjno,qczl_num')
  916. ->select();
  917. $list = [];
  918. $j = 0;
  919. foreach ($data as $entry) {
  920. for ($i = 1; $i <= 13; $i++) {
  921. $labelKey = "fp_lb" . $i;
  922. $slKey = "fp_sl" . $i;
  923. $bhKey = "fp_bh" . $i;
  924. $gxhKey = "fp_gxmc". $i;
  925. if (!empty($entry[$labelKey]) && $entry[$slKey] > 0) {
  926. $list[$j]['fp_lb'] = $entry[$labelKey];
  927. $list[$j]['fp_sl'] = $entry[$slKey];
  928. $list[$j]['fp_bh'] = $entry[$bhKey];
  929. $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
  930. $list[$j]['fp_name'] = $name;
  931. $list[$j]['fp_gxh'] = empty(substr($entry[$gxhKey],0,2)) ? "0" : substr($entry[$gxhKey],0,2);
  932. $list[$j]['qczl_num'] = $entry['qczl_num'];
  933. $list[$j]['qczl_yjno'] = $entry['qczl_yjno'];
  934. $list[$j]['product_code'] = $entry['product_code'];
  935. $list[$j]['product_name'] = $entry['product_name'];
  936. $list[$j]['订单数量'] = $entry['订单数量'];
  937. $list[$j]['计量单位'] = $entry['计量单位'];
  938. $list[$j]['交货日期'] = substr($entry['交货日期'],0,10);
  939. $list[$j]['yj_ls'] = $entry['yj_ls'];
  940. $list[$j]['jjcp_sl'] = $entry['jjcp_sl'];
  941. $list[$j]['jjcp_sj'] = substr($entry['jjcp_sj'],0,10);
  942. $j++;
  943. }
  944. }
  945. }
  946. $summedData = [];
  947. foreach ($list as $item) {
  948. $key = $item['qczl_num'] . $item['fp_lb'];
  949. if (!isset($summedData[$key])) {
  950. $summedData[$key] = $item;
  951. } else {
  952. $summedData[$key]['fp_sl'] += $item['fp_sl'];
  953. }
  954. }
  955. $fpGxhColumn = array_column($summedData, 'fp_gxh');
  956. $qczlNumColumn = array_column($summedData, 'qczl_num');
  957. $fpLbColumn = array_column($summedData, 'fp_lb');
  958. array_multisort($fpGxhColumn, SORT_ASC, $qczlNumColumn, SORT_ASC, $fpLbColumn, SORT_ASC, $summedData);
  959. $summedData = array_values($summedData);
  960. $this->success('请求成功',$summedData);
  961. }
  962. /**
  963. * 工单核检单删除
  964. * @return void
  965. * @throws \think\Exception
  966. * @throws \think\exception\PDOException
  967. */
  968. public function del()
  969. {
  970. if ($this->request->isGet() === false){
  971. $this->error('请求错误');
  972. }
  973. $param = $this->request->param();
  974. if (empty($param['UniqId'])){
  975. $this->error('参数错误');
  976. }
  977. $res = \db('db_qczl')
  978. ->where('UniqId',$param['UniqId'])
  979. ->delete();
  980. if ($res !== false){
  981. $this->success('删除成功');
  982. }else{
  983. $this->error('产出失败');
  984. }
  985. }
  986. public function getJunkdata()
  987. {
  988. if ($this->request->isGet() === false){
  989. $this->error('请求错误');
  990. }
  991. $param = $this->request->param();
  992. if (empty($param)){
  993. $this->error('参数错误');
  994. }
  995. $sql = "SELECT
  996. a.jjcp_gdbh,
  997. a.jjcp_yjno,
  998. a.jjcp_sj,
  999. a.jjcp_sl,
  1000. a.成品名称,
  1001. b.fp_lb1,
  1002. b.fp_lb2,
  1003. b.fp_lb3,
  1004. b.fp_lb4,
  1005. b.fp_lb5,
  1006. b.fp_lb6,
  1007. b.fp_lb7,
  1008. b.fp_lb8,
  1009. b.fp_lb9,
  1010. b.fp_lb10,
  1011. b.fp_lb11,
  1012. b.fp_lb12,
  1013. b.fp_lb13,
  1014. b.fp_gxmc1,
  1015. b.fp_gxmc2,
  1016. b.fp_gxmc3,
  1017. b.fp_gxmc4,
  1018. b.fp_gxmc5,
  1019. b.fp_gxmc6,
  1020. b.fp_gxmc7,
  1021. b.fp_gxmc8,
  1022. b.fp_gxmc9,
  1023. b.fp_gxmc10,
  1024. b.fp_gxmc11,
  1025. b.fp_gxmc12,
  1026. b.fp_gxmc13,
  1027. b.fp_sl1,
  1028. b.fp_sl2,
  1029. b.fp_sl3,
  1030. b.fp_sl4,
  1031. b.fp_sl5,
  1032. b.fp_sl6,
  1033. b.fp_sl7,
  1034. b.fp_sl8,
  1035. b.fp_sl9,
  1036. b.fp_sl10,
  1037. b.fp_sl11,
  1038. b.fp_sl12,
  1039. b.fp_sl13,
  1040. sum(b.qczl_fp) as fp,
  1041. b.UniqId,
  1042. c.实际投料 * 10000
  1043. FROM
  1044. `成品入仓` `a`
  1045. LEFT JOIN db_qczl b ON a.jjcp_gdbh = b.qczl_gdbh AND a.jjcp_yjno = b.qczl_yjno
  1046. JOIN `工单_基本资料` c ON a.jjcp_gdbh = c.Gd_gdbh AND a.jjcp_yjno = c.`行号`
  1047. WHERE
  1048. (a.jjcp_sj LIKE '2024-07%'
  1049. OR a.jjcp_sj LIKE '2024-08%')
  1050. AND (b.qczl_fp <> null or b.qczl_fp > 0)
  1051. AND a.成品编码 like 'J0031%'
  1052. GROUP BY
  1053. b.UniqId";
  1054. $res = \db()->query($sql);
  1055. // halt($res);
  1056. $data = [];
  1057. foreach ($res as $key=>$value){
  1058. if (isset($data[$value['jjcp_gdbh']]) === false){
  1059. if (isset($data[$value['jjcp_gdbh']][$value['jjcp_yjno']]) === false){
  1060. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']] = [];
  1061. }
  1062. }
  1063. if (isset($data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['废品总数']) === false){
  1064. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['废品总数'] = $value['fp'];
  1065. }else{
  1066. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['废品总数'] += $value['fp'];
  1067. }
  1068. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']]['实际投料'] = $value['c.实际投料 * 10000'];
  1069. for ($i=1;$i<14;$i++){
  1070. if ($value['fp_gxmc'.$i] !== ''){
  1071. if (isset($data[$value['jjcp_gdbh']][$value['jjcp_yjno']][$value['fp_lb'.$i]]) === false){
  1072. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']][$value['fp_lb'.$i]] = $value['fp_sl'.$i];
  1073. }else{
  1074. $data[$value['jjcp_gdbh']][$value['jjcp_yjno']][$value['fp_lb'.$i]] += $value['fp_sl'.$i];
  1075. }
  1076. }
  1077. }
  1078. }
  1079. $list = [];
  1080. foreach ($data as $key=>$value){
  1081. foreach ($value as $k=>$v){
  1082. $i = 0;
  1083. foreach ($v as $kk=>$vv){
  1084. if ($kk !== '废品总数' && $kk !== '实际投料'){
  1085. $list[$key][$k][$i] = [
  1086. '类型' => $kk,
  1087. '数量' => $vv,
  1088. '废品占比' => number_format($vv/$v['废品总数']*100,4).'%',
  1089. '报损占比' => number_format($vv/$v['实际投料']*100,4).'%',
  1090. ];
  1091. $i++;
  1092. $result = [
  1093. '类型' => $kk,
  1094. '数量' => $vv,
  1095. '废品占比' => number_format($vv/$v['废品总数']*100,4).'%',
  1096. '报损占比' => number_format($vv/$v['实际投料']*100,4).'%',
  1097. '工单编号' => $key,
  1098. '印件号' => $k
  1099. ];
  1100. $sql = \db('废品报表')->fetchSql(true)->insert($result);
  1101. $reult = \db()->query($sql);
  1102. }
  1103. }
  1104. }
  1105. }
  1106. // $this->success('成功',$list);
  1107. }
  1108. }