PieceWorkSchedule.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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_wgjs1')
  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_wgjs1')
  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_wgjs1')->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. * @params date $data
  140. * @params string code
  141. */
  142. public function locate(){
  143. if (Request::instance()->isGet() == false){
  144. $this->error('非法请求');
  145. }
  146. $params = Request::instance()->param();
  147. if (!isset($params['code']) || !isset($params['date'])){
  148. $this->error('参数错误');
  149. }
  150. halt($params);
  151. }
  152. /**
  153. * 详情
  154. * @ApiMethod (GET)
  155. * @param string $wgjs_rq 日期
  156. * @param string $wgjs_bh1 员工编号
  157. */
  158. public function detail(){
  159. //get请求
  160. if(!$this->request->isGet()){
  161. $this->error('请求方式错误');
  162. }
  163. $req = $this->request->param();
  164. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
  165. $this->error('参数错误');
  166. }else{
  167. }
  168. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
  169. $this->error('参数不能为空');
  170. }
  171. $rows = db()->table('db_wgjs1')
  172. ->field('LEFT(wgjs_rq, 10) as wgjs_rq,
  173. wgjs_bh1, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
  174. wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
  175. wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
  176. wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
  177. wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
  178. wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6,
  179. rs1.员工姓名 as name1,rs2.员工姓名 as name2,rs3.员工姓名 as name3,rs4.员工姓名
  180. as name4,rs5.员工姓名 as name5,rs6.员工姓名 as name6,wgjs_冲定额1,wgjs_冲定额2
  181. ,wgjs_冲定额3,wgjs_冲定额4,wgjs_冲定额5,wgjs_冲定额6')
  182. ->join('人事_基本资料 rs1','rs1.员工编号=db_wgjs1.wgjs_bh1','LEFT')
  183. ->join('人事_基本资料 rs2','rs2.员工编号=db_wgjs1.wgjs_bh2','LEFT')
  184. ->join('人事_基本资料 rs3','rs3.员工编号=db_wgjs1.wgjs_bh3','LEFT')
  185. ->join('人事_基本资料 rs4','rs4.员工编号=db_wgjs1.wgjs_bh4','LEFT')
  186. ->join('人事_基本资料 rs5','rs5.员工编号=db_wgjs1.wgjs_bh5','LEFT')
  187. ->join('人事_基本资料 rs6','rs6.员工编号=db_wgjs1.wgjs_bh6','LEFT')
  188. ->where(['wgjs_rq'=>$req['wgjs_rq'].' 00:00:00','wgjs_bh1'=>$req['wgjs_bh1']])
  189. ->find();
  190. if($rows){
  191. $this->success('成功',$rows);
  192. }else{
  193. $this->error('失败');
  194. }
  195. }
  196. /**
  197. * 修改
  198. * @ApiMethod POST
  199. */
  200. public function edit()
  201. {
  202. if(!$this->request->isPost()){
  203. $this->error('请求方式错误');
  204. }
  205. $req = $this->request->param();
  206. // $req = ['wgjs_js1'=>12,'wgjs_rq'=>'2023-10-12','wgjs_bh1'=>'ZM01269'];
  207. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
  208. $this->error('参数错误');
  209. }
  210. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
  211. $this->error('参数不能为空');
  212. }
  213. $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  214. $req['mod_rq'] = date('Y-m-d H:i:s');
  215. //开启事务
  216. db()->startTrans();
  217. try{
  218. $sql = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'],'wgjs_bh1'=>$req['wgjs_bh1']])
  219. ->fetchSql(true)->update($req);
  220. $res= db()->query($sql);
  221. // 提交事务
  222. db()->commit();
  223. } catch (\Exception $e) {
  224. // 回滚事务
  225. db()->rollback();
  226. $this->error($e->getMessage());
  227. }
  228. if($res===false) $this->error('失败');
  229. $this->success('成功');
  230. }
  231. /**
  232. * 新增
  233. * @ApiMethod POST
  234. */
  235. public function add()
  236. {
  237. if(!$this->request->isPost()){
  238. $this->error('请求方式错误');
  239. }
  240. $req = $this->request->param();
  241. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
  242. $this->error('参数错误');
  243. }
  244. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
  245. $this->error('参数不能为空');
  246. }
  247. $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
  248. $req['sys_rq'] = date('Y-m-d H:i:s');
  249. //开启事务
  250. db()->startTrans();
  251. try{
  252. $sql = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'],'wgjs_bh1'=>$req['wgjs_bh1']])
  253. ->fetchSql(true)->insert($req);
  254. $res= db()->query($sql);
  255. // 提交事务
  256. db()->commit();
  257. } catch (\Exception $e) {
  258. // 回滚事务
  259. db()->rollback();
  260. $this->error($e->getMessage());
  261. }
  262. if($res===false) $this->error('失败');
  263. $this->success('成功');
  264. }
  265. /**
  266. * 删除
  267. * @ApiMethod (GET)
  268. * @param string $wgjs_rq 日期
  269. * @param string $wgjs_bh1 员工编号
  270. */
  271. public function del(){
  272. //get请求
  273. if(!$this->request->isGet()){
  274. $this->error('请求方式错误');
  275. }
  276. $req = $this->request->param();
  277. if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
  278. $this->error('参数错误');
  279. }else{
  280. }
  281. if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
  282. $this->error('参数不能为空');
  283. }
  284. $rows = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'].' 00:00:00','wgjs_bh1'=>$req['wgjs_bh1']])
  285. ->delete();
  286. if($rows){
  287. $this->success('成功');
  288. }else{
  289. $this->error('失败');
  290. }
  291. }
  292. }