WorkOrderVerification.php 39 KB

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