WorkOrderSpotCheck.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 工单抽检记录维护接口
  6. */
  7. class WorkOrderSpotCheck 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_抽检记录1')
  30. ->field('LEFT(Sys_rq, 10) as date, COUNT(*) as counts')
  31. ->group('date')
  32. ->order('UniqId desc')
  33. ->limit(45)
  34. ->select();
  35. $arr = db()->table('db_抽检记录1')
  36. ->field('LEFT(Sys_rq, 10) as date, rtrim(Sys_id) as Sys_id, COUNT(Sys_id) as count')
  37. ->where('Sys_rq','>=',$rows[44]['date'])
  38. ->group('date, Sys_id')
  39. ->order('UniqId desc')
  40. ->select();
  41. foreach($rows as $key=>$value){
  42. $rows[$key]['sys'] = [];
  43. foreach($arr as $k=>$v){
  44. if($value['date'] == $v['date']){
  45. unset($v['date']);
  46. array_push($rows[$key]['sys'],$v);
  47. unset($arr[$k]);
  48. }
  49. }
  50. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  51. }
  52. $this->success('成功',$rows);
  53. }
  54. /**
  55. * 获取工单抽检记录列表
  56. * @ApiMethod (GET)
  57. * @param string $date 时间
  58. * @param string $sys_id 用户
  59. */
  60. public function getList()
  61. {
  62. //get请求
  63. if(!$this->request->isGet()){
  64. $this->error('请求方式错误');
  65. }
  66. $req = $this->request->param();
  67. $page = 1;
  68. $limit = 15;
  69. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  70. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  71. $where = [];
  72. if (isset($req['date']) && !empty($req['date'])){
  73. $where['Sys_rq'] = ['LIKE',$req['date'].'%'];
  74. }else{
  75. $this->error('参数错误');
  76. }
  77. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  78. $rows = db()->table('db_抽检记录1')
  79. ->field('LEFT(Sczl_rq, 10) as Sczl_rq, Sczl_bh, Sczl_gdbh, rtrim(Sczl_gxmc) as Sczl_gxmc,
  80. sczl_yjno, sczl_gxh, Sczl_num, Sczl_抽检数, sczl_A类废, sczl_B类废, sczl_C类废,
  81. rtrim(Sczl_desc) as Sczl_desc, rtrim(Sys_id) as Sys_id, Sys_rq, Mod_rq, UniqId')
  82. ->where($where)
  83. ->order('UniqId asc')
  84. ->page($page,$limit)
  85. ->select();
  86. $total = db()->table('db_抽检记录1')->where($where)->count();
  87. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  88. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  89. foreach ($rows as $key=>$value) {
  90. $rows[$key]['sczl_A类废'] = $value['sczl_A类废']==0 ? '' :$value['sczl_A类废'];
  91. $rows[$key]['sczl_B类废'] = $value['sczl_B类废']==0 ? '' :$value['sczl_B类废'];
  92. $rows[$key]['sczl_C类废'] = $value['sczl_C类废']==0 ? '' :$value['sczl_C类废'];
  93. $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
  94. $rows[$key]['Gd_cpmc'] = array_key_exists($value['Sczl_gdbh'],$gd) ? trim($gd[$value['Sczl_gdbh']]) : '';
  95. $rows[$key]['name'] = array_key_exists($value['Sczl_bh'],$rs) ? trim($rs[$value['Sczl_bh']]) : '';
  96. }
  97. $data = [
  98. 'total' => $total,
  99. 'rows' => $rows,
  100. ];
  101. $this->success('成功',$data);
  102. }
  103. /**
  104. * 获取工单抽检记录信息
  105. * @ApiMethod (GET)
  106. * @param string $UniqId UniqId
  107. */
  108. public function getInfo()
  109. {
  110. //get请求
  111. if(!$this->request->isGet()){
  112. $this->error('请求方式错误');
  113. }
  114. $req = $this->request->param();
  115. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  116. $UniqId = $req['UniqId'];
  117. }else{
  118. $this->error('参数错误');
  119. }
  120. $rows = db()->table('db_抽检记录1')
  121. ->field('Sczl_bh,rs.员工姓名 as name,sczl_bzdh,LEFT(Sczl_rq, 10) as Sczl_rq,Sczl_gdbh,g.Gd_cpmc,
  122. Sczl_gxmc,sczl_gxh,Sczl_num,Sczl_抽检数,Sczl_A类废,Sczl_B类废,Sczl_C类废,Sczl_desc')
  123. ->join('人事_基本资料 rs','rs.员工编号=db_抽检记录1.Sczl_bh','LEFT')
  124. ->join('工单_基本资料 g','g.Gd_gdbh=db_抽检记录1.Sczl_gdbh','LEFT')
  125. ->where('db_抽检记录1.UniqId',$UniqId)->select();
  126. $this->success('成功',$rows);
  127. }
  128. /**
  129. * 修改
  130. * @ApiMethod POST
  131. */
  132. public function edit()
  133. {
  134. if(!$this->request->isPost()){
  135. $this->error('请求方式错误');
  136. }
  137. $req = $this->request->param();
  138. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  139. $UniqId = $req['UniqId'];
  140. }else{
  141. $this->error('参数错误');
  142. }
  143. $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  144. $req['mod_rq'] = date('Y-m-d H:i:s');
  145. //开启事务
  146. db()->startTrans();
  147. try{
  148. $sql = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'],'wgjs_bh1'=>$req['wgjs_bh1']])
  149. ->fetchSql(true)->update($req);
  150. $res= db()->query($sql);
  151. // 提交事务
  152. db()->commit();
  153. } catch (\Exception $e) {
  154. // 回滚事务
  155. db()->rollback();
  156. $this->error($e->getMessage());
  157. }
  158. if($res===false) $this->error('失败');
  159. $this->success('成功');
  160. }
  161. /**
  162. * 新增
  163. * @ApiMethod POST
  164. */
  165. public function add()
  166. {
  167. if(!$this->request->isPost()){
  168. $this->error('请求方式错误');
  169. }
  170. $req = $this->request->param();
  171. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  172. $UniqId = $req['UniqId'];
  173. }else{
  174. $this->error('参数错误');
  175. }
  176. $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  177. $req['sys_rq'] = date('Y-m-d H:i:s');
  178. //开启事务
  179. db()->startTrans();
  180. try{
  181. $sql = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'],'wgjs_bh1'=>$req['wgjs_bh1']])
  182. ->fetchSql(true)->insert($req);
  183. $res= db()->query($sql);
  184. // 提交事务
  185. db()->commit();
  186. } catch (\Exception $e) {
  187. // 回滚事务
  188. db()->rollback();
  189. $this->error($e->getMessage());
  190. }
  191. if($res===false) $this->error('失败');
  192. $this->success('成功');
  193. }
  194. /**
  195. * 删除
  196. * @ApiMethod (GET)
  197. * @param string $UniqId UniqId
  198. */
  199. public function del(){
  200. //get请求
  201. if(!$this->request->isGet()){
  202. $this->error('请求方式错误');
  203. }
  204. $req = $this->request->param();
  205. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  206. $UniqId = $req['UniqId'];
  207. }else{
  208. $this->error('参数错误');
  209. }
  210. $rows = db()->table('db_抽检记录1')->where('UniqId',$UniqId)->delete();
  211. if($rows){
  212. $this->success('成功');
  213. }else{
  214. $this->error('失败');
  215. }
  216. }
  217. }