| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use \think\Request;
- use \think\Db;
- /**
- * 员工日工资查询接口
- */
- class EmployeeDailySalary extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- $this->success('请求成功');
- }
- /**
- * 员工日工资查询侧边栏
- * @ApiMethod (GET)
- */
- public function getTab()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $rows = db()->table('绩效工资汇总')
- ->group('sys_ny')
- ->order('sys_ny desc')
- ->limit(15)
- ->column('sys_ny');
- foreach($rows as $k=>$v){
- $res[$k]['ny']=$v;
- $res[$k]['bh']=db()->table('绩效工资汇总')
- ->group('bh')
- ->where('sys_ny',$v)
- ->column('bh');
- // $res[$k]['bm']=db()->table('绩效工资汇总')
- // ->join('人事_基本资料','人事_基本资料.员工编号=绩效工资汇总.bh','LEFT')
- // ->group('人事_基本资料.所在部门')
- // ->where('sys_ny',$v)
- // ->column('人事_基本资料.所在部门');
- }
- $rs = db()->table('人事_基本资料')->column('员工编号,所在部门');
- foreach($res as $k=>$v){
- foreach($v['bh'] as $value){
- $res[$k]['bm'][]=$rs[$value];
- }
- }
- foreach($res as &$v){
- unset($v['bh']);
- $v['bm']=array_unique($v['bm']);
- foreach($v['bm'] as &$value){
- $value=rtrim($value);
- }
- usort($v['bm'], function($a, $b) {
- $order = array(
- '胶印车间',
- '凹印车间',
- '丝印车间',
- '模切车间',
- '检验车间',
- '精品试验车间',
- '品保部',
- '人力资源部',
- '生产部',
- '营销部'
- );
- $a_index = array_search($a, $order);
- $b_index = array_search($b, $order);
- return $a_index - $b_index;
- });
- }
- foreach($res as $k=>$v){
- $data[$k]['lable']=$v['ny'];
- foreach($v['bm'] as $value){
- $data[$k]['children'][]['lable']=$value;
- }
- }
- $this->success('成功',$data);
- }
-
- /**
- * 员工日工资查询列表
- * @ApiMethod (GET)
- * @param string $date 时间
- * @param string $Sczl_bh1 员工编号
- */
- public function getList()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- $res=db()->table('绩效工资汇总')
- ->join('人事_基本资料','人事_基本资料.员工编号=绩效工资汇总.bh','LEFT')
- ->field('bh,xm as 员工姓名,LEFT(sczl_rq, 10) as sczl_rq,sum(个人计件工资) as 计件工资,
- sum(个人加班工资) as 加班工资,(sum(个人计件工资)+sum(个人加班工资)) as 日工资合计')
- ->group('绩效工资汇总.bh,LEFT(sczl_rq, 10)')
- ->where('sys_ny',$req['date'])
- ->where('人事_基本资料.所在部门',$req['department'])
- ->select();
- $year=substr($req['date'],0,4);
- $month=substr($req['date'],-2);
- if($month==12){
- $start_time=$year.'-12-01 00:00:00';
- $end_time=($year+1).'-01-01 00:00:00';
- }else{
- $start_time=$year.'-'.$month.'-01 00:00:00';
- $end_time=$year.'-'.($month+1).'-01 00:00:00';
- }
- $res1=db()->table('db_wgjs1')
- ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh1 as wgjs_bh,wgjs_js1 as wgjs_js')
- ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh1','LEFT')
- ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
- ->select();
- $res2=db()->table('db_wgjs1')
- ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh2 as wgjs_bh,wgjs_js2 as wgjs_js')
- ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh2','LEFT')
- ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
- ->select();
- $res3=db()->table('db_wgjs1')
- ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh3 as wgjs_bh,wgjs_js3 as wgjs_js')
- ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh3','LEFT')
- ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
- ->select();
- $res4=db()->table('db_wgjs1')
- ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh4 as wgjs_bh,wgjs_js4 as wgjs_js')
- ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh4','LEFT')
- ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
- ->select();
- $res5=db()->table('db_wgjs1')
- ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh5 as wgjs_bh,wgjs_js5 as wgjs_js')
- ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh5','LEFT')
- ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
- ->select();
- $res6=db()->table('db_wgjs1')
- ->field('LEFT(wgjs_rq, 10) as wgjs_rq,wgjs_bh6 as wgjs_bh,wgjs_js6 as wgjs_js')
- ->join('人事_基本资料','人事_基本资料.员工编号=db_wgjs1.wgjs_bh6','LEFT')
- ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'人事_基本资料.所在部门'=>$req['department']])
- ->select();
- $arr=array_merge($res1,$res2,$res3,$res4,$res5,$res6);
- foreach($arr as $v){
- if(isset($list[$v['wgjs_rq']][$v['wgjs_bh']])){
- $list[$v['wgjs_rq']][$v['wgjs_bh']]+=$v['wgjs_js'];
- }else{
- $list[$v['wgjs_rq']][$v['wgjs_bh']]=$v['wgjs_js'];
- }
- }
- foreach($res as &$v){
- if(isset($list[$v['sczl_rq']][$v['bh']])){
- $v['计时']=$list[$v['sczl_rq']][$v['bh']];
- }else{
- $v['计时']='';
- }
- }
- $this->success('成功',$res);
- }
- /**
- * 获取计件工计时单信息
- * @ApiMethod (GET)
- * @param string $UniqId UniqId
- */
- public function getInfo()
- {
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (isset($req['UniqId']) && !empty($req['UniqId'])){
- $UniqId = $req['UniqId'];
- }else{
- $this->error('参数错误');
- }
- $rows = db()->table('db_wgjs')->alias('d')
- ->field('d.*, ')
- ->join('工单_基本资料 g', 'd.')
- ->where('d.UniqId',$UniqId)
- ->select();
- $this->success('成功',$rows);
- }
- /**
- * 定位
- * @ApiMethod GET
- */
- public function search(){
- if (Request::instance()->isGet() == false){
- $this->error('非法请求');
- }
- $req = Request::instance()->param();
- if (!isset($req['search']) || !isset($req['date'])){
- $this->error('参数错误');
- }
- $page = 1;
- $limit = 10;
- if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
- if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
- $year=substr($req['date'],0,4);
- $month=substr($req['date'],-2);
- if($month==12){
- $start_time=$year.'-12-01 00:00:00';
- $end_time=($year+1).'-01-01 00:00:00';
- }else{
- $start_time=$year.'-'.$month.'-01 00:00:00';
- $end_time=$year.'-'.($month+1).'-01 00:00:00';
- }
- $yg = db()->table('人事_基本资料')->where('员工姓名',$req['search'])->value('员工编号');
- if($yg){
- $req['search']=$yg;
- }
- $rows = db()->table('db_wgjs1')
- ->field('LEFT(wgjs_rq, 10) as wgjs_rq,
- wgjs_bh1,rs1.所在部门, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
- wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
- wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
- wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
- wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
- wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6,
- rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名)
- as name3,rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名)
- as name6')
- ->join('人事_基本资料 rs1','rs1.员工编号=db_wgjs1.wgjs_bh1','LEFT')
- ->join('人事_基本资料 rs2','rs2.员工编号=db_wgjs1.wgjs_bh2','LEFT')
- ->join('人事_基本资料 rs3','rs3.员工编号=db_wgjs1.wgjs_bh3','LEFT')
- ->join('人事_基本资料 rs4','rs4.员工编号=db_wgjs1.wgjs_bh4','LEFT')
- ->join('人事_基本资料 rs5','rs5.员工编号=db_wgjs1.wgjs_bh5','LEFT')
- ->join('人事_基本资料 rs6','rs6.员工编号=db_wgjs1.wgjs_bh6','LEFT')
- ->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'wgjs_bh1'=>$req['search']])
- ->select();
- $total = db()->table('db_wgjs1')->where(['wgjs_rq'=>['between',"$start_time,$end_time"],'wgjs_bh1'=>$req['search']])->count();
- $data = ['total'=> $total,'rows'=> $rows];
- if($rows){
- $this->success('成功',$data);
- }else{
- $this->error('失败');
- }
- }
- /**
- * 详情
- * @ApiMethod (GET)
- * @param string $wgjs_rq 日期
- * @param string $wgjs_bh1 员工编号
- */
- public function detail(){
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
- $this->error('参数错误');
- }else{
- }
- if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
- $this->error('参数不能为空');
- }
- $rows = db()->table('db_wgjs1')
- ->field('LEFT(wgjs_rq, 10) as wgjs_rq,
- wgjs_bh1, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
- wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
- wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
- wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
- wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
- wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6,
- rtrim(rs1.员工姓名) as name1,rtrim(rs2.员工姓名) as name2,rtrim(rs3.员工姓名)
- as name3,rtrim(rs4.员工姓名) as name4,rtrim(rs5.员工姓名) as name5,rtrim(rs6.员工姓名)
- as name6,wgjs_冲定额1,wgjs_冲定额2,wgjs_冲定额3,wgjs_冲定额4,wgjs_冲定额5,wgjs_冲定额6')
- ->join('人事_基本资料 rs1','rs1.员工编号=db_wgjs1.wgjs_bh1','LEFT')
- ->join('人事_基本资料 rs2','rs2.员工编号=db_wgjs1.wgjs_bh2','LEFT')
- ->join('人事_基本资料 rs3','rs3.员工编号=db_wgjs1.wgjs_bh3','LEFT')
- ->join('人事_基本资料 rs4','rs4.员工编号=db_wgjs1.wgjs_bh4','LEFT')
- ->join('人事_基本资料 rs5','rs5.员工编号=db_wgjs1.wgjs_bh5','LEFT')
- ->join('人事_基本资料 rs6','rs6.员工编号=db_wgjs1.wgjs_bh6','LEFT')
- ->where(['wgjs_rq'=>$req['wgjs_rq'].' 00:00:00','wgjs_bh1'=>$req['wgjs_bh1']])
- ->find();
- if($rows){
- $this->success('成功',$rows);
- }else{
- $this->error('失败');
- }
- }
- /**
- * 修改
- * @ApiMethod POST
- */
- public function edit()
- {
- if(!$this->request->isPost()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- // $req = ['wgjs_js1'=>12,'wgjs_rq'=>'2023-10-12','wgjs_bh1'=>'ZM01269'];
- if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
- $this->error('参数错误');
- }
- if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
- $this->error('参数不能为空');
- }
- $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
- $req['mod_rq'] = date('Y-m-d H:i:s');
- //开启事务
- db()->startTrans();
- try{
- $sql = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'],'wgjs_bh1'=>$req['wgjs_bh1']])
- ->fetchSql(true)->update($req);
- $res= db()->query($sql);
- // 提交事务
- db()->commit();
- } catch (\Exception $e) {
- // 回滚事务
- db()->rollback();
- $this->error($e->getMessage());
- }
- if($res===false) $this->error('失败');
- $this->success('成功');
- }
- /**
- * 新增
- * @ApiMethod POST
- */
- public function add()
- {
- if(!$this->request->isPost()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
- $this->error('参数错误');
- }
- if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
- $this->error('参数不能为空');
- }
- $req['wgjs_rq'] = $req['wgjs_rq'].' 00:00:00';
- $req['sys_rq'] = date('Y-m-d H:i:s');
- //开启事务
- db()->startTrans();
- try{
- $sql = db()->table('db_wgjs1')->fetchSql(true)->insert($req);
- $res= db()->query($sql);
- // 提交事务
- db()->commit();
- } catch (\Exception $e) {
- // 回滚事务
- db()->rollback();
- $this->error($e->getMessage());
- }
- if($res===false) $this->error('失败');
- $this->success('成功');
- }
- /**
- * 删除
- * @ApiMethod (GET)
- * @param string $wgjs_rq 日期
- * @param string $wgjs_bh1 员工编号
- */
- public function del(){
- //get请求
- if(!$this->request->isGet()){
- $this->error('请求方式错误');
- }
- $req = $this->request->param();
- if (!isset($req['wgjs_rq']) || !isset($req['wgjs_bh1']) ){
- $this->error('参数错误');
- }else{
- }
- if (empty($req['wgjs_rq']) || empty($req['wgjs_bh1'])){
- $this->error('参数不能为空');
- }
- $rows = db()->table('db_wgjs1')->where(['wgjs_rq'=>$req['wgjs_rq'].' 00:00:00','wgjs_bh1'=>$req['wgjs_bh1']])
- ->delete();
- if($rows){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- }
|