From 22399fe20490bbaf822d60bfc5f7e3818c5d4094 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Thu, 11 Mar 2021 15:46:35 +0800 Subject: [PATCH] 20201112 --- application/api/controller/Staff.php | 430 +++++++++++++++++++-------- application/common.php | 38 ++- 2 files changed, 341 insertions(+), 127 deletions(-) diff --git a/application/api/controller/Staff.php b/application/api/controller/Staff.php index b879017..7608c47 100644 --- a/application/api/controller/Staff.php +++ b/application/api/controller/Staff.php @@ -1,10 +1,14 @@ staff_to_journal_obj = Db::name('staff_to_journal'); } + public function mytest(){ + $url = self::JURL; + $param = []; + $param['issn'] = '2413-3973'; + $res = json_decode(myPost($url,$param)); + echo '
';
+        var_dump($res->data->cites);
+        echo '
'; + die; + } + + /** * 添加工资level */ - public function addStaffLevel(){ + public function addStaffLevel() { $data = $this->request->post(); $insert['title'] = $data['title']; $insert['wages'] = $data['wages']; $this->staff_level_obj->insert($insert); return jsonSuccess([]); } - + /** * 删除工资level */ - public function delStaffLevel(){ + public function delStaffLevel() { $data = $this->request->post(); - $this->staff_level_obj->where('staff_level_id',$data['staff_level_id'])->update(['state'=>1]); + $this->staff_level_obj->where('staff_level_id', $data['staff_level_id'])->update(['state' => 1]); return jsonSuccess([]); } - + /** * 编辑工资level */ - public function editStaffLevel(){ + public function editStaffLevel() { $data = $this->request->post(); $update['title'] = $data['title']; $update['wages'] = $data['wages']; - $this->staff_level_obj->where('staff_level_id',$data['staff_level_id'])->update($update); + $this->staff_level_obj->where('staff_level_id', $data['staff_level_id'])->update($update); return jsonSuccess([]); } - + /** * 获取工资levels */ - public function getStaffLevels(){ - $list = $this->staff_level_obj->where('state',0)->select(); - + public function getStaffLevels() { + $list = $this->staff_level_obj->where('state', 0)->select(); + $re['levels'] = $list; - + return jsonSuccess($re); } - + /** * 添加员工 */ - public function addStaff(){ + public function addStaff() { $data = $this->request->post(); -// $data['staff_level_id'] = '3'; -// $data['addition'] = '1'; -// $data['addition_reason'] = ''; -// $data['subtraction'] = ''; -// $data['subtraction_reason'] = ''; -// $data['name'] = '1'; -// $data['phone'] = '1'; -// $data['email'] = '1'; -// $data['password'] = '1'; $insert['staff_level_id'] = $data['staff_level_id']; $insert['name'] = $data['name']; $insert['phone'] = $data['phone']; $insert['email'] = $data['email']; + $insert['ident'] = $data['ident']; + $insert['bank'] = $data['bank']; $insert['password'] = md5($data['password']); $insert['add_price'] = $data['add_price']; $insert['add_reason'] = $data['add_reason']; @@ -111,16 +120,16 @@ class Staff extends Controller{ $this->staff_obj->insert($insert); return jsonSuccess([]); } - + /** * 删除员工 */ public function delStaff() { $data = $this->request->post(); - $this->staff_obj->where('staff_id',$data['staff_id'])->update(['state'=>1]); + $this->staff_obj->where('staff_id', $data['staff_id'])->update(['state' => 1]); return jsonSuccess([]); } - + /** * 更新员工信息 */ @@ -130,148 +139,317 @@ class Staff extends Controller{ $update['name'] = $data['name']; $update['phone'] = $data['phone']; $update['email'] = $data['email']; - $update['password'] = md5($data['password']); + $update['ident'] = $data['ident']; + $update['bank'] = $data['bank']; $update['add_price'] = $data['add_price']; $update['add_reason'] = $data['add_reason']; $update['sub_price'] = $data['sub_price']; $update['sub_reason'] = $data['sub_reason']; - $this->staff_obj->where('staff_id',$data['staff_id'])->update($update); + $this->staff_obj->where('staff_id', $data['staff_id'])->update($update); return jsonSuccess([]); } - + /** * 获取员工列表 */ - public function getStaffs(){ + public function getStaffs() { $data = $this->request->post(); $limit_start = ($data['pageIndex'] - 1) * $data['pageSize']; $list = $this->staff_obj->field('t_staff.*,t_staff_level.*') - ->join('t_staff_level','t_staff_level.staff_level_id = t_staff.staff_level_id','left') - ->where('t_staff.state',0) - ->limit($limit_start,$data['pageSize']) + ->join('t_staff_level', 't_staff_level.staff_level_id = t_staff.staff_level_id', 'left') + ->where('t_staff.state', 0) + ->order('staff_id') + ->limit($limit_start, $data['pageSize']) ->select(); - $count = $this->staff_obj->where('state',0)->count(); + $count = $this->staff_obj->where('state', 0)->count(); $re['staffs'] = $list; $re['count'] = $count; return jsonSuccess($re); } + + /** + * 获取全部员工 + */ + public function getAllStaffs() { + $list = $this->staff_obj->where('state', 0)->select(); + $re['staffs'] = $list; + return jsonSuccess($re); + } + + /** + * 获取全部期刊 + */ + public function getJournals() { + $list = $this->journal_obj + ->field('t_journal.*,t_staff.name staff_name') + ->join('t_staff', 't_journal.staff_id = t_staff.staff_id', 'left') + ->where('t_journal.state', 0) + ->select(); + + $re['journals'] = $list; + return jsonSuccess($re); + } + + /** + * 更改期刊提成对接人与稿件数量与期刊基础工资 + */ + public function editJournalStaff() { + $data = $this->request->post(); + $this->journal_obj + ->where('journal_id', $data['journal_id']) + ->update(['staff_id' => $data['staff_id'], 'jour_num' => $data['jour_num'],'jour_price'=>$data['jour_price']]); + return jsonSuccess([]); + } + + /** + * 获取员工实时工资(员工用) + */ + public function getStaffRealtime() { + $data = $this->request->post(); + $res = $this->getTomonthPrice($data['name'], date('Ym')); + if ($res == 'error') { + return jsonError($res); + } else { + return jsonSuccess($res); + } + } + + /** + * 核算月薪,记录进log(系统自动调用) + */ + public function pushStaffLog() { + $staff_list = $this->staff_obj->where('state', 0)->select(); +// $where['state'] = 0; + $c_time = strtotime("-1 month", strtotime(date('Y-m') . '-26 00:00:00')); + $c_time1 = strtotime(date('Y-m' . '-25 23:59:59')); + $where['ctime'] = array(['>', $c_time], ['<=', $c_time1]); + foreach ($staff_list as $value) { + $base_price = $this->getBasePrice($value['name']); + $journals = $this->journal_obj->where('staff_id', $value['staff_id'])->select(); + $journal_price = 0; + $cite_price = 0; + foreach ($journals as $v) { + $c_price = 0; +// $where['journal_id'] = $v['journal_id']; + $where['accept_sn'] = ['like',$v['abbr'].'%']; + $cache_articles = $this->article_obj->where($where)->select(); + $c_gn = 0; + $c_gw = 0; + foreach ($cache_articles as $vv) { + $c_country = $this->article_author_obj->where('article_id', $vv['article_id'])->where('state', 0)->column('country'); + $c_c = 'gn'; + foreach ($c_country as $vvv) { + if ($vvv != 'China' && $vvv != '') { + $c_c = 'gw'; + } + } + if ($c_c == 'gn') { + $c_gn++; + } else { + $c_gw++; + } + } + if ($c_gn - $v['jour_num'] >= 0) { + $c_price = ($c_gn - $v['jour_num']) * 100 + $c_gw * 200; + } else { + if (($c_gw - ($v['jour_num'] - $c_gn)) >= 0) { + $c_price = ($c_gn + $c_gw - $v['jour_num']) * 200; + } else { + $c_price = 0 - ($v['jour_num'] - $c_gn - $c_gw) * 50; + } + } + $journal_price += $c_price; + //获取cite提成 + $jcites = json_decode(myPost(self::JURL,['issn'=>$v['issn']])); + $jcs = $jcites->data->cites; + $cite_price += count($jcs)*500; + } + //添加数据 + $ccc = $this->staff_log_obj->where('staff_id',$value['staff_id'])->where('date', date('Ym'))->find(); + if($ccc==null){ + $insert['staff_id'] = $value['staff_id']; + $insert['date'] = date('Ym'); + $insert['base_price'] = $base_price; + $insert['journal_price'] = $journal_price; + $insert['cite_price'] = $cite_price; + $this->staff_log_obj->insert($insert); + } + } + echo 'finshed'; + } + + + /** + * 获取员工工资信息列表(管理员用) + */ + public function getAllStaff() { +// $data = $this->request->post(); + $data['pageIndex'] = 1; + $data['pageSize'] = 100; + $data['date'] = '202103'; + + $limit_start = ($data['pageIndex'] - 1) * $data['pageSize']; + $staff_list = $this->staff_obj->where('state', 0)->limit($limit_start, $data['pageSize'])->select(); + $count = $this->staff_obj->where('state', 0)->count(); + foreach ($staff_list as $k => $v) { + $ca = $this->getTomonthPrice($v['name'], $data['date']); + $staff_list[$k]['pp'] = $ca; + } + $re['staffs'] = $staff_list; + $re['count'] = $count; + return jsonSuccess($re); + } /** - * 获取全部期刊 + * 修改工资详情 */ - public function getJournals(){ - $list = $this->journal_obj->where('state',0)->select(); - - $re['journals'] = $list; - return jsonSuccess($re); - } - - /** - * 更改期刊提成对接人 - */ - public function editJournalStaff(){ + public function editStaffLog(){ $data = $this->request->post(); - $this->journal_obj->where('journal_id',$data['journal_id'])->update(['staff_id'=>$data['staff_id']]); + $update['add_price'] = $data['add_price']; + $update['add_reason'] = $data['add_reason']; + $update['sub_price'] = $data['sub_price']; + $update['sub_reason'] = $data['sub_reason']; + $this->staff_log_obj->where('staff_log_id',$data['staff_log_id'])->update($update); return jsonSuccess([]); } - - /** - * 获取员工实时工资 - */ - public function getStaffRealtime(){ - $data = $this->request->post(); - $staff_info = $this->staff_obj->where('name',$data['name'])->find(); - $price = $this->getBasePrice($data['name']); - - //获取实时期刊提成情况 - $journals = $this->journal_obj->where('staff_id',$staff_info['staff_id'])->column('journal_id'); - $where['journal'] = array('in',$journals); - if(date('d')>25){ - $ch_time = strtotime(date('Y-m').'-26 00:00:00'); - $where['ctime'] = array('>',$ch_time); - }else{ - $c_time = strtotime("-1 month", strtotime(date('Y-m').'-26 00:00:00')); - $c_time1 = strtotime(date('Y-m'.'-25 23:59:59')); - $where['ctime'] = array(['>',$c_time],['<=',$c_time1]); - } - $where['state'] = 0; - $list = $this->article_obj->where($where)->select(); - - - echo '
';
-        var_dump($list);
-        echo '
'; - die; - - - $re['price'] = $price; - return jsonSuccess($re); - } - - - /** - * 核算月薪,记录进log(系统自动调用) - */ - public function pushStaffLog(){ - - - - } - - /** - * 获取员工工资信息列表(管理员专用) - */ - public function getAllStaff($month = '0'){ - if($month=='0'){//获取当月实时工资 - - }else{//获取其他月份工资log - - } - } - + /** * 获取用户某月份工资详情 */ - public function getStaffLog(){ + public function getStaffLog() { $data = $this->request->post(); - $staff_info = $this->staff_obj->where('name',$data['name'])->find(); + $staff_info = $this->staff_obj->where('name', $data['name'])->find(); $staff_log_obj = $this->staff_log_obj - ->where('staff_id',$staff_info['staff_id']) - ->where('date',$data['date']) - ->where('state',0) + ->where('staff_id', $staff_info['staff_id']) + ->where('date', $data['date']) + ->where('state', 0) ->find(); $re['staffLog'] = $staff_log_obj; return jsonSuccess($re); } - + /** - * 获取员工工资查询 + * 检测员工查询 */ - public function checkStaffLogin(){ + public function checkStaffLogin() { $data = $this->request->post(); $where['name'] = $data['name']; $where['password'] = md5($data['password']); $where['state'] = 0; $res = $this->staff_obj->where($where)->find(); - if($res){ - return jsonSuccess(['info'=>$res]); - }else{ + if ($res) { + return jsonSuccess(['info' => $res]); + } else { return jsonError('check error'); } } - - private function getBasePrice($name){ - $staff_info = $this->staff_obj->where('name',$name)->where('state',0)->find(); - $level_info = $this->staff_level_obj->where('staff_level_id',$staff_info['staff_level_id'])->where('state',0)->find(); - //获取基本薪资 - $price1 = $level_info['wages']+$staff_info['add_price']-$staff_info['sub_price']; - - //获取稿件提成信息 - $price2 = 0; - - //返回基础工资 - return $price1 +$price2; + + /** + * 获取某月某员工工资 + * @return type + */ + private function getTomonthPrice($name, $date) { + $staff_info = $this->staff_obj->where('name', $name)->where('state',0)->find(); + $baseprice = $this->getBasePrice($name); + + if ($date != date('Ym')) { + $log_res = $this->staff_log_obj->where('staff_id', $staff_info['staff_id'])->where('date', $date)->where('state', 0)->find(); + if ($log_res) { + $re['baseprice'] = $log_res['base_price']; + $re['journalprice'] = $log_res['journal_price']; + $re['citeprice'] = $log_res['cite_price']; + $re['add_price'] = $log_res['add_price']; + $re['sub_price'] = $log_res['sub_price']; + return $re; + } else { + return 'error'; + } + } + + //获取实时期刊提成情况 + if (date('d') > 25) { +// $ch_time = strtotime(date('Y-m').'-26 00:00:00'); +// $where['ctime'] = array('>',$ch_time); + //返回log数据 + $log_res = $this->staff_log_obj->where('staff_id', $staff_info['staff_id'])->where('date', date('Ym'))->where('state', 0)->find(); + if ($log_res) { + $re['staff_log_id'] = $log_res['staff_log_id']; + $re['baseprice'] = $log_res['base_price']; + $re['journalprice'] = $log_res['journal_price']; + $re['citeprice'] = $log_res['cite_price']; + $re['add_price'] = $log_res['add_price']; + $re['sub_price'] = $log_res['sub_price']; + return $re; + } else { + return 'error'; + } + } else { + $c_time = strtotime("-1 month", strtotime(date('Y-m') . '-26 00:00:00')); + $c_time1 = strtotime(date('Y-m' . '-25 23:59:59')); + $where['ctime'] = array(['>', $c_time], ['<=', $c_time1]); + } + $journals = $this->journal_obj->where('staff_id', $staff_info['staff_id'])->select(); + $journal_price = 0; + $cite_price = 0; + foreach ($journals as $v) { + $c_price = 0; + $where['accept_sn'] = ['like',$v['abbr'].'%']; + $cache_articles = $this->article_obj->where($where)->select(); + $c_gn = 0; + $c_gw = 0; + foreach ($cache_articles as $vv) { + $c_country = $this->article_author_obj->where('article_id', $vv['article_id'])->where('state', 0)->column('country'); + $c_c = 'gn'; + foreach ($c_country as $vvv) { + if ($vvv != 'China' && $vvv != '') { + $c_c = 'gw'; + } + } + if ($c_c == 'gn') { + $c_gn++; + } else { + $c_gw++; + } + } + if ($c_gn - $v['jour_num'] >= 0) { + $c_price = ($c_gn - $v['jour_num']) * 100 + $c_gw * 200; + } else { + if (($c_gw - ($v['jour_num'] - $c_gn)) >= 0) { + $c_price = ($c_gn + $c_gw - $v['jour_num']) * 200; + } else { + $c_price = 0 - ($v['jour_num'] - $c_gn - $c_gw) * 50; + } + } + $journal_price += $c_price; + + //获取cite提成 + $jcites = json_decode(myPost(self::JURL,['issn'=>$v['issn']])); + $jcs = $jcites->data->cites; + $cite_price += count($jcs)*500; + } + $re['staff_log_id'] = 0; + $re['baseprice'] = $baseprice; + $re['journalprice'] = $journal_price; + $re['citeprice'] = $cite_price; + $re['add_price'] = 0; + $re['sub_price'] = 0; + return $re; } + private function getBasePrice($name) { + $staff_info = $this->staff_obj->where('name', $name)->where('state', 0)->find(); +// $level_info = $this->staff_level_obj->where('staff_level_id', $staff_info['staff_level_id'])->where('state', 0)->find(); + + $wag = $this->journal_obj->where('staff_id',$staff_info['staff_id'])->where('state',0)->sum('jour_price'); + + //获取基本薪资 + $price1 = $wag + $staff_info['add_price'] - $staff_info['sub_price']; + + //获取稿件提成信息 + $price2 = 0; + + //返回基础工资 + return $price1 + $price2; + } } diff --git a/application/common.php b/application/common.php index 8fe288e..501d3f7 100644 --- a/application/common.php +++ b/application/common.php @@ -139,4 +139,40 @@ function jsonSuccess($data){ function jsonError($msg){ return json(['code'=>1,'msg'=>$msg]); -} \ No newline at end of file +} + +function myPost($url, $param=array()){ + + if(!is_array($param)){ + + throw new Exception("参数必须为array"); + + } + + $httph =curl_init($url); + +// curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0); + +// curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1); + + curl_setopt($httph,CURLOPT_RETURNTRANSFER,1); + + curl_setopt($httph, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); + + curl_setopt($httph, CURLOPT_POST, 1);//设置为POST方式 + + curl_setopt($httph, CURLOPT_POSTFIELDS, $param); + +// curl_setopt($httph, CURLOPT_RETURNTRANSFER,0); + +// curl_setopt($httph, CURLOPT_HEADER,1); + + $rst=curl_exec($httph); + + curl_close($httph); + + return $rst; + + } + +