Inspect.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 Inspect 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. *
  24. * @ApiMethod GET
  25. */
  26. public function getInspectCount(){
  27. if (Request::instance()->isGet() == false){
  28. $this->error('非法请求');
  29. }
  30. $sql = 'SELECT DISTINCT DATE(sys_rq) AS sys_rq FROM `db_手工检验` ORDER BY sys_rq DESC LIMIT 30 ';
  31. $list = Db::query($sql);
  32. foreach ($list as $key => $value){
  33. $where = [$value['sys_rq'].'00:00:00',$value['sys_rq'].'24:00:00'];
  34. $list[$key]['count'] = Db::name('db_手工检验')->where('sys_rq','between time',$where)->count();
  35. }
  36. $this->success('请求成功',$list);
  37. }
  38. /**
  39. * 获取某个日期手工单据
  40. *
  41. * @ApiMethod GET
  42. * @params string date
  43. */
  44. public function getDateList(){
  45. if (Request::instance()->isGet() == false){
  46. $this->error('非法请求');
  47. }
  48. $params = Request::instance()->param();
  49. $date = $params['date'];
  50. if (!isset($date)){
  51. $this->error('参数不能为空');
  52. }
  53. $limit = $params['limit'];
  54. if (empty($limit)){
  55. $limit = 15;
  56. }
  57. $pages = $params['page'];
  58. if (empty($pages)){
  59. $pages = 1;
  60. }
  61. $field = 'a.sczl_gdbh,a.sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,a.sczl_dedh,a.sczl_废品率系数,a.sczl_检验类别,a.sczl_bh0,
  62. rtrim(a.qczl_NumDesc) as qczl_NumDesc,rtrim(a.sys_id) as sys_id,a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,rtrim(c.员工姓名) as 员工姓名,rtrim(d.yj_yjmc) as yj_yjmc';
  63. $where = [$date.' 00:00:00',$date.'24:00:00'];
  64. $list = Db::name('db_手工检验')->alias('a')
  65. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  66. ->join('人事_基本资料 c','a.sczl_bh0 = c.员工编号','left')
  67. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  68. ->where('a.sys_rq','between time',$where)
  69. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_yjno')
  70. ->field($field)->limit($limit)->page($pages)->order('a.sczl_rq,a.UniqId asc')->select();
  71. $option['sys_rq'] = array('between time',[$date.' 00:00:00',$date.' 24:00:00']);
  72. $count = Db::name('db_手工检验')->where($option)->count();
  73. $data['data'] = $list;
  74. $data['total'] = $count;
  75. $this->success('请求成功',$data);
  76. }
  77. /**
  78. * 获取机器检验左侧菜单栏
  79. *
  80. * @ApiMethod GET
  81. */
  82. public function getMachineCount(){
  83. if (Request::instance()->isGet() == false){
  84. $this->error('非法请求');
  85. }
  86. $sql = 'SELECT DISTINCT DATE(sys_rq) AS sys_rq FROM `db_机器检验` ORDER BY sys_rq DESC LIMIT 30 ';
  87. $list = Db::query($sql);
  88. foreach ($list as $key => $value){
  89. $where = [$value['sys_rq'].'00:00:00',$value['sys_rq'].'24:00:00'];
  90. $list[$key]['count'] = Db::name('db_机器检验')->where('sys_rq','between time',$where)->count();
  91. }
  92. $this->success('请求成功',$list);
  93. }
  94. /**
  95. * 获取某个日期机器单据
  96. *
  97. * @ApiMethod GET
  98. * @params string date
  99. */
  100. public function getDateMachine(){
  101. if (Request::instance()->isGet() == false){
  102. $this->error('非法请求');
  103. }
  104. $params = Request::instance()->param();
  105. $date = $params['date'];
  106. if (!isset($date)){
  107. $this->error('参数不能为空');
  108. }
  109. $limit = $params['limit'];
  110. if (empty($limit)){
  111. $limit = 15;
  112. }
  113. $pages = $params['page'];
  114. if (empty($pages)){
  115. $pages = 1;
  116. }
  117. $where['a.sczl_单据类型'] = '初检单';
  118. $where['a.sys_rq'] = array('between time',[$date.' 00:00:00',$date.' 24:00:00']);
  119. $field = 'a.sczl_gdbh,trim(a.sczl_yjgx) as sczl_yjgx,rtrim(a.sczl_gxmc) as sczl_gxmc,a.sczl_jtbh,a.sczl_bzdh,DATE(a.sczl_rq) as sczl_rq,a.sczl_cl,rtrim(a.sczl_单据类型) as sczl_单据类型,
  120. a.sczl_设备运行工时,a.sczl_dedh,a.sczl_废品率系数,a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.qczl_NumDesc,rtrim(a.sys_id) as sys_id,a.sys_rq,a.mod_rq,a.UniqId,b.千件工价,b.日定额,
  121. rtrim(c1.员工姓名) as sczl_bh1_name,rtrim(c2.员工姓名) as sczl_bh2_name,rtrim(c3.员工姓名) as sczl_bh3_name,rtrim(c4.员工姓名) as sczl_bh4_name,rtrim(d.yj_yjmc) as yj_yjmc';
  122. $list = Db::name('db_机器检验')->alias('a')
  123. ->join('dic_lzde b','a.sczl_dedh = b.sys_bh','left')
  124. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  125. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  126. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  127. ->join('人事_基本资料 c4','a.sczl_bh4 = c4.员工编号','left')
  128. ->join('工单_印件资料 d','a.sczl_gdbh = d.Yj_Gdbh','left')
  129. ->where($where)
  130. ->where('SUBSTR(a.sczl_yjgx,1,2) = d.yj_yjno')
  131. ->field($field)->limit($limit)->page($pages)->order('a.sczl_rq asc,a.UniqId desc')->select();
  132. $option['sczl_单据类型'] = '初检单';
  133. $option['sys_rq'] = array('between time',[$date.' 00:00:00',$date.' 24:00:00']);
  134. $count = Db::name('db_机器检验')->where($option)->count();
  135. $data['data'] = $list;
  136. $data['total'] = $count;
  137. $this->success('请求成功',$data);
  138. }
  139. }