WorkOrderVerification.php 37 KB

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