PieceWorkSchedule.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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, UniqId,
  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. $start_time = $year . '-' . $month . '-01 00:00:00';
  155. $end_time = date('Y-m-t', strtotime("$year-$month-01")) . ' 23:59:59';
  156. $yg = db()->table('人事_基本资料')->where('员工姓名',$req['search'])->value('员工编号');
  157. if($yg){
  158. $req['search']=$yg;
  159. }
  160. $where = [
  161. 'db_wgjs.wgjs_rq'=>['between',"$start_time,$end_time"],
  162. 'db_wgjs.wgjs_bh1|db_wgjs.wgjs_bh2|db_wgjs.wgjs_bh3|db_wgjs.wgjs_bh4|db_wgjs.wgjs_bh5|db_wgjs.wgjs_bh6'=>['like', '%'.$req['search'].'%']
  163. ];
  164. $rows = db()->table('db_wgjs')
  165. ->field('LEFT(db_wgjs.wgjs_rq, 10) as wgjs_rq,
  166. db_wgjs.wgjs_bh1,trim(rs1.所在部门) as 所在部门, CAST(db_wgjs.wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(db_wgjs.wgjs_yy1) as wgjs_yy1,
  167. db_wgjs.wgjs_bh2, CAST(db_wgjs.wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(db_wgjs.wgjs_yy2) as wgjs_yy2,
  168. db_wgjs.wgjs_bh3, CAST(db_wgjs.wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(db_wgjs.wgjs_yy3) as wgjs_yy3,
  169. db_wgjs.wgjs_bh4, CAST(db_wgjs.wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(db_wgjs.wgjs_yy4) as wgjs_yy4,
  170. db_wgjs.wgjs_bh5, CAST(db_wgjs.wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(db_wgjs.wgjs_yy5) as wgjs_yy5,
  171. db_wgjs.wgjs_bh6, CAST(db_wgjs.wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(db_wgjs.wgjs_yy6) as wgjs_yy6,
  172. rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名) as name3,
  173. rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名) as name6,
  174. db_wgjs.UniqId')
  175. ->join('人事_基本资料 rs1','rs1.员工编号=db_wgjs.wgjs_bh1','LEFT')
  176. ->join('人事_基本资料 rs2','rs2.员工编号=db_wgjs.wgjs_bh2','LEFT')
  177. ->join('人事_基本资料 rs3','rs3.员工编号=db_wgjs.wgjs_bh3','LEFT')
  178. ->join('人事_基本资料 rs4','rs4.员工编号=db_wgjs.wgjs_bh4','LEFT')
  179. ->join('人事_基本资料 rs5','rs5.员工编号=db_wgjs.wgjs_bh5','LEFT')
  180. ->join('人事_基本资料 rs6','rs6.员工编号=db_wgjs.wgjs_bh6','LEFT')
  181. ->where($where)
  182. ->order('wgjs_rq desc, UniqId asc')
  183. ->page($page,$limit)
  184. ->select();
  185. $total = db()->table('db_wgjs')->where($where)->count();
  186. $data = ['total'=> $total,'rows'=> $rows];
  187. if($rows){
  188. $this->success('成功',$data);
  189. }else{
  190. $this->error('失败');
  191. }
  192. }
  193. /**
  194. * 详情
  195. * @ApiMethod (GET)
  196. * @param string $wgjs_rq 日期
  197. * @param string $wgjs_bh1 员工编号
  198. */
  199. public function detail(){
  200. //get请求
  201. if(!$this->request->isGet()){
  202. $this->error('请求方式错误');
  203. }
  204. $req = $this->request->param();
  205. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  206. $this->error('参数错误','UniqId',100);
  207. }
  208. $rows = db('db_wgjs')
  209. ->field('LEFT(wgjs_rq, 10) as wgjs_rq, db_wgjs.UniqId,
  210. wgjs_bh1, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
  211. wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
  212. wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
  213. wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
  214. wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
  215. wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6,
  216. rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名)
  217. as name3,rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名)
  218. as name6,wgjs_冲定额1,wgjs_冲定额2,wgjs_冲定额3,wgjs_冲定额4,wgjs_冲定额5,wgjs_冲定额6')
  219. ->join('人事_基本资料 rs1','rs1.员工编号=db_wgjs.wgjs_bh1','LEFT')
  220. ->join('人事_基本资料 rs2','rs2.员工编号=db_wgjs.wgjs_bh2','LEFT')
  221. ->join('人事_基本资料 rs3','rs3.员工编号=db_wgjs.wgjs_bh3','LEFT')
  222. ->join('人事_基本资料 rs4','rs4.员工编号=db_wgjs.wgjs_bh4','LEFT')
  223. ->join('人事_基本资料 rs5','rs5.员工编号=db_wgjs.wgjs_bh5','LEFT')
  224. ->join('人事_基本资料 rs6','rs6.员工编号=db_wgjs.wgjs_bh6','LEFT')
  225. ->where('db_wgjs.UniqId', $req['UniqId'])
  226. ->find();
  227. if($rows!==false){
  228. $this->success('成功',$rows);
  229. }else{
  230. $this->error('失败');
  231. }
  232. }
  233. /**
  234. * 修改
  235. * @ApiMethod POST
  236. */
  237. public function edit()
  238. {
  239. if(!$this->request->isPost()){
  240. $this->error('请求方式错误');
  241. }
  242. $req = $this->request->param();
  243. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  244. $this->error('参数错误','UniqId',100);
  245. }
  246. $arr = [
  247. 'wgjs_rq',
  248. 'wgjs_bh1', 'wgjs_bh2', 'wgjs_bh3', 'wgjs_bh4', 'wgjs_bh5', 'wgjs_bh6',
  249. 'wgjs_js1', 'wgjs_js2', 'wgjs_js3', 'wgjs_js4', 'wgjs_js5', 'wgjs_js6',
  250. 'wgjs_yy1', 'wgjs_yy2', 'wgjs_yy3', 'wgjs_yy4', 'wgjs_yy5', 'wgjs_yy6',
  251. 'wgjs_冲定额1', 'wgjs_冲定额2', 'wgjs_冲定额3', 'wgjs_冲定额4', 'wgjs_冲定额5', 'wgjs_冲定额6'
  252. ];
  253. $data = [];
  254. foreach ($arr as $key => $value){
  255. if (!isset($req[$value])){
  256. continue;
  257. }
  258. $data[$value] = $req[$value];
  259. }
  260. if (count($data)==0){
  261. $this->error('参数错误','',111);
  262. }
  263. $data['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  264. $data['mod_rq'] = date('Y-m-d H:i:s');
  265. //开启事务
  266. db()->startTrans();
  267. try{
  268. $sql = db('db_wgjs')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
  269. $bool = db()->query($sql);
  270. // 提交事务
  271. db()->commit();
  272. } catch (\Exception $e) {
  273. // 回滚事务
  274. db()->rollback();
  275. $this->error($e->getMessage());
  276. }
  277. if($bool===false) $this->error('失败');
  278. $this->success('成功');
  279. }
  280. /**
  281. * 新增
  282. * @ApiMethod POST
  283. */
  284. public function add()
  285. {
  286. if(!$this->request->isPost()){
  287. $this->error('请求方式错误');
  288. }
  289. $req = $this->request->param();
  290. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) || !isset($req['sys_id']) ){
  291. $this->error('参数错误');
  292. }
  293. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1']) || empty($req['sys_id'])){
  294. $this->error('参数不能为空');
  295. }
  296. $UniqId = db()->table('db_wgjs')->order('UniqId desc')->value('UniqId');
  297. if ($UniqId < 1000000){
  298. $UniqId = 1000000;
  299. }else{
  300. $UniqId = $UniqId + 1;
  301. }
  302. $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  303. $req['sys_rq'] = date('Y-m-d H:i:s');
  304. $req['UniqId'] = $UniqId;
  305. $req['sys_id'] = $req['sys_id'];
  306. //开启事务
  307. db()->startTrans();
  308. try{
  309. $sql = db()->table('db_wgjs')->fetchSql(true)->insert($req);
  310. $res= db()->query($sql);
  311. // 提交事务
  312. db()->commit();
  313. } catch (\Exception $e) {
  314. // 回滚事务
  315. db()->rollback();
  316. $this->error($e->getMessage());
  317. }
  318. if($res===false) $this->error('失败');
  319. $this->success('成功');
  320. }
  321. /**
  322. * 删除
  323. * @ApiMethod (GET)
  324. * @param string $wgjs_rq 日期
  325. * @param string $wgjs_bh1 员工编号
  326. */
  327. public function del(){
  328. //get请求
  329. if(!$this->request->isGet()){
  330. $this->error('请求方式错误');
  331. }
  332. $req = $this->request->param();
  333. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  334. $this->error('参数错误','UniqId',100);
  335. }
  336. //开启事务
  337. db()->startTrans();
  338. try{
  339. $bool = db('db_wgjs')->where('UniqId',$req['UniqId'])->delete();
  340. // 提交事务
  341. db()->commit();
  342. } catch (\Exception $e) {
  343. // 回滚事务
  344. db()->rollback();
  345. $this->error($e->getMessage());
  346. }
  347. if($bool===false) $this->error('失败');
  348. $this->success('成功');
  349. }
  350. }