OtherCountDocument.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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('date')
  32. ->order('UniqId desc')
  33. ->limit(13)
  34. ->select();
  35. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  36. foreach($rows as $key=>$value){
  37. $arr = db()->table('db_拉料计件')
  38. ->field('rtrim(Sczl_bh1) as Sczl_bh1, CAST(sum(Sczl_cl) AS SIGNED) as count')
  39. ->where('sczl_rq','LIKE',$value['date'].'%')
  40. ->group('Sczl_bh1')
  41. ->select();
  42. foreach ($arr as $k=>$v) {
  43. $arr[$k]['name'] = array_key_exists($v['Sczl_bh1'],$rs) ? trim($rs[$v['Sczl_bh1']]) : '';
  44. }
  45. $rows[$key]['sys'] = $arr;
  46. $rows[$key]['date'] = str_replace('-', '', $rows[$key]['date']);
  47. }
  48. $this->success('成功',$rows);
  49. }
  50. /**
  51. * 获取其他计件单据列表
  52. * @ApiMethod (GET)
  53. * @param string $date 时间
  54. * @param string $Sczl_bh1 员工编号
  55. */
  56. public function getList()
  57. {
  58. //get请求
  59. if(!$this->request->isGet()){
  60. $this->error('请求方式错误');
  61. }
  62. $req = $this->request->param();
  63. $page = 1;
  64. $limit = 15;
  65. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  66. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  67. $where = [];
  68. if (isset($req['date']) && !empty($req['date'])){
  69. $where['Sczl_rq'] = ['LIKE',$req['date'].'%'];
  70. }else{
  71. $this->error('参数错误');
  72. }
  73. if (isset($req['Sczl_bh1']) && !empty($req['Sczl_bh1'])) $where['Sczl_bh1'] = $req['Sczl_bh1'];
  74. $rows = db()->table('db_拉料计件')
  75. ->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,
  76. 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')
  77. ->where($where)
  78. ->page($page,$limit)
  79. ->order('Sczl_rq asc, UniqId asc')
  80. ->select();
  81. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  82. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  83. foreach ($rows as $key=>$value) {
  84. $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
  85. $rows[$key]['Gd_cpmc'] = array_key_exists($value['sczl_gdbh'],$gd) ? trim($gd[$value['sczl_gdbh']]) : '';
  86. $rows[$key]['name'] = array_key_exists($value['Sczl_bh1'],$rs) ? trim($rs[$value['Sczl_bh1']]) : '';
  87. }
  88. $data = [
  89. 'rows' => $rows,
  90. ];
  91. $this->success('成功',$data);
  92. }
  93. /**
  94. * 获取其他计件单据信息
  95. * @ApiMethod (GET)
  96. * @param string $UniqId UniqId
  97. */
  98. public function getInfo()
  99. {
  100. //get请求
  101. if(!$this->request->isGet()){
  102. $this->error('请求方式错误');
  103. }
  104. $req = $this->request->param();
  105. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  106. $UniqId = $req['UniqId'];
  107. }else{
  108. $this->error('参数错误');
  109. }
  110. $rows = db()->table('db_拉料计件')->alias('d')
  111. ->field('d.*, ')
  112. ->join('工单_基本资料 g', 'd.')
  113. ->where('d.UniqId',$UniqId)
  114. ->select();
  115. $this->success('成功',$rows);
  116. }
  117. }