PackagingCountDocument.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. $page = 1;
  66. $limit = 15;
  67. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  68. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  69. $where = [];
  70. if (isset($req['date']) && !empty($req['date'])){
  71. $where['b.sys_rq'] = ['LIKE',$req['date'].'%'];
  72. }else{
  73. $this->error('参数错误');
  74. }
  75. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['b.sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  76. $rows = db()->table('db_包装计件')->alias('b')
  77. ->field('b.sczl_bh, rtrim(r.员工姓名) as name, b.sczl_rq, b.sczl_bzdh,
  78. b.sczl_cl1 + b.sczl_cl2 + b.sczl_cl3 + b.sczl_cl4 + b.sczl_cl5 + b.sczl_cl6 as sczl_cl,
  79. b.sczl_返工产量1 + b.sczl_返工产量2 + b.sczl_返工产量3 + b.sczl_返工产量4 + b.sczl_返工产量5 + b.sczl_返工产量6 as sczl_fgsl,
  80. 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,
  81. b.sczl_gdbh1, rtrim(b.sys_id) as sys_id, b.sys_rq, b.mod_rq, b.UniqId')
  82. ->where($where)
  83. ->join(['人事_基本资料'=>'r'],'b.sczl_bh = r.员工编号')
  84. ->page($page,$limit)
  85. ->select();
  86. $data = [
  87. 'rows' => $rows,
  88. ];
  89. $this->success('成功',$data);
  90. }
  91. /**
  92. * 获取包装计件单据信息
  93. * @ApiMethod (GET)
  94. * @param string $UniqId UniqId
  95. */
  96. public function getInfo()
  97. {
  98. //get请求
  99. if(!$this->request->isGet()){
  100. $this->error('请求方式错误');
  101. }
  102. $req = $this->request->param();
  103. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  104. $UniqId = $req['UniqId'];
  105. }else{
  106. $this->error('参数错误');
  107. }
  108. $rows = db()->table('db_包装计件')->alias('d')
  109. ->field('d.*, ')
  110. ->join('工单_基本资料 g', 'd.')
  111. ->where('d.UniqId',$UniqId)
  112. ->select();
  113. $this->success('成功',$rows);
  114. }
  115. }