WorkOrderVerification.php 48 KB

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