*/ class BusinessAffairsAwardController extends ThinkController { private $model; public function _initialize() { $this->model = M("business_affairs_award","tab_"); parent::_initialize(); } /** *商务奖金比例列表 */ public function lists() { $params = I('get.'); $page = $params['p'] ? intval($params['p']) : 1; $row = $params['row'] ? intval($params['row']) : 10; $data = $this->model->page($page, $row)->select(); foreach ($data as $key => $value) { if($value['end_amount'] == '0') { $data[$key]['end_amount'] = '永久'; } } if(IS_ROOT){ $this->assign('add_check',true); }else { $exportRule = strtolower(MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME . "_add_check"); $this->assign('add_check', $this->checkRule($exportRule, array('in', '1,2'))); } $count = $this->model->where("1=1")->count(); $page = set_pagination($count, $row,$params); if($page) { $this->assign('_page', $page); } $this->assign("list",$data); $this->display(); } public function add() { if(IS_POST) { if (!$_POST['ratio']) { $this->ajaxReturn(["msg"=>"请填写抽成比例","code"=>0]); } if(!$_POST['start_amount'] && $_POST['start_amount']!='0') { $this->ajaxReturn(["msg"=>"请填写起始流水","code"=>0]); } if($_POST['start_amount'] >= $_POST['end_amount']&&$_POST['end_amount']) { $this->ajaxReturn(["msg"=>"起始流水必须小于结束流水","code"=>0]); } $amount_start = $_POST['start_amount']; $amount_end = $_POST['end_amount']; $busunessData = M("business_affairs_award", "tab_") ->where("((start_amount<{$amount_start} and (end_amount >{$amount_start} or end_amount=0)) or (start_amount<{$amount_end} and (end_amount >={$amount_end} or end_amount=0)) or ((end_amount>{$amount_start} or end_amount=0) and (end_amount <={$amount_end} and end_amount!=0)))") ->select(); if ($busunessData) { $this->ajaxReturn(["msg"=>"流水段已经存在","code"=>0]); } $add_data = $_POST; $add_data['create_time'] = time(); !$add_data['end_amount']?($add_data['end_amount']=0):''; $this->model->add($add_data); $this->ajaxReturn(["msg"=>"添加成功","code"=>1,"url"=>U("lists")]); } else { $this->display(); } } public function edit() { $id = $_REQUEST["id"]; if(IS_POST) { if (!$_POST['ratio']) { $this->ajaxReturn(["msg"=>"请填写抽成比例","code"=>0]); } if(!$_POST['start_amount'] && $_POST['start_amount']!='0') { $this->ajaxReturn(["msg"=>"请填写起始流水","code"=>0]); } if($_POST['start_amount'] >= $_POST['end_amount']&&$_POST['end_amount']) { $this->ajaxReturn(["msg"=>"起始流水必须小于结束流水","code"=>0]); } $amount_start = $_POST['start_amount']; $amount_end = $_POST['end_amount']; $busunessData = M("business_affairs_award", "tab_") ->where("id != {$id} and ((start_amount<{$amount_start} and (end_amount >{$amount_start} or end_amount=0)) or (start_amount<{$amount_end} and (end_amount >={$amount_end} or end_amount=0)) or ((end_amount>{$amount_start} or end_amount=0) and (end_amount <={$amount_end} and end_amount!=0)))") ->select(); if ($busunessData) { $this->ajaxReturn(["msg"=>"流水段已经存在","code"=>0]); } $add_data = $_POST; $add_data['update_time'] = time(); !$add_data['end_amount']?($add_data['end_amount']=0):''; $this->model->where(['id'=>$id])->save($add_data); $this->ajaxReturn(["msg"=>"修改成功","code"=>1,"url"=>U("lists")]); } else { $data = $this->model->where(['id'=>$id])->find(); $data['start_amount'] = round($data['start_amount'],2); $data['end_amount'] = round($data['end_amount'],2); $this->assign("data",$data); $this->display(); } } public function del() { if(!isset($_REQUEST['id'])){ $this->error('参数错误'); } $id = $_REQUEST['id']; $res = $this->model->where("id='{$id}'")->delete(); if($res !== false){ $this->success('删除成功',U("lists")); }else{ $this->error('删除错误'); } } public function businessAffairsList() { $check_quarter = ["03","06","09","12"]; $map = []; $params = I('get.'); $page = $params['p'] ? intval($params['p']) : 1; $row = $params['row'] ? intval($params['row']) : 10; if($_REQUEST['time']) { $map['time'] = $_REQUEST['time']; } if ($_REQUEST['game_belong_name']) { $map['game_belong_name'] = ['like',"%{$_REQUEST['game_belong_name']}%"]; } if ($_REQUEST['relation_game_name']) { $map['relation_game_name'] = ['like',"%{$_REQUEST['game_name']}%"]; } if ($_REQUEST['verify_status'] || $_REQUEST['verify_status'] == '0') { $map['verify_status'] = ['like',"%{$_REQUEST['verify_status']}%"]; } $query = M("business_affairs_award_pool","tab_") ->where($map); if (!$_REQUEST['export']) { $query->page($page, $row); } $data = $query->order("time desc")->select(); foreach ($data as $key => $value) { $detail = '未审核'; if ($value['verify_status'] == 1) { $detail = '审批通过'; } elseif($value['verify_status'] == 2) { $detail = '审批拒绝'; } if($_REQUEST['export']) { $data[$key]['time'] = '`'.$value['time']; $detail .= "\n"; }else { $detail .= "
"; } if ($value['verify_status']) { $data[$key]['verify_detail'] = $detail.date('Y-m-d H:i:s',$value['verify_time']); } else { $data[$key]['verify_detail'] = '未审核'; } $data[$key]['ratio'] = round(($value['month_award']/$value['pay_amount']*100),2)."%"; $data[$key]['game_assistant_name'] = $value['game_assistant_name'] == '' ? '无' : $value['game_assistant_name']; } if ($_REQUEST['export']) { $title = [ 'time' => '时间', 'game_belong_name' => '对应商务', 'relation_game_name' => '产品', 'pay_amount' => '流水', 'game_bonus_pool' => '该产品奖金池', 'month_award'=>'商务个人本月应得', 'game_assistant_name' => '助理', 'assistant_month_award' => '助理本月应得', 'department_award' => '部门累计', 'person_award' => '个人激励', 'verify_detail' => '审批状态' ]; data2csv($data, '商务奖金汇总', $title); } $count = M("business_affairs_award_pool","tab_") ->where($map) ->count(); $gameBonusPool = M("business_affairs_award_pool","tab_") ->where($map) ->sum('game_bonus_pool'); if(IS_ROOT){ $this->assign('verify_check',true); $this->assign('caculate_check',true); }else { $exportRule = strtolower(MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME . "_verify_check"); $caculate_check = strtolower(MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME . "_caculate_check"); $this->assign('verify_check', $this->checkRule($exportRule, array('in', '1,2'))); $this->assign('caculate_check', $this->checkRule($caculate_check, array('in', '1,2'))); } $page = set_pagination($count, $row,$params); if($page) { $this->assign('_page', $page); } $this->assign("list",$data); $this->assign("gameBonusPool", round(floatval($gameBonusPool), 2)); $this->display(); } public function verify() { $status = $_REQUEST['status']; $ids = $_REQUEST['ids']; if ($ids) { $is_save = M("business_affairs_award_pool","tab_") ->where(['id'=>['in',$ids]]) ->save(['verify_status'=>$status,'verify_time'=>time()]); if($is_save) { $this->ajaxReturn(['status'=>1,'info'=>'操作成功']); } else { $this->ajaxReturn(['status'=>0,'info'=>'操作失败']); } } else { $this->ajaxReturn(['status'=>0,'info'=>'数据错误']); } } public function reCaculate() { exec("source /etc/profile;cd " . ROOTTT . ";php " . SUBSITE_INDEX . " timing/setbusinessAffairsAward > /dev/null &"); $this->ajaxReturn(['status' => 1]); } }