PackagingCountDocument.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 包装计件单据维护接口
  6. */
  7. class PackagingCountDocument extends Api
  8. {
  9. protected $noNeedLogin = ['*'];
  10. protected $noNeedRight = ['*'];
  11. /**
  12. * 首页
  13. *
  14. */
  15. public function index()
  16. {
  17. $this->success('请求成功');
  18. }
  19. /**
  20. * 获取包装计件单据侧边栏
  21. * @ApiMethod (GET)
  22. */
  23. public function getTab()
  24. {
  25. //get请求
  26. if(!$this->request->isGet()){
  27. $this->error('请求方式错误');
  28. }
  29. $rows = db()->table('db_包装计件')
  30. ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  31. ->group('date')
  32. ->order('UniqId desc')
  33. ->limit(30)
  34. ->select();
  35. $arr = db()->table('db_包装计件')
  36. ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
  37. ->where('sys_rq','>=',$rows[29]['date'])
  38. ->group('date, sys_id')
  39. ->select();
  40. foreach($rows as $key=>$value){
  41. $rows[$key]['sys'] = [];
  42. foreach($arr as $k=>$v){
  43. if($value['date'] == $v['date']){
  44. unset($v['date']);
  45. array_push($rows[$key]['sys'],$v);
  46. unset($arr[$k]);
  47. }
  48. }
  49. }
  50. $this->success('成功',$rows);
  51. }
  52. /**
  53. * 获取包装计件单据列表
  54. * @ApiMethod (GET)
  55. * @param string $date 时间
  56. * @param string $sys_id 用户
  57. */
  58. public function getList()
  59. {
  60. //get请求
  61. if(!$this->request->isGet()){
  62. $this->error('请求方式错误');
  63. }
  64. $req = $this->request->param();
  65. $where = [];
  66. if (isset($req['date']) && !empty($req['date'])){
  67. $where['b.sys_rq'] = ['LIKE',$req['date'].'%'];
  68. }else{
  69. $this->error('参数错误');
  70. }
  71. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['b.sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  72. $rows = db()->table('db_包装计件')->alias('b')
  73. ->field('b.sczl_bh, rtrim(r.员工姓名) as name, b.sczl_rq, b.sczl_bzdh,
  74. b.sczl_cl1 + b.sczl_cl2 + b.sczl_cl3 + b.sczl_cl4 + b.sczl_cl5 + b.sczl_cl6 as sczl_cl,
  75. b.sczl_返工产量1 + b.sczl_返工产量2 + b.sczl_返工产量3 + b.sczl_返工产量4 + b.sczl_返工产量5 + b.sczl_返工产量6 as sczl_fgsl,
  76. b.sczl_cl1 + b.sczl_cl2 + b.sczl_cl3 + b.sczl_cl4 + b.sczl_cl5 + b.sczl_cl6 + b.sczl_返工产量1 + b.sczl_返工产量2 + b.sczl_返工产量3 + b.sczl_返工产量4 + b.sczl_返工产量5 + b.sczl_返工产量6 as sczl_jjcl,
  77. b.sczl_gdbh1, rtrim(b.sys_id) as sys_id, b.sys_rq, b.mod_rq, b.UniqId')
  78. ->where($where)
  79. ->join(['人事_基本资料'=>'r'],'b.sczl_bh = r.员工编号')
  80. ->select();
  81. $data = [
  82. 'rows' => $rows,
  83. ];
  84. $this->success('成功',$data);
  85. }
  86. /**
  87. * 获取包装计件单据信息
  88. * @ApiMethod (GET)
  89. * @param string $UniqId UniqId
  90. */
  91. public function getInfo()
  92. {
  93. //get请求
  94. if(!$this->request->isGet()){
  95. $this->error('请求方式错误');
  96. }
  97. $req = $this->request->param();
  98. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  99. $UniqId = $req['UniqId'];
  100. }else{
  101. $this->error('参数错误');
  102. }
  103. $rows = db()->table('db_包装计件')->alias('d')
  104. ->field('d.*, ')
  105. ->join('工单_基本资料 g', 'd.')
  106. ->where('d.UniqId',$UniqId)
  107. ->select();
  108. $this->success('成功',$rows);
  109. }
  110. }