WorkOrderVerification.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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 WorkOrderVerification 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. * @ApiMethod (GET)
  24. */
  25. public function getTab()
  26. {
  27. //get请求
  28. if(!$this->request->isGet()){
  29. $this->error('请求方式错误');
  30. }
  31. $rows = db()->table('db_qczl')
  32. ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  33. ->group('date')
  34. ->order('UniqId desc')
  35. ->limit(30)
  36. ->select();
  37. $arr = db()->table('db_qczl')
  38. ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
  39. ->where('sys_rq','>=',$rows[29]['date'])
  40. ->group('date, sys_id')
  41. ->select();
  42. foreach($rows as $key=>$value){
  43. $rows[$key]['sys'] = [];
  44. foreach($arr as $k=>$v){
  45. if($value['date'] == $v['date']){
  46. unset($v['date']);
  47. array_push($rows[$key]['sys'],$v);
  48. unset($arr[$k]);
  49. }
  50. }
  51. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  52. }
  53. $this->success('成功',$rows);
  54. }
  55. /**
  56. * 获取工单核验单列表
  57. * @ApiMethod (GET)
  58. * @param string $date 时间
  59. * @param string $sys_id 用户
  60. */
  61. public function getList()
  62. {
  63. //get请求
  64. if(!$this->request->isGet()){
  65. $this->error('请求方式错误');
  66. }
  67. $req = $this->request->param();
  68. $page = 1;
  69. $limit = 15;
  70. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  71. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  72. $where = [];
  73. if (isset($req['date']) && !empty($req['date'])){
  74. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  75. }else{
  76. $this->error('参数错误');
  77. }
  78. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  79. if (isset($req['order']) && !empty($req['order'])) $where['qczl_gdbh'] = $req['order'];
  80. $rows = db()->table('db_qczl')
  81. ->field('qczl_gdbh, qczl_yjno, LEFT(qczl_rq, 10) as qczl_rq, qczl_num, rtrim(qczl_NumDesc) as qczl_NumDesc, qczl_fp,
  82. fp_lb1, fp_lb2, fp_lb3, fp_lb4, fp_lb5, fp_lb6, fp_lb7, fp_lb8, fp_lb9, fp_lb10, fp_lb11, fp_lb12, fp_lb13, fp_lb14, fp_lb15, fp_lb16, fp_lb17,
  83. fp_sl1, fp_sl2, fp_sl3, fp_sl4, fp_sl5, fp_sl6, fp_sl7, fp_sl8, fp_sl9, fp_sl10, fp_sl11, fp_sl12, fp_sl13, fp_sl14, fp_sl15, fp_sl16, fp_sl17,
  84. rtrim(sys_id) as sys_id,UniqId')
  85. ->where($where)
  86. ->order('UniqId desc')
  87. ->page($page,$limit)
  88. ->select();
  89. $total = db()->table('db_qczl')->where($where)->count();
  90. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  91. foreach ($rows as $key=>$value){
  92. $rows[$key]['Gd_cpmc'] = array_key_exists($value['qczl_gdbh'],$gd) ? sprintf("%02d", $value['qczl_yjno']).'-'.trim($gd[$value['qczl_gdbh']]) : '';
  93. for ($i=1;$i<=17;$i++){
  94. if ($value['fp_sl'.$i]==0){
  95. $rows[$key]['sl_lb'.$i] = '';
  96. }else{
  97. $rows[$key]['sl_lb'.$i] = trim($value['fp_sl'.$i].'-->'.$value['fp_lb'.$i]);
  98. }
  99. unset($rows[$key]['fp_sl'.$i]);
  100. unset($rows[$key]['fp_lb'.$i]);
  101. }
  102. }
  103. $data = [
  104. 'total' => $total,
  105. 'rows' => $rows,
  106. ];
  107. $this->success('成功',$data);
  108. }
  109. /**
  110. * 获取工单核验单信息
  111. * @ApiMethod (GET)
  112. * @param string $UniqId UniqId
  113. */
  114. public function getInfo()
  115. {
  116. //get请求
  117. if(!$this->request->isGet()){
  118. $this->error('请求方式错误');
  119. }
  120. $req = $this->request->param();
  121. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  122. $UniqId = $req['UniqId'];
  123. }else{
  124. $this->error('参数错误');
  125. }
  126. $rows = db()->table('db_qczl')->alias('d')
  127. ->field('d.*, ')
  128. ->join('工单_基本资料 g', 'd.')
  129. ->where('d.UniqId',$UniqId)
  130. ->select();
  131. $this->success('成功',$rows);
  132. }
  133. /**
  134. * 获取单个工单核检单信息
  135. * @ApiMethod GET
  136. * @params string UniqId
  137. */
  138. public function getOneWorkOrder(){
  139. if (Request::instance()->isGet() == false){
  140. $this->error('非法请求');
  141. }
  142. $params = Request::instance()->param();
  143. if (!isset($params['UniqId']) || empty($params['UniqId'])){
  144. $this->error('参数错误');
  145. }
  146. $list = Db::name('db_qczl')->where('UniqId',$params['UniqId'])->find();
  147. $list['fp_name1'] = '';
  148. if (!empty($list['fp_bh1'])){
  149. $list['fp_name1'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh1'])->value('rtrim(员工姓名)');
  150. }
  151. $list['fp_name2'] = '';
  152. if (!empty($list['fp_bh2'])){
  153. $list['fp_name2'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh2'])->value('rtrim(员工姓名)');
  154. }
  155. $list['fp_name3'] = '';
  156. if (!empty($list['fp_bh3'])){
  157. $list['fp_name3'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh3'])->value('rtrim(员工姓名)');
  158. }
  159. $list['fp_name4'] = '';
  160. if (!empty($list['fp_bh4'])){
  161. $list['fp_name4'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh4'])->value('rtrim(员工姓名)');
  162. }
  163. $list['fp_name5'] = '';
  164. if (!empty($list['fp_bh5'])){
  165. $list['fp_name5'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh5'])->value('rtrim(员工姓名)');
  166. }
  167. $list['fp_name6'] = '';
  168. if (!empty($list['fp_bh6'])){
  169. $list['fp_name6'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh6'])->value('rtrim(员工姓名)');
  170. }
  171. $list['fp_name7'] = '';
  172. if (!empty($list['fp_bh7'])){
  173. $list['fp_name7'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh7'])->value('rtrim(员工姓名)');
  174. }
  175. $list['fp_name8'] = '';
  176. if (!empty($list['fp_bh8'])){
  177. $list['fp_name8'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh8'])->value('rtrim(员工姓名)');
  178. }
  179. $list['fp_name9'] = '';
  180. if (!empty($list['fp_bh9'])){
  181. $list['fp_name9'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh9'])->value('rtrim(员工姓名)');
  182. }
  183. $list['fp_name10'] = '';
  184. if (!empty($list['fp_bh10'])){
  185. $list['fp_name10'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh10'])->value('rtrim(员工姓名)');
  186. }
  187. $list['fp_name11'] = '';
  188. if (!empty($list['fp_bh11'])){
  189. $list['fp_name11'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh11'])->value('rtrim(员工姓名)');
  190. }
  191. $list['fp_name12'] = '';
  192. if (!empty($list['fp_bh12'])){
  193. $list['fp_name12'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh12'])->value('rtrim(员工姓名)');
  194. }
  195. $list['fp_name13'] = '';
  196. if (!empty($list['fp_bh13'])){
  197. $list['fp_name13'] = Db::name('人事_基本资料')->where('员工编号',$list['fp_bh13'])->value('rtrim(员工姓名)');
  198. }
  199. $max = Db::name('设备_产量计酬')->where('sczl_gdbh',$list['qczl_gdbh'])->field('MAX(sczl_num) as sczl_num')->find();
  200. $list['total_liucheng'] = $max['sczl_num'];
  201. $this->success('请求成功',$list);
  202. }
  203. /**
  204. * 获取工单基本信息
  205. * @ApiMethod GET
  206. * @params string order
  207. */
  208. public function getOrderInfo(){
  209. if (Request::instance()->isGet() == false){
  210. $this->error('非法请求');
  211. }
  212. $params = Request::instance()->param();
  213. if (!isset($params['order']) || empty($params['order'])){
  214. $this->error('参数错误');
  215. }
  216. $list = Db::name('工单_基本资料')->alias('a')
  217. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
  218. ->where('a.Gd_gdbh',$params['order'])
  219. ->where('a.行号',1)
  220. ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc')
  221. ->find();
  222. $this->success('请求成功',$list);
  223. }
  224. /**
  225. * 获取印件名称及工序
  226. * @ApiMethod GET
  227. * @params string order
  228. * @params string yj_no
  229. */
  230. public function getYjInfo(){
  231. if (Request::instance()->isGet() == false){
  232. $this->error('非法请求');
  233. }
  234. $params = Request::instance()->param();
  235. if (!isset($params['order']) || empty($params['order'])){
  236. $this->error('参数错误');
  237. }
  238. if (!isset($params['yj_no']) || empty($params['yj_no'])){
  239. $this->error('参数错误');
  240. }
  241. $where['Yj_Gdbh'] = $params['order'];
  242. $where['yj_Yjno'] = $params['yj_no'];
  243. $list = Db::name('工单_印件资料')->where($where)->field('yj_yjmc')->find();
  244. $option['Gy0_gdbh'] = $params['order'];
  245. $option['Gy0_yjno'] = $params['yj_no'];
  246. $option['Gy0_site'] = '检验车间';
  247. $option['Gy0_gxmc'] = array('not in',['包装','外发加工','废挑正','成品防护']);
  248. $gxList = Db::name('工单_工艺资料')->where($option)->field('Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')->select();
  249. $max = Db::name('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yj_no'])->field('MAX(sczl_num) as sczl_num')->value('sczl_num');
  250. $list['gx_data'] = $gxList;
  251. $list['max_num'] = $max;
  252. $this->success('请求成功',$list);
  253. }
  254. /**
  255. * 获取废品分类
  256. * @ApiMethod GET
  257. * @params string search
  258. */
  259. public function getWastInfo(){
  260. if (Request::instance()->isGet() == false){
  261. $this->error('非法请求');
  262. }
  263. $params = Request::instance()->param();
  264. if (!isset($params['search']) || empty($params['search'])){
  265. $this->error('参数错误');
  266. }
  267. $where['分类'] = '废品分类';
  268. $where['名称'] = array('like','%'.$params['search'].'%');
  269. $data = Db::name('erp_常用字典')->where($where)->column('名称');
  270. // 分割字符串并合并相同项
  271. $resultArray = [];
  272. foreach ($data as $item) {
  273. $parts = explode('_', $item);
  274. // 使用第一个部分作为一级键,第二个部分作为二级键
  275. $firstKey = $parts[0];
  276. $secondKey = $parts[1];
  277. $thirdValue = $parts[2];
  278. $resultArray[$firstKey][$secondKey][] = $thirdValue;
  279. }
  280. // 对废品分类下的数组进行升序排序
  281. if (isset($resultArray['data']['废品分类'])) {
  282. foreach ($resultArray['data']['废品分类'] as &$category) {
  283. // 判断是关联数组(单凹等)还是索引数组(分切等)
  284. if (is_array($category) && !empty($category) && is_array(current($category))) {
  285. foreach ($category as &$subCategory) {
  286. ksort($subCategory);
  287. }
  288. } else {
  289. ksort($category);
  290. }
  291. }
  292. }
  293. $this->success('请求成功',$resultArray);
  294. }
  295. /**
  296. *获取工序及责任组长
  297. * @ApiMethod GET
  298. * @params string type
  299. * @params string order
  300. */
  301. public function getGxAndLeader(){
  302. if (Request::instance()->isGet() == false){
  303. $this->error('非法请求');
  304. }
  305. $params = Request::instance()->param();
  306. if (!isset($params['type']) || empty($params['type'])){
  307. $this->error('参数错误');
  308. }
  309. if (!isset($params['order']) || empty($params['order'])){
  310. $this->error('参数错误');
  311. }
  312. $type = trim($params['type']);
  313. $waste = Db::name('erp_常用字典')->where('名称','like','%'.$type.'%')->find();
  314. if (empty($waste)){
  315. $this->error('未查询到废品分类');
  316. }
  317. $wasteType = explode('_',substr($waste['名称'],0,-1));
  318. $searchArr = explode('-',$wasteType[1]);
  319. $search = substr($searchArr[1],0,6);
  320. $where['a.sczl_gdbh'] = $params['order'];
  321. $where['a.sczl_type'] = array('like','%'.$search.'%');
  322. $list = Db::name('设备_产量计酬')->alias('a')
  323. ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
  324. ->where($where)->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
  325. ->select();
  326. $count = count($list);
  327. $list[$count]['sczl_gxmc'] = '99-外发加工';
  328. $list[$count]['sczl_bzdh'] = 'A班';
  329. $list[$count]['sczl_jtbh'] = '';
  330. $list[$count]['sczl_bh1'] = '000000';
  331. $list[$count]['name'] = '计时工';
  332. $this->success('请求成功',$list);
  333. }
  334. }