OtherCountDocument.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 其他计件单据维护接口
  6. */
  7. class OtherCountDocument 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(Sczl_rq, 7) as date, CAST(sum(Sczl_cl) AS SIGNED) as counts')
  31. // ->group('LEFT(Sczl_rq, 7)')
  32. // ->order('UniqId desc')
  33. // ->paginate(13);
  34. //halt($rows);
  35. // $rows->each(function ($item){
  36. // $arr = db()->table('db_拉料计件')->alias('l')
  37. // ->field('rtrim(l.Sczl_bh1) as Sczl_bh1, rtrim(r.员工姓名) as name, sum(l.Sczl_cl) as count')
  38. // ->where('l.sczl_rq','LIKE',$item['date'].'%')
  39. // ->join(['人事_基本资料'=>'r'],'l.Sczl_bh1 = r.员工编号')
  40. // ->group('Sczl_bh1')
  41. // ->select();
  42. //
  43. // $item['sys']=$arr;
  44. // });
  45. // halt($rows);
  46. $rows = db()->table('db_拉料计件')
  47. ->field('LEFT(Sczl_rq, 7) as date, CAST(sum(Sczl_cl) AS SIGNED) as counts')
  48. ->group('date')
  49. ->order('UniqId desc')
  50. ->limit(13)
  51. ->select();
  52. // halt($rows);
  53. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  54. foreach($rows as $key=>$value){
  55. $arr = db()->table('db_拉料计件')
  56. ->field('rtrim(Sczl_bh1) as Sczl_bh1, CAST(sum(Sczl_cl) AS SIGNED) as count')
  57. ->where('sczl_rq','LIKE',$value['date'].'%')
  58. ->group('Sczl_bh1')
  59. ->select();
  60. foreach ($arr as $k=>$v) {
  61. $arr[$k]['name'] = array_key_exists($v['Sczl_bh1'],$rs) ? trim($rs[$v['Sczl_bh1']]) : '';
  62. }
  63. $rows[$key]['sys'] = $arr;
  64. $rows[$key]['date'] = str_replace('-', '', $rows[$key]['date']);
  65. }
  66. $this->success('成功',$rows);
  67. }
  68. /**
  69. * 获取其他计件单据列表
  70. * @ApiMethod (GET)
  71. * @param string $date 时间
  72. * @param string $Sczl_bh1 员工编号
  73. */
  74. public function getList()
  75. {
  76. //get请求
  77. if(!$this->request->isGet()){
  78. $this->error('请求方式错误');
  79. }
  80. $req = $this->request->param();
  81. $page = 1;
  82. $limit = 15;
  83. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  84. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  85. $where = [];
  86. if (isset($req['date']) && !empty($req['date'])){
  87. $where['Sczl_rq'] = ['LIKE',$req['date'].'%'];
  88. }else{
  89. $this->error('参数错误');
  90. }
  91. if (isset($req['Sczl_bh1']) && !empty($req['Sczl_bh1'])) $where['Sczl_bh1'] = $req['Sczl_bh1'];
  92. $rows = db()->table('db_拉料计件')
  93. ->field('rtrim(sczl_Type) as sczl_Type, LEFT(Sczl_rq, 10) as Sczl_rq, Sczl_bh1, sczl_gdbh, CAST(Sczl_cl AS SIGNED) as Sczl_cl,
  94. rtrim(Sczl_desc) as Sczl_desc, rtrim(Sczl_gxmc) as Sczl_gxmc, sczl_yjno, sczl_gxh, rtrim(sys_id) as sys_id, sys_rq, mod_rq, UniqId')
  95. ->where($where)
  96. ->page($page,$limit)
  97. ->order('Sczl_rq asc, UniqId asc')
  98. ->select();
  99. $total = db()->table('db_拉料计件')
  100. ->where($where)
  101. ->count();
  102. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  103. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  104. foreach ($rows as $key=>$value) {
  105. $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
  106. $rows[$key]['Gd_cpmc'] = array_key_exists($value['sczl_gdbh'],$gd) ? trim($gd[$value['sczl_gdbh']]) : '';
  107. $rows[$key]['name'] = array_key_exists($value['Sczl_bh1'],$rs) ? trim($rs[$value['Sczl_bh1']]) : '';
  108. }
  109. $data = [
  110. 'total' => $total,
  111. 'rows' => $rows,
  112. ];
  113. $this->success('成功',$data);
  114. }
  115. /**
  116. * 获取其他计件单据信息
  117. * @ApiMethod (GET)
  118. * @param string $UniqId UniqId
  119. */
  120. public function getInfo()
  121. {
  122. //get请求
  123. if(!$this->request->isGet()){
  124. $this->error('请求方式错误');
  125. }
  126. $req = $this->request->param();
  127. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  128. $UniqId = $req['UniqId'];
  129. }else{
  130. $this->error('参数错误');
  131. }
  132. $rows = db()->table('db_拉料计件')->alias('d')
  133. ->field('d.*, ')
  134. ->join('工单_基本资料 g', 'd.')
  135. ->where('d.UniqId',$UniqId)
  136. ->select();
  137. $this->success('成功',$rows);
  138. }
  139. }