PieceWorkSchedule.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 PieceWorkSchedule 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_wgjs')
  32. ->field('LEFT(wgjs_rq, 7) as date')
  33. ->group('date')
  34. ->order('UniqId desc')
  35. ->limit(15)
  36. ->select();
  37. foreach($rows as $key=>$value){
  38. $rows[$key]['date'] = str_replace('-', '', $rows[$key]['date']);
  39. }
  40. $this->success('成功',$rows);
  41. }
  42. /**
  43. * 获取计件工计时单列表
  44. * @ApiMethod (GET)
  45. * @param string $date 时间
  46. * @param string $Sczl_bh1 员工编号
  47. */
  48. public function getList()
  49. {
  50. //get请求
  51. if(!$this->request->isGet()){
  52. $this->error('请求方式错误');
  53. }
  54. $req = $this->request->param();
  55. $page = 1;
  56. $limit = 15;
  57. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  58. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  59. $where = [];
  60. if (isset($req['date']) && !empty($req['date'])){
  61. $where['wgjs_rq'] = ['LIKE',$req['date'].'%'];
  62. }else{
  63. $this->error('参数错误');
  64. }
  65. $rows = db()->table('db_wgjs')
  66. ->field('LEFT(wgjs_rq, 10) as wgjs_rq,
  67. wgjs_bh1, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
  68. wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
  69. wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
  70. wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
  71. wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
  72. wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6')
  73. ->where($where)
  74. ->order('wgjs_rq desc, UniqId asc')
  75. ->page($page,$limit)
  76. ->select();
  77. $total = db()->table('db_wgjs')->where($where)->count();
  78. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名, 所在部门');
  79. foreach ($rows as $key=>$value){
  80. $rows[$key]['wgjs_js1'] = $value['wgjs_js1'] == 0 ? '' : $value['wgjs_js1'];
  81. //存在该员工编号
  82. if (array_key_exists($value['wgjs_bh1'],$rs)){
  83. $rows[$key]['department'] = trim($rs[$value['wgjs_bh1']]['所在部门']);
  84. $rows[$key]['name1'] = trim($rs[$value['wgjs_bh1']]['员工姓名']);
  85. for ($i=2;$i<=6;$i++){
  86. $rows[$key]['wgjs_js'.$i] = $value['wgjs_js'.$i] == '0.0' ? '' : $value['wgjs_js'.$i];
  87. if ($value['wgjs_bh'.$i]){
  88. if ($value['wgjs_bh'.$i]==$value['wgjs_bh1']){
  89. $rows[$key]['name'.$i] = $rows[$key]['name1'];
  90. }else{
  91. $rows[$key]['name'.$i] = trim($rs[$value['wgjs_bh'.$i]]['员工姓名']);
  92. }
  93. }else{
  94. $rows[$key]['name'.$i] = '';
  95. }
  96. }
  97. }else{
  98. $rows[$key]['department'] = '';
  99. $rows[$key]['name1'] = '';
  100. for ($i=2;$i<=6;$i++){
  101. $rows[$key]['wgjs_js'.$i] = $value['wgjs_js'.$i] == '0.0' ? '' : $value['wgjs_js'.$i];
  102. $rows[$key]['name'.$i] = '';
  103. }
  104. }
  105. }
  106. $data = [
  107. 'total' => $total,
  108. 'rows' => $rows,
  109. ];
  110. $this->success('成功',$data);
  111. }
  112. /**
  113. * 获取计件工计时单信息
  114. * @ApiMethod (GET)
  115. * @param string $UniqId UniqId
  116. */
  117. public function getInfo()
  118. {
  119. //get请求
  120. if(!$this->request->isGet()){
  121. $this->error('请求方式错误');
  122. }
  123. $req = $this->request->param();
  124. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  125. $UniqId = $req['UniqId'];
  126. }else{
  127. $this->error('参数错误');
  128. }
  129. $rows = db()->table('db_wgjs')->alias('d')
  130. ->field('d.*, ')
  131. ->join('工单_基本资料 g', 'd.')
  132. ->where('d.UniqId',$UniqId)
  133. ->select();
  134. $this->success('成功',$rows);
  135. }
  136. /**
  137. * 定位
  138. * @ApiMethod GET
  139. */
  140. public function search(){
  141. if (Request::instance()->isGet() == false){
  142. $this->error('非法请求');
  143. }
  144. $req = Request::instance()->param();
  145. if (!isset($req['search']) || !isset($req['date'])){
  146. $this->error('参数错误');
  147. }
  148. $page = 1;
  149. $limit = 10;
  150. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  151. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  152. $year=substr($req['date'],0,4);
  153. $month=substr($req['date'],-2);
  154. if($month==12){
  155. $start_time=$year.'-12-01 00:00:00';
  156. $end_time=($year+1).'-01-01 00:00:00';
  157. }else{
  158. $start_time=$year.'-'.$month.'-01 00:00:00';
  159. $end_time=$year.'-'.($month+1).'-01 00:00:00';
  160. }
  161. $yg = db()->table('人事_基本资料')->where('员工姓名',$req['search'])->value('员工编号');
  162. if($yg){
  163. $req['search']=$yg;
  164. }
  165. $rows = db()->table('db_wgjs')
  166. ->field('LEFT(wgjs_rq, 10) as wgjs_rq,
  167. wgjs_bh1,rs1.所在部门, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
  168. wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
  169. wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
  170. wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
  171. wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
  172. wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6,
  173. rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名)
  174. as name3,rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名)
  175. as name6')
  176. ->join('人事_基本资料 rs1','rs1.员工编号=db_wgjs.wgjs_bh1','LEFT')
  177. ->join('人事_基本资料 rs2','rs2.员工编号=db_wgjs.wgjs_bh2','LEFT')
  178. ->join('人事_基本资料 rs3','rs3.员工编号=db_wgjs.wgjs_bh3','LEFT')
  179. ->join('人事_基本资料 rs4','rs4.员工编号=db_wgjs.wgjs_bh4','LEFT')
  180. ->join('人事_基本资料 rs5','rs5.员工编号=db_wgjs.wgjs_bh5','LEFT')
  181. ->join('人事_基本资料 rs6','rs6.员工编号=db_wgjs.wgjs_bh6','LEFT')
  182. ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'wgjs_bh1'=>$req['search']])
  183. ->select();
  184. $total = db()->table('db_wgjs')->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'wgjs_bh1'=>$req['search']])->count();
  185. $data = ['total'=> $total,'rows'=> $rows];
  186. if($rows){
  187. $this->success('成功',$data);
  188. }else{
  189. $this->error('失败');
  190. }
  191. }
  192. /**
  193. * 详情
  194. * @ApiMethod (GET)
  195. * @param string $wgjs_rq 日期
  196. * @param string $wgjs_bh1 员工编号
  197. */
  198. public function detail(){
  199. //get请求
  200. if(!$this->request->isGet()){
  201. $this->error('请求方式错误');
  202. }
  203. $req = $this->request->param();
  204. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
  205. $this->error('参数错误');
  206. }else{
  207. }
  208. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
  209. $this->error('参数不能为空');
  210. }
  211. $rows = db()->table('db_wgjs')
  212. ->field('LEFT(wgjs_rq, 10) as wgjs_rq,
  213. wgjs_bh1, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
  214. wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
  215. wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
  216. wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
  217. wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
  218. wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6,
  219. rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名)
  220. as name3,rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名)
  221. as name6,wgjs_冲定额1,wgjs_冲定额2,wgjs_冲定额3,wgjs_冲定额4,wgjs_冲定额5,wgjs_冲定额6')
  222. ->join('人事_基本资料 rs1','rs1.员工编号=db_wgjs.wgjs_bh1','LEFT')
  223. ->join('人事_基本资料 rs2','rs2.员工编号=db_wgjs.wgjs_bh2','LEFT')
  224. ->join('人事_基本资料 rs3','rs3.员工编号=db_wgjs.wgjs_bh3','LEFT')
  225. ->join('人事_基本资料 rs4','rs4.员工编号=db_wgjs.wgjs_bh4','LEFT')
  226. ->join('人事_基本资料 rs5','rs5.员工编号=db_wgjs.wgjs_bh5','LEFT')
  227. ->join('人事_基本资料 rs6','rs6.员工编号=db_wgjs.wgjs_bh6','LEFT')
  228. ->where(['wgjs_rq'=>$req['wgjs_rq'].' 00:00:00','wgjs_bh1'=>$req['wgjs_bh1']])
  229. ->find();
  230. if($rows){
  231. $this->success('成功',$rows);
  232. }else{
  233. $this->error('失败');
  234. }
  235. }
  236. /**
  237. * 修改
  238. * @ApiMethod POST
  239. */
  240. public function edit()
  241. {
  242. if(!$this->request->isPost()){
  243. $this->error('请求方式错误');
  244. }
  245. $req = $this->request->param();
  246. // $req = ['wgjs_js1'=>12,'wgjs_rq'=>'2023-10-12','wgjs_bh1'=>'ZM01269'];
  247. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
  248. $this->error('参数错误');
  249. }
  250. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
  251. $this->error('参数不能为空');
  252. }
  253. $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  254. $req['mod_rq'] = date('Y-m-d H:i:s');
  255. //开启事务
  256. db()->startTrans();
  257. try{
  258. $sql = db()->table('db_wgjs')->where(['wgjs_rq'=>$req['wgjs_rq'],'wgjs_bh1'=>$req['wgjs_bh1']])
  259. ->fetchSql(true)->update($req);
  260. $res= db()->query($sql);
  261. // 提交事务
  262. db()->commit();
  263. } catch (\Exception $e) {
  264. // 回滚事务
  265. db()->rollback();
  266. $this->error($e->getMessage());
  267. }
  268. if($res===false) $this->error('失败');
  269. $this->success('成功');
  270. }
  271. /**
  272. * 新增
  273. * @ApiMethod POST
  274. */
  275. public function add()
  276. {
  277. if(!$this->request->isPost()){
  278. $this->error('请求方式错误');
  279. }
  280. $req = $this->request->param();
  281. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
  282. $this->error('参数错误');
  283. }
  284. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
  285. $this->error('参数不能为空');
  286. }
  287. $UniqId = db()->table('db_wgjs')->order('UniqId desc')->value('UniqId');
  288. if ($UniqId < 1000000){
  289. $UniqId = 1000000;
  290. }else{
  291. $UniqId = $UniqId + 1;
  292. }
  293. $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  294. $req['sys_rq'] = date('Y-m-d H:i:s');
  295. $req['UniqId'] = $UniqId;
  296. //开启事务
  297. db()->startTrans();
  298. try{
  299. $sql = db()->table('db_wgjs')->fetchSql(true)->insert($req);
  300. $res= db()->query($sql);
  301. // 提交事务
  302. db()->commit();
  303. } catch (\Exception $e) {
  304. // 回滚事务
  305. db()->rollback();
  306. $this->error($e->getMessage());
  307. }
  308. if($res===false) $this->error('失败');
  309. $this->success('成功');
  310. }
  311. /**
  312. * 删除
  313. * @ApiMethod (GET)
  314. * @param string $wgjs_rq 日期
  315. * @param string $wgjs_bh1 员工编号
  316. */
  317. public function del(){
  318. //get请求
  319. if(!$this->request->isGet()){
  320. $this->error('请求方式错误');
  321. }
  322. $req = $this->request->param();
  323. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
  324. $this->error('参数错误');
  325. }else{
  326. }
  327. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
  328. $this->error('参数不能为空');
  329. }
  330. $rows = db()->table('db_wgjs')->where(['wgjs_rq'=>$req['wgjs_rq'].' 00:00:00','wgjs_bh1'=>$req['wgjs_bh1']])
  331. ->delete();
  332. if($rows){
  333. $this->success('成功');
  334. }else{
  335. $this->error('失败');
  336. }
  337. }
  338. }