LargeWasteRewardPunish.php 19 KB

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