LargeWasteRewardPunish.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\db;
  5. use think\Request;
  6. /**
  7. * 工序大废品惩奖记录接口
  8. */
  9. class LargeWasteRewardPunish 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_大废品')
  32. ->field('DISTINCT(LEFT(sys_rq, 7)) AS mouth,LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  33. ->group('date')
  34. ->order('UniqId desc')
  35. ->limit(40)
  36. ->select();
  37. $list = [];
  38. foreach($rows as $key=>$value){
  39. if (!isset($list[$value['mouth']])){
  40. $list[$value['mouth']] = [];
  41. }
  42. $arr['date'] = str_replace('-', '.', $rows[$key]['date']);
  43. $arr['counts'] = $rows[$key]['counts'];
  44. array_push($list[$value['mouth']],$arr);
  45. // $list[$value['mouth']]['date'] = str_replace('-', '.', $rows[$key]['date']);
  46. }
  47. $this->success('成功',$list);
  48. }
  49. /**
  50. * 获取工序大废品惩奖侧边栏根据工单
  51. * @ApiMethod (GET)
  52. */
  53. public function getTabByGd()
  54. {
  55. //get请求
  56. if(!$this->request->isGet()){
  57. $this->error('请求方式错误');
  58. }
  59. $rows = db()->table('db_大废品')
  60. ->field('sczl_gdbh,rtrim(g.成品名称) as 成品名称')
  61. ->join('工单_基本资料 g','g.Gd_gdbh=db_大废品.sczl_gdbh','LEFT')
  62. ->group('sczl_gdbh')
  63. ->whereTime('db_大废品.sys_rq', '>=', strtotime('-60 days'))
  64. ->order('sczl_gdbh desc')
  65. ->select();
  66. foreach($rows as $key=>$value){
  67. $data[$key]['label']=$value['sczl_gdbh'].' 【'.$value['成品名称'].'】';
  68. $data[$key]['sczl_gdbh']=$value['sczl_gdbh'];
  69. }
  70. $this->success('成功',$data);
  71. }
  72. /**
  73. * 获取工序大废品惩奖列表
  74. * @ApiMethod (GET)
  75. * @param string $date 时间
  76. */
  77. public function getList()
  78. {
  79. //get请求
  80. if(!$this->request->isGet()){
  81. $this->error('请求方式错误');
  82. }
  83. $req = $this->request->param();
  84. $page = 1;
  85. $limit = 15;
  86. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  87. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  88. $date = substr($req['date'],0,10);
  89. $req['date'] = str_replace('.','-',$date);
  90. $where = [];
  91. if (isset($req['date']) && !empty($req['date'])){
  92. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  93. }else{
  94. $this->error('参数错误');
  95. }
  96. $res = db()->table('db_大废品')
  97. ->field('sczl_gdbh, LEFT(sczl_rq, 10) as sczl_rq, rtrim(sczl_numDesc) as sczl_numDesc, sczl_ls, sczl_yjno,
  98. rtrim(责任部门) as 责任部门, CAST(sczl_cl AS SIGNED) as sczl_cl,
  99. rtrim(sczl_fplxA) as sczl_fplxA, sczl_fplxB, Jl_bzdh, JL_bh1,
  100. sczl_bzdh, sczl_bh1, sczl_je1, sczl_bh2, sczl_je2, rtrim(sys_id) as sys_id, sys_rq, UniqId')
  101. ->where('sczl_gdbh',$req['date'])
  102. ->order('UniqId desc')
  103. ->page($page,$limit)
  104. ->select();
  105. if($res){
  106. $rows=$res;
  107. $total = db()->table('db_大废品')->where('sczl_gdbh',$req['date'])->count();;
  108. }else{
  109. $rows = db()->table('db_大废品')
  110. ->field('sczl_gdbh, LEFT(sczl_rq, 10) as sczl_rq, rtrim(sczl_numDesc) as sczl_numDesc, sczl_ls, sczl_yjno,
  111. rtrim(责任部门) as 责任部门, CAST(sczl_cl AS SIGNED) as sczl_cl,
  112. rtrim(sczl_fplxA) as sczl_fplxA, sczl_fplxB, Jl_bzdh, JL_bh1,
  113. sczl_bzdh, sczl_bh1, sczl_je1, sczl_bh2, sczl_je2, rtrim(sys_id) as sys_id, sys_rq, UniqId')
  114. ->where($where)
  115. ->order('UniqId desc')
  116. ->page($page,$limit)
  117. ->select();
  118. $total = db()->table('db_大废品')->where($where)->count();
  119. }
  120. $gd = db()->table('工单_印件资料')->column('Yj_Gdbh, yj_yjmc');
  121. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  122. foreach ($rows as $key=>$value) {
  123. $rows[$key]['yj_yjmc'] = array_key_exists($value['sczl_gdbh'],$gd) ? sprintf("%02d", $value['sczl_yjno']).'-'.trim($gd[$value['sczl_gdbh']]) : '';
  124. $rows[$key]['JL_bh1'] = array_key_exists($value['JL_bh1'],$rs) ? trim($rs[$value['JL_bh1']]) : '';
  125. $rows[$key]['sczl_bh1'] = array_key_exists($value['sczl_bh1'],$rs) ? trim($rs[$value['sczl_bh1']]) : '';
  126. $rows[$key]['sczl_bh2'] = array_key_exists($value['sczl_bh2'],$rs) ? trim($rs[$value['sczl_bh2']]) : '';
  127. $rows[$key]['sczl_fplxB'] = $value['sczl_fplxB'] == 1 ? '制程废' : '';
  128. if ($value['sczl_je1'] > 0){
  129. $rows[$key]['sczl_bh1'] = $rows[$key]['sczl_bh1'].'('.$value['sczl_je1'].')';
  130. }
  131. if ($value['sczl_je2'] > 0){
  132. $rows[$key]['sczl_bh2'] = $rows[$key]['sczl_bh2'].'('.$value['sczl_je2'].')';
  133. }
  134. unset($rows[$key]['sczl_yjno']);
  135. }
  136. $data = [
  137. 'total' => $total,
  138. 'rows' => $rows,
  139. ];
  140. $this->success('成功',$data);
  141. }
  142. /**
  143. * 获取工序大废品惩奖信息
  144. * @ApiMethod (GET)
  145. * @param string $UniqId UniqId
  146. */
  147. public function getInfo()
  148. {
  149. //get请求
  150. if(!$this->request->isGet()){
  151. $this->error('请求方式错误');
  152. }
  153. $req = $this->request->param();
  154. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  155. $UniqId = $req['UniqId'];
  156. }else{
  157. $this->error('参数错误');
  158. }
  159. $rows = db()->table('db_大废品')->alias('d')
  160. ->field('sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc,sczl_yjno,rtrim(yj.yj_yjmc) as yj_yjmc,
  161. rtrim(sczl_gxmc) as sczl_gxmc,sczl_gxh,rtrim(sczl_numDesc) as sczl_numDesc,LEFT(sczl_rq, 10)
  162. as sczl_rq,sczl_cl,sczl_ls,rtrim(sczl_fplxA) as sczl_fplxA,sczl_fplxB,rtrim(责任部门) as 责任部门,
  163. rtrim(Jl_bzdh) as Jl_bzdh,jl_jtbh,JL_bh1,JL_bh2,JL_bh3,JL_bh4,JL_bh5,JL_bh6,JL_bh7,JL_bh8,JL_bh9,
  164. rtrim(jl1.员工姓名) as jlname1,rtrim(jl2.员工姓名) as jlname2,rtrim(jl3.员工姓名) as jlname3
  165. ,rtrim(jl4.员工姓名) as jlname4,rtrim(jl5.员工姓名) as jlname5,rtrim(jl6.员工姓名) as jlname6
  166. ,rtrim(jl7.员工姓名) as jlname7,rtrim(jl8.员工姓名) as jlname8,rtrim(jl9.员工姓名) as jlname9
  167. ,JL_Je1,JL_Je2,JL_Je3,JL_Je4,JL_Je5,JL_Je6,JL_Je7,JL_Je8,JL_Je9,rtrim(sczl_bzdh) as sczl_bzdh,
  168. sczl_jtbh,sczl_bh1,sczl_bh2,sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,
  169. rtrim(Jl_bzdh) as Jl_bzdh,jl_jtbh,JL_bh1,JL_bh2,JL_bh3,JL_bh4,JL_bh5,JL_bh6,JL_bh7,JL_bh8,JL_bh9,
  170. rtrim(zr1.员工姓名) as zrname1,rtrim(zr2.员工姓名) as zrname2,rtrim(zr3.员工姓名) as zrname3
  171. ,rtrim(zr4.员工姓名) as zrname4,rtrim(zr5.员工姓名) as zrname5,rtrim(zr6.员工姓名) as zrname6
  172. ,rtrim(zr7.员工姓名) as zrname7,rtrim(zr8.员工姓名) as zrname8,rtrim(zr9.员工姓名) as zrname9
  173. ,sczl_je1,sczl_je2,sczl_je3,sczl_je4,sczl_je5,sczl_je6,sczl_je7,sczl_je8,sczl_je9')
  174. ->join('工单_基本资料 g','g.Gd_gdbh=db_大废品.sczl_gdbh')
  175. ->join('工单_印件资料 yj','yj.Yj_Gdbh=db_大废品.sczl_gdbh','LEFT')
  176. ->join('人事_基本资料 jl1','jl1.员工编号=db_大废品.JL_bh1','LEFT')
  177. ->join('人事_基本资料 jl2','jl2.员工编号=db_大废品.JL_bh2','LEFT')
  178. ->join('人事_基本资料 jl3','jl3.员工编号=db_大废品.JL_bh3','LEFT')
  179. ->join('人事_基本资料 jl4','jl4.员工编号=db_大废品.JL_bh4','LEFT')
  180. ->join('人事_基本资料 jl5','jl5.员工编号=db_大废品.JL_bh5','LEFT')
  181. ->join('人事_基本资料 jl6','jl6.员工编号=db_大废品.JL_bh6','LEFT')
  182. ->join('人事_基本资料 jl7','jl7.员工编号=db_大废品.JL_bh7','LEFT')
  183. ->join('人事_基本资料 jl8','jl8.员工编号=db_大废品.JL_bh8','LEFT')
  184. ->join('人事_基本资料 jl9','jl9.员工编号=db_大废品.JL_bh9','LEFT')
  185. ->join('人事_基本资料 zr1','zr1.员工编号=db_大废品.sczl_bh1','LEFT')
  186. ->join('人事_基本资料 zr2','zr2.员工编号=db_大废品.sczl_bh2','LEFT')
  187. ->join('人事_基本资料 zr3','zr3.员工编号=db_大废品.sczl_bh3','LEFT')
  188. ->join('人事_基本资料 zr4','zr4.员工编号=db_大废品.sczl_bh4','LEFT')
  189. ->join('人事_基本资料 zr5','zr5.员工编号=db_大废品.sczl_bh5','LEFT')
  190. ->join('人事_基本资料 zr6','zr6.员工编号=db_大废品.sczl_bh6','LEFT')
  191. ->join('人事_基本资料 zr7','zr7.员工编号=db_大废品.sczl_bh7','LEFT')
  192. ->join('人事_基本资料 zr8','zr8.员工编号=db_大废品.sczl_bh8','LEFT')
  193. ->join('人事_基本资料 zr9','zr9.员工编号=db_大废品.sczl_bh9','LEFT')
  194. ->where('d.UniqId',$UniqId)->limit(1)->select();
  195. $this->success('成功',$rows);
  196. }
  197. /**
  198. * 工单编号获取
  199. * @return void
  200. * @throws \think\exception\DbException
  201. * @throws db\exception\DataNotFoundException
  202. * @throws db\exception\ModelNotFoundException
  203. */
  204. public function JunkWorkOrderList()
  205. {
  206. if ($this->request->isGet() === false){
  207. $this->error('非法请求');
  208. }
  209. $params = $this->request->param();
  210. if (empty($params['search'])){
  211. $this->error('参数错误');
  212. }
  213. $list = \db('工单_基本资料')
  214. ->field('rtrim(Gd_gdbh) as 工单编号,rtrim(成品名称) as 产品名称')
  215. ->where('Gd_gdbh','like','%'.$params['search'].'%')
  216. ->select();
  217. if (empty($list)){
  218. $this->success('未找到工单信息');
  219. }
  220. $this->success('成功',$list);
  221. }
  222. /**
  223. * 印件编号获取
  224. * @return void
  225. * @throws \think\exception\DbException
  226. * @throws db\exception\DataNotFoundException
  227. * @throws db\exception\ModelNotFoundException
  228. */
  229. public function PrintCodeList()
  230. {
  231. if ($this->request->isGet() === false){
  232. $this->error('非法请求');
  233. }
  234. $param = $this->request->param();
  235. if (empty($param['workorder'])){
  236. $this->error('参数错误');
  237. }
  238. $list = \db('工单_印件资料')
  239. ->field('rtrim(yj_Yjno) as 印件号,rtrim(yj_yjmc) as 印件名称')
  240. ->where('Yj_Gdbh',$param['workorder'])
  241. ->select();
  242. if (empty($list)){
  243. $this->success('未找到该工单印件');
  244. }
  245. $this->success('成功',$list);
  246. }
  247. /**
  248. * 工单工序获取
  249. * @return void
  250. * @throws \think\exception\DbException
  251. * @throws db\exception\DataNotFoundException
  252. * @throws db\exception\ModelNotFoundException
  253. */
  254. public function ProcessList()
  255. {
  256. if ($this->request->isGet() === false){
  257. $this->error('非法请求');
  258. }
  259. $param = $this->request->param();
  260. if (empty($param['workorder']) || empty($param['yjno'])){
  261. $this->error('参数错误');
  262. }
  263. $list = \db('工单_工艺资料')
  264. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc')
  265. ->where('Gy0_gdbh',$param['workorder'])
  266. ->where('Gy0_yjno',$param['yjno'])
  267. ->select();
  268. if (empty($list)){
  269. $this->success('未找到该工单工艺');
  270. }
  271. $data = [];
  272. foreach ($list as $key=>$value){
  273. if ((int)$value['gxh'] < 10){
  274. $value['gxh'] = '0'.$value['gxh'];
  275. }
  276. $data[$key] = $value['gxh'].'-'.$value['gxmc'];
  277. }
  278. $this->success('成功',$data);
  279. }
  280. /**
  281. * 机台编号获取
  282. * @return void
  283. * @throws \think\exception\DbException
  284. * @throws db\exception\DataNotFoundException
  285. * @throws db\exception\ModelNotFoundException
  286. */
  287. public function MachineList()
  288. {
  289. if ($this->request->isGet() === false){
  290. $this->error('非法请求');
  291. }
  292. $param = $this->request->param();
  293. $list = \db('设备_产量计酬')
  294. ->alias('a')
  295. ->join('人事_基本资料 b1','a.sczl_bh1 = b1.员工编号','left')
  296. ->join('人事_基本资料 b2','a.sczl_bh2 = b2.员工编号','left')
  297. ->join('人事_基本资料 b3','a.sczl_bh3 = b3.员工编号','left')
  298. ->join('人事_基本资料 b4','a.sczl_bh4 = b4.员工编号','left')
  299. ->join('人事_基本资料 b5','a.sczl_bh5 = b5.员工编号','left')
  300. ->join('人事_基本资料 b6','a.sczl_bh6 = b6.员工编号','left')
  301. ->join('人事_基本资料 b7','a.sczl_bh7 = b7.员工编号','left')
  302. ->join('人事_基本资料 b8','a.sczl_bh8 = b8.员工编号','left')
  303. ->join('人事_基本资料 b9','a.sczl_bh9 = b9.员工编号','left')
  304. ->join('人事_基本资料 b10','a.sczl_bh10 = b10.员工编号','left')
  305. ->field('a.sczl_gxmc as 工序名称,a.sczl_jtbh as 机台编号,a.sczl_bh1 as 员工编号1,rtrim(b1.员工姓名) as 员工姓名1
  306. ,a.sczl_bh2 as 员工编号2,rtrim(b2.员工姓名) as 员工姓名2,a.sczl_bh3 as 员工编号3,rtrim(b3.员工姓名) as 员工姓名3
  307. ,a.sczl_bh4 as 员工编号4,rtrim(b4.员工姓名) as 员工姓名4,a.sczl_bh5 as 员工编号5,rtrim(b5.员工姓名) as 员工姓名5
  308. ,a.sczl_bh6 as 员工编号6,rtrim(b6.员工姓名) as 员工姓名6,a.sczl_bh7 as 员工编号7,rtrim(b7.员工姓名) as 员工姓名7
  309. ,a.sczl_bh8 as 员工编号8,rtrim(b8.员工姓名) as 员工姓名8,a.sczl_bh9 as 员工编号9,rtrim(b9.员工姓名) as 员工姓名9
  310. ,a.sczl_bh10 as 员工编号10,rtrim(b10.员工姓名) as 员工姓名10')
  311. ->where('a.sczl_gdbh',$param['gdbh'])
  312. ->where('a.sczl_yjno',$param['yjno'])
  313. ->where('a.sczl_bzdh','like',substr($param['bzdh'],0,1).'%')
  314. ->group('机台编号,员工编号1,员工编号2,员工编号3,员工编号4,员工编号5,员工编号6,员工编号7,员工编号8,员工编号9,员工编号10')
  315. ->select();
  316. // $list = \db('设备_基本资料')
  317. // ->field('rtrim(设备编号) as 设备编号')
  318. // ->where('sys_sbID','<>','')
  319. // ->select();
  320. if (empty($list)){
  321. $this->success('未找到机台编号');
  322. }
  323. $this->success('成功',$list);
  324. }
  325. /**
  326. * 机台班组获取
  327. * @return void
  328. * @throws \think\exception\DbException
  329. * @throws db\exception\DataNotFoundException
  330. * @throws db\exception\ModelNotFoundException
  331. */
  332. public function MachineClassList()
  333. {
  334. if ($this->request->isGet() === false){
  335. $this->error('非法请求');
  336. }
  337. $param = $this->request->param();
  338. if (empty($param['machine'])){
  339. $this->error('参数错误');
  340. }
  341. $list = \db('设备_班组资料')
  342. ->where('sczl_jtbh',$param['machine'])
  343. ->field('rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,
  344. rtrim(sczl_bh4) as bh4,rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,
  345. rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
  346. rtrim(sczl_bh10) as bh10,rtrim(sczl_bzdh) as 班组代号')
  347. ->select();
  348. if (empty($list)){
  349. $this->success('未找到该机台班组');
  350. }
  351. foreach ($list as $key=>$value){
  352. for ($i=1;$i<=10;$i++){
  353. if (!empty($value['bh'.$i])){
  354. $name = \db('人事_基本资料')->where('员工编号',$value['bh'.$i])->field('rtrim(员工姓名) as name')->find();
  355. if (isset($name['name'])){
  356. $list[$key]['组员'.$i] = [
  357. '编号' => $value['bh'.$i],
  358. '姓名' => $name['name']
  359. ];
  360. }
  361. }else{
  362. $list[$key]['组员'.$i] = [
  363. '编号' => '',
  364. '姓名' => ''
  365. ];
  366. }
  367. unset($list[$key]['bh'.$i]);
  368. }
  369. }
  370. $this->success('成功',$list);
  371. }
  372. /**
  373. * 大废品数据修改
  374. * @return void
  375. * @throws \think\Exception
  376. * @throws \think\exception\PDOException
  377. * @throws db\exception\BindParamException
  378. */
  379. public function JunkDetailEdit()
  380. {
  381. if (Request::instance()->isPost() === false){
  382. $this->error('非法请求');
  383. }
  384. $param = Request::instance()->post();
  385. if (empty($param['sczl_gdbh']) || empty($param['UniqId'])){
  386. $this->error('参数错误');
  387. }
  388. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  389. $data = $param;
  390. unset($data['UniqId']);
  391. $sql = \db('db_大废品')
  392. ->where('UniqId',$param['UniqId'])
  393. ->fetchSql(true)
  394. ->update($data);
  395. $res = \db()->query($sql);
  396. if ($res !== false){
  397. $this->success('修改成功');
  398. }else{
  399. $this->error('失败');
  400. }
  401. }
  402. /**
  403. * 大废品数据添加
  404. * @return void
  405. * @throws \think\exception\PDOException
  406. * @throws db\exception\BindParamException
  407. */
  408. public function JunkDetailAdd()
  409. {
  410. if (Request::instance()->isPost() === false){
  411. $this->error('非法请求');
  412. }
  413. $param = Request::instance()->post();
  414. if (empty($param['sczl_gdbh'])){
  415. $this->error('参数错误');
  416. }
  417. $lastID = \db('db_大废品')->order('UniqId desc')->value('UniqId');
  418. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  419. $param['mod_rq'] = '1900-01-01 00:00:00';
  420. $param['UniqId'] = $lastID + 1;
  421. $sql = \db('db_大废品')->fetchSql(true)->insert($param);
  422. $res = \db()->query($sql);
  423. if ($res !== false){
  424. $this->success('添加成功');
  425. }else{
  426. $this->error('失败');
  427. }
  428. }
  429. /**
  430. * 大废品数据删除
  431. * @return void
  432. * @throws \think\Exception
  433. * @throws \think\exception\PDOException
  434. */
  435. public function JunkDetailDel()
  436. {
  437. if ($this->request->isGet() === false){
  438. $this->error('非法请求');
  439. }
  440. $param = $this->request->param();
  441. if (empty($param['UniqId'])){
  442. $this->error('参数错误');
  443. }
  444. $idList = explode(',',$param['UniqId']);
  445. $res = \db('db_大废品')
  446. ->whereIn('UniqId',$idList)
  447. ->delete();
  448. if ($res !== false){
  449. $this->success('删除成功');
  450. }else{
  451. $this->error('失败');
  452. }
  453. }
  454. }