WorkOrderSpotCheck.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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(*) 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. */
  58. public function getTabByGdbh()
  59. {
  60. //get请求
  61. if(!$this->request->isGet()){
  62. $this->error('请求方式错误');
  63. }
  64. $date = date('Y-m-d',strtotime("-1 year"));
  65. $rows = db()->table('db_抽检记录')->alias('d')->cache(true)
  66. ->field('d.Sczl_gdbh, rtrim(y.Gd_cpmc) as Gd_cpmc')
  67. ->join('工单_基本资料 y','y.Gd_gdbh = d.Sczl_gdbh','left')
  68. // ->where('d.sys_rq','>=',$date)
  69. ->group('d.Sczl_gdbh')
  70. ->order('d.Sczl_gdbh desc')
  71. ->limit(65)
  72. ->select();
  73. $arr = db()->table('db_抽检记录')->cache(true)
  74. ->field('Sczl_gdbh, rtrim(Sys_id) as Sys_id, COUNT(*) as count')
  75. ->where('Sczl_gdbh','>=',$rows[count($rows)-1]['Sczl_gdbh'])
  76. ->group('Sczl_gdbh, Sys_id')
  77. ->select();
  78. foreach($rows as $key=>$value){
  79. $rows[$key]['sys'] = [];
  80. foreach($arr as $k=>$v){
  81. if($value['Sczl_gdbh'] == $v['Sczl_gdbh']){
  82. unset($v['Sczl_gdbh']);
  83. array_push($rows[$key]['sys'],$v);
  84. unset($arr[$k]);
  85. }
  86. }
  87. }
  88. $this->success('成功',$rows);
  89. }
  90. /**
  91. * 获取工单抽检记录列表
  92. * @ApiMethod (GET)
  93. * @param string $date 时间
  94. * @param string $sys_id 用户
  95. */
  96. public function getList()
  97. {
  98. //get请求
  99. if(!$this->request->isGet()){
  100. $this->error('请求方式错误');
  101. }
  102. $req = $this->request->param();
  103. $page = 1;
  104. $limit = 15;
  105. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  106. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  107. $where = [];
  108. if (isset($req['date']) && !empty($req['date'])){
  109. if(strpos($req['date'],'-')){
  110. $where['Sys_rq'] = ['like',$req['date'].'%'];
  111. }else{
  112. $where['Sczl_gdbh'] = $req['date'];
  113. }
  114. }else{
  115. $this->error('参数错误');
  116. }
  117. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['Sys_id'] = ['LIKE',$req['sys_id'].'%'];
  118. $rows = db()->table('db_抽检记录')
  119. ->field('LEFT(Sczl_rq, 10) as Sczl_rq, Sczl_bh, Sczl_gdbh, rtrim(Sczl_gxmc) as Sczl_gxmc,
  120. sczl_yjno, sczl_gxh, Sczl_num, Sczl_抽检数, sczl_A类废, sczl_B类废, sczl_C类废,
  121. rtrim(Sczl_desc) as Sczl_desc, rtrim(Sys_id) as Sys_id, Sys_rq, Mod_rq, UniqId')
  122. ->where($where)
  123. ->order('UniqId asc')
  124. ->page($page,$limit)
  125. ->select();
  126. $total = db()->table('db_抽检记录')->where($where)->count();
  127. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  128. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  129. foreach ($rows as $key=>$value) {
  130. $rows[$key]['sczl_A类废'] = $value['sczl_A类废']==0 ? '' :$value['sczl_A类废'];
  131. $rows[$key]['sczl_B类废'] = $value['sczl_B类废']==0 ? '' :$value['sczl_B类废'];
  132. $rows[$key]['sczl_C类废'] = $value['sczl_C类废']==0 ? '' :$value['sczl_C类废'];
  133. $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
  134. $rows[$key]['Gd_cpmc'] = array_key_exists($value['Sczl_gdbh'],$gd) ? trim($gd[$value['Sczl_gdbh']]) : '';
  135. $rows[$key]['name'] = array_key_exists($value['Sczl_bh'],$rs) ? trim($rs[$value['Sczl_bh']]) : '';
  136. }
  137. $data = [
  138. 'total' => $total,
  139. 'rows' => $rows,
  140. ];
  141. $this->success('成功',$data);
  142. }
  143. /**
  144. * 获取工单抽检记录信息
  145. * @ApiMethod (GET)
  146. * @param string $UniqId UniqId
  147. */
  148. public function getInfo()
  149. {
  150. //get请求
  151. if(!$this->request->isGet()){
  152. $this->error('请求方式错误');
  153. }
  154. $req = $this->request->param();
  155. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  156. $UniqId = $req['UniqId'];
  157. }else{
  158. $this->error('参数错误');
  159. }
  160. $rows = db()->table('db_抽检记录')
  161. ->field('Sczl_bh,rtrim(rs.员工姓名) as name,rtrim(sczl_bzdh) as sczl_bzdh ,LEFT(Sczl_rq, 10) as Sczl_rq,
  162. Sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc, rtrim(Sczl_gxmc) as Sczl_gxmc,sczl_gxh,Sczl_num,Sczl_抽检数,
  163. Sczl_A类废,Sczl_B类废,Sczl_C类废,rtrim(Sczl_desc) as Sczl_desc')
  164. ->join('人事_基本资料 rs','rs.员工编号=db_抽检记录.Sczl_bh','LEFT')
  165. ->join('工单_基本资料 g','g.Gd_gdbh=db_抽检记录.Sczl_gdbh','LEFT')
  166. ->where('db_抽检记录.UniqId',$UniqId)->limit(1)->select();
  167. if($rows){
  168. $this->success('成功',$rows);
  169. }else{
  170. $this->error('失败');
  171. }
  172. }
  173. /**
  174. * 定位
  175. * @ApiMethod (GET)
  176. */
  177. public function search()
  178. {
  179. //get请求
  180. if(!$this->request->isGet()){
  181. $this->error('请求方式错误');
  182. }
  183. $req = $this->request->param();
  184. if (isset($req['search']) && !empty($req['search'])){
  185. $search = $req['search'];
  186. }else{
  187. $this->error('参数错误');
  188. }
  189. $page = 1;
  190. $limit = 10;
  191. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  192. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  193. $gd = db()->table('工单_基本资料')->where('Gd_cpmc',$search)->value('Gd_gdbh');
  194. if($gd){
  195. $search=$gd;
  196. }
  197. $rows = db()->table('db_抽检记录')
  198. ->field('Sczl_bh,sczl_yjno,rtrim(rs.员工姓名) as name,LEFT(Sczl_rq, 10) as Sczl_rq,
  199. Sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc, rtrim(Sczl_gxmc) as Sczl_gxmc,sczl_gxh,Sczl_num,Sczl_抽检数,
  200. Sczl_A类废,Sczl_B类废,Sczl_C类废,rtrim(Sczl_desc) as Sczl_desc,rtrim(db_抽检记录.Sys_id) as Sys_id,
  201. db_抽检记录.Sys_rq,db_抽检记录.Mod_rq,db_抽检记录.UniqId')
  202. ->join('人事_基本资料 rs','rs.员工编号=db_抽检记录.Sczl_bh','LEFT')
  203. ->join('工单_基本资料 g','g.Gd_gdbh=db_抽检记录.Sczl_gdbh','LEFT')
  204. ->where('db_抽检记录.Sczl_gdbh',$search)
  205. ->page($page,$limit)->select();
  206. $total = db()->table('db_抽检记录')->where('db_抽检记录.Sczl_gdbh',$search)->count();
  207. $data = ['total'=> $total,'rows'=> $rows];
  208. if($rows){
  209. $this->success('成功',$data);
  210. }else{
  211. $this->error('失败');
  212. }
  213. }
  214. /**
  215. * 修改
  216. * @ApiMethod POST
  217. */
  218. public function edit()
  219. {
  220. if(!$this->request->isPost()){
  221. $this->error('请求方式错误');
  222. }
  223. $req = $this->request->param();
  224. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  225. $UniqId = $req['UniqId'];
  226. }else{
  227. $this->error('参数错误');
  228. }
  229. if (isset($req['Sczl_gxmc']) && !empty($req['Sczl_gxmc'])){
  230. $req['sczl_gxh'] = explode('-',$req['Sczl_gxmc'])[1];
  231. }
  232. if (isset($req['Sczl_rq']) && !empty($req['Sczl_rq'])){
  233. $req['Sczl_rq'] = $req['Sczl_rq'].' 00:00:00';
  234. }
  235. $req['Mod_rq'] = date('Y-m-d H:i:s');
  236. //开启事务
  237. db()->startTrans();
  238. try{
  239. $sql = db()->table('db_抽检记录')->where('UniqId',$UniqId)->fetchSql(true)->update($req);
  240. $res= db()->query($sql);
  241. // 提交事务
  242. db()->commit();
  243. } catch (\Exception $e) {
  244. // 回滚事务
  245. db()->rollback();
  246. $this->error($e->getMessage());
  247. }
  248. if($res===false) $this->error('失败');
  249. $this->success('成功');
  250. }
  251. /**
  252. * 新增
  253. * @ApiMethod POST
  254. */
  255. public function add()
  256. {
  257. if(!$this->request->isPost()){
  258. $this->error('请求方式错误');
  259. }
  260. $req = $this->request->param();
  261. if (isset($req) && !empty($req)){
  262. }else{
  263. $this->error('参数错误');
  264. }
  265. if (isset($req['Sczl_gxmc']) && !empty($req['Sczl_gxmc'])){
  266. $req['sczl_gxh'] = explode('-',$req['Sczl_gxmc'])[1];
  267. }
  268. if (isset($req['Sczl_rq']) && !empty($req['Sczl_rq'])){
  269. $req['Sczl_rq'] = $req['Sczl_rq'].' 00:00:00';
  270. }
  271. $req['Sys_rq'] = date('Y-m-d H:i:s');
  272. $UniqId = db()->table('db_抽检记录')->order('UniqId desc')->value('UniqId');
  273. if ($UniqId < 1000000){
  274. $UniqId = 1000000;
  275. }else{
  276. $UniqId = $UniqId + 1;
  277. }
  278. $req['UniqId'] = $UniqId;
  279. //开启事务
  280. db()->startTrans();
  281. try{
  282. $sql = db()->table('db_抽检记录')->fetchSql(true)->insert($req);
  283. $res= db()->query($sql);
  284. // 提交事务
  285. db()->commit();
  286. } catch (\Exception $e) {
  287. // 回滚事务
  288. db()->rollback();
  289. $this->error($e->getMessage());
  290. }
  291. if($res===false) $this->error('失败');
  292. $this->success('成功');
  293. }
  294. /**
  295. * 删除
  296. * @ApiMethod (GET)
  297. * @param string $UniqId UniqId
  298. */
  299. public function del(){
  300. //get请求
  301. if(!$this->request->isGet()){
  302. $this->error('请求方式错误');
  303. }
  304. $req = $this->request->param();
  305. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  306. $UniqId = $req['UniqId'];
  307. }else{
  308. $this->error('参数错误');
  309. }
  310. $rows = db()->table('db_抽检记录')->where('UniqId',$UniqId)->delete();
  311. if($rows){
  312. $this->success('成功');
  313. }else{
  314. $this->error('失败');
  315. }
  316. }
  317. }