WorkOrderSpotCheck.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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_抽检记录')
  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_抽检记录')
  36. ->field('LEFT(Sys_rq, 10) as date, rtrim(Sys_id) as Sys_id, COUNT(Sys_id) as count')
  37. ->where('Sys_rq','>=',$rows[count($rows)-1]['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_抽检记录')
  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_抽检记录')->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_抽检记录')
  121. ->field('Sczl_bh,rtrim(rs.员工姓名) as name,rtrim(sczl_bzdh) as sczl_bzdh ,LEFT(Sczl_rq, 10) as Sczl_rq,
  122. Sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc, rtrim(Sczl_gxmc) as Sczl_gxmc,sczl_gxh,Sczl_num,Sczl_抽检数,
  123. Sczl_A类废,Sczl_B类废,Sczl_C类废,rtrim(Sczl_desc) as Sczl_desc')
  124. ->join('人事_基本资料 rs','rs.员工编号=db_抽检记录.Sczl_bh','LEFT')
  125. ->join('工单_基本资料 g','g.Gd_gdbh=db_抽检记录.Sczl_gdbh','LEFT')
  126. ->where('db_抽检记录.UniqId',$UniqId)->limit(1)->select();
  127. if($rows){
  128. $this->success('成功',$rows);
  129. }else{
  130. $this->error('失败');
  131. }
  132. }
  133. /**
  134. * 定位
  135. * @ApiMethod (GET)
  136. */
  137. public function search()
  138. {
  139. //get请求
  140. if(!$this->request->isGet()){
  141. $this->error('请求方式错误');
  142. }
  143. $req = $this->request->param();
  144. if (isset($req['search']) && !empty($req['search'])){
  145. $search = $req['search'];
  146. }else{
  147. $this->error('参数错误');
  148. }
  149. $page = 1;
  150. $limit = 10;
  151. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  152. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  153. $gd = db()->table('工单_基本资料')->where('Gd_cpmc',$search)->value('Gd_gdbh');
  154. if($gd){
  155. $search=$gd;
  156. }
  157. $rows = db()->table('db_抽检记录')
  158. ->field('Sczl_bh,sczl_yjno,rtrim(rs.员工姓名) as name,LEFT(Sczl_rq, 10) as Sczl_rq,
  159. Sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc, rtrim(Sczl_gxmc) as Sczl_gxmc,sczl_gxh,Sczl_num,Sczl_抽检数,
  160. Sczl_A类废,Sczl_B类废,Sczl_C类废,rtrim(Sczl_desc) as Sczl_desc,rtrim(db_抽检记录.Sys_id) as Sys_id,
  161. db_抽检记录.Sys_rq,db_抽检记录.Mod_rq,db_抽检记录.UniqId')
  162. ->join('人事_基本资料 rs','rs.员工编号=db_抽检记录.Sczl_bh','LEFT')
  163. ->join('工单_基本资料 g','g.Gd_gdbh=db_抽检记录.Sczl_gdbh','LEFT')
  164. ->where('db_抽检记录.Sczl_gdbh',$search)
  165. ->page($page,$limit)->select();
  166. $total = db()->table('db_抽检记录')->where('db_抽检记录.Sczl_gdbh',$search)->count();
  167. $data = ['total'=> $total,'rows'=> $rows];
  168. if($rows){
  169. $this->success('成功',$data);
  170. }else{
  171. $this->error('失败');
  172. }
  173. }
  174. /**
  175. * 修改
  176. * @ApiMethod POST
  177. */
  178. public function edit()
  179. {
  180. if(!$this->request->isPost()){
  181. $this->error('请求方式错误');
  182. }
  183. $req = $this->request->param();
  184. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  185. $UniqId = $req['UniqId'];
  186. }else{
  187. $this->error('参数错误');
  188. }
  189. if (isset($req['Sczl_gxmc']) && !empty($req['Sczl_gxmc'])){
  190. $req['sczl_gxh'] = explode('-',$req['Sczl_gxmc'])[1];
  191. }
  192. if (isset($req['Sczl_rq']) && !empty($req['Sczl_rq'])){
  193. $req['Sczl_rq'] = $req['Sczl_rq'].' 00:00:00';
  194. }
  195. $req['Mod_rq'] = date('Y-m-d H:i:s');
  196. //开启事务
  197. db()->startTrans();
  198. try{
  199. $sql = db()->table('db_抽检记录')->where('UniqId',$UniqId)->fetchSql(true)->update($req);
  200. $res= db()->query($sql);
  201. // 提交事务
  202. db()->commit();
  203. } catch (\Exception $e) {
  204. // 回滚事务
  205. db()->rollback();
  206. $this->error($e->getMessage());
  207. }
  208. if($res===false) $this->error('失败');
  209. $this->success('成功');
  210. }
  211. /**
  212. * 新增
  213. * @ApiMethod POST
  214. */
  215. public function add()
  216. {
  217. if(!$this->request->isPost()){
  218. $this->error('请求方式错误');
  219. }
  220. $req = $this->request->param();
  221. if (isset($req) && !empty($req)){
  222. }else{
  223. $this->error('参数错误');
  224. }
  225. if (isset($req['Sczl_gxmc']) && !empty($req['Sczl_gxmc'])){
  226. $req['sczl_gxh'] = explode('-',$req['Sczl_gxmc'])[1];
  227. }
  228. if (isset($req['Sczl_rq']) && !empty($req['Sczl_rq'])){
  229. $req['Sczl_rq'] = $req['Sczl_rq'].' 00:00:00';
  230. }
  231. $req['Sys_rq'] = date('Y-m-d H:i:s');
  232. $UniqId = db()->table('db_抽检记录')->order('UniqId desc')->value('UniqId');
  233. if ($UniqId < 1000000){
  234. $UniqId = 1000000;
  235. }else{
  236. $UniqId = $UniqId + 1;
  237. }
  238. $req['UniqId'] = $UniqId;
  239. //开启事务
  240. db()->startTrans();
  241. try{
  242. $sql = db()->table('db_抽检记录')->fetchSql(true)->insert($req);
  243. $res= db()->query($sql);
  244. // 提交事务
  245. db()->commit();
  246. } catch (\Exception $e) {
  247. // 回滚事务
  248. db()->rollback();
  249. $this->error($e->getMessage());
  250. }
  251. if($res===false) $this->error('失败');
  252. $this->success('成功');
  253. }
  254. /**
  255. * 删除
  256. * @ApiMethod (GET)
  257. * @param string $UniqId UniqId
  258. */
  259. public function del(){
  260. //get请求
  261. if(!$this->request->isGet()){
  262. $this->error('请求方式错误');
  263. }
  264. $req = $this->request->param();
  265. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  266. $UniqId = $req['UniqId'];
  267. }else{
  268. $this->error('参数错误');
  269. }
  270. $rows = db()->table('db_抽检记录')->where('UniqId',$UniqId)->delete();
  271. if($rows){
  272. $this->success('成功');
  273. }else{
  274. $this->error('失败');
  275. }
  276. }
  277. }