You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

332 lines
13 KiB
PHTML

5 years ago
<?php
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
use Base\Service\PromoteService as PromoteService;
5 years ago
/**
* 后台首页控制器
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
class MendController extends ThinkController {
public $tempid = 0;
5 years ago
public function lists($p=1){
$this->checkListOrCountAuthRestMap($map,[]);
5 years ago
$this->m_title = '推广补链';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'Mend/lists','status'=>1])->find());
$this->mendList();
5 years ago
}
public function mendList(){
if(isset($_REQUEST['account'])){
if ($_REQUEST['account']=='全部') {
unset($_REQUEST['account']);
}
$map['account']=array('like','%'.$_REQUEST['account'].'%');
unset($_REQUEST['account']);
}
$map['puid']=0;
$map['length(account)'] = array('gt', 0);
$map['register_time'] = array('gt', 0);
$p = I('p');
$map['register_type'] = array('in','(0,1,2,3,4,5,6,7)');
//为数据权限添加
setPowerPromoteIds($map);
$show_data_power = (is_administrator()|| session('user_auth')['show_data']);
$this->assign('show_data_power', $show_data_power);
5 years ago
parent::lists("user",$p,$map);
}
/**
* 补链记录
* @param integer $p 分页
5 years ago
* @param booble IS_POST post请求时为下一页ajax请求
* @param booble export 是否导出
* @return void
*/
5 years ago
public function recordList($p=1,$export=false)
5 years ago
{
$page = intval($p);
$page = $page ? $page : 1;
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
if(isset($_REQUEST['account'])) $map['user_account']=array('like','%'.$_REQUEST['account'].'%');
if(isset($_REQUEST['promote_account'])) $map['promote_account']=array('like','%'.$_REQUEST['promote_account'].'%');
if(isset($_REQUEST['promote_account_to'])) $map['promote_account_to']=array('like','%'.$_REQUEST['promote_account_to'].'%');
if(isset($_REQUEST['op_account'])) $map['op_account']=array('like','%'.$_REQUEST['op_account'].'%');
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
$map['order_time'] = ['between', [strtotime($_REQUEST['time_start']), strtotime($_REQUEST['time_end']) + 86399]];
} elseif (isset($_REQUEST['time_start'])) {
$map['order_time'] = ['GT', strtotime($_REQUEST['time_start'])];
} elseif (isset($_REQUEST['time_end'])) {
$map['order_time'] = ['LT', strtotime($_REQUEST['time_end']) + 86399];
5 years ago
}
$show_data_power = (is_administrator()|| session('user_auth')['show_data']);
//为数据权限添加
setPowerPromoteIds($map);
5 years ago
$data = M("Mend","tab_")
->field("user_account,promote_account,pay_amount,promote_account_to,order_time,create_time,op_account,remark")
->where($map)
5 years ago
->order("create_time desc");
if($export){
$data = $data->select();
}else{
$data = $data->page($page, $row)->select();
}
//格式化信息
foreach ($data as $key => $value) {
($data[$key]['promote_account']=='官方渠道')?($data[$key]['promote_account']=C('OFFICIEL_CHANNEL')):'';
$data[$key]['create_time'] = date("Y-m-d H:i:s",$value['create_time']);
$data[$key]['order_time'] = date("Y-m-d H:i:s",$value['order_time']);
if(!$show_data_power){
$data[$key]['user_account'] = encryptStr($data[$key]['user_account']);
}
}
5 years ago
if($export) db2csv($data,"推广员管理_推广补链_补链记录",["玩家账号","补链前渠道","补链前归属金额","补链后渠道","切分时间","补链时间","操作人员","备注"]);
5 years ago
if(IS_POST){
$page = set_pagination($_REQUEST['row_count'],$row);
$this->ajaxReturn(array(
"list_data"=>$data,
"page"=>$page
));
die();
}
$this->checkListOrCountAuthRestMap($map,[]);
$count = M("Mend","tab_")->where($map)->count();
$this->assign('row_count',$count);
$this->assign('list_data', $data);
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
5 years ago
$this->assign('show_data_power', $show_data_power);
$this->display();
// parent::lists("Mend",$p,$map);
5 years ago
}
5 years ago
5 years ago
public function edit($id = null)
{
if (IS_POST) {
$promoteService = new PromoteService();
5 years ago
if ($_POST['prmoote_id_to'] == -1){
$_POST['prmoote_id_to'] = 0;
}
if ($_POST['prmoote_id_to'] === ''){
$this->error('请选择需要变更的渠道');
}
if ($_POST['promote_id'] == $_POST['prmoote_id_to']) {
$this->error('没有变更数据');
}
if ($_POST['order_time'] == '') {
$this->error('没有订单日期');
}
//判断是否已经结算
// if(self::checkSettlement(strtotime($_POST['order_time']),$_POST['promote_id'])){
// $this->error('在订单日期内含有已经结算的订单,无法补链');
// }
// if(self::checkSpend(strtotime($_POST['order_time']),$_POST['account'])){
// $this->error("在订单日期内含有已经结算的订单,无法补链。");
// }
if(self::checkOrderTime(strtotime($_POST['order_time']))){
$this->error('仅能补链本周数据,请重新选择补链时间');
}
if(self::checkPromote(strtotime($_POST['order_time']),$_POST['account'])){
$this->error('在订单日期内含有多个推广员,无法补链');
}
5 years ago
$create = $_REQUEST;
$create['order_time'] = date($create['order_time']);
$params = array(
"from_promote_id"=>$create['promote_id'],
"to_promote_id"=>$create['prmoote_id_to'],
"order_time"=>$create['order_time'],
"type"=>2,
"shift_ids"=>[$create['user_id']],
"creator_type"=>0,
"creator_id"=>$_SESSION["onethink_admin"]["user_auth"]["uid"]
);
if(!empty($create['remark'])){
$params['remark'] = $create['remark'];
}
// dump($create);die();
$res = $promoteService->addShiftTask($params);
if($res['status']){
$userData = M('user','tab_')->field('account')->where(['id'=>$create['user_id']])->find();
$promoteToData = M('promote','tab_')->field('account')->where(['id'=>$create['prmoote_id_to']])->find();
$promoteFromData = M('promote','tab_')->field('account')->where(['id'=>$create['promote_id']])->find();
if ($create['promote_id'] == '0') {
$promoteFromData['account'] = '官方渠道';
}
addOperationLog(['op_type'=>1,'key'=>$userData['account'].'/'.$promoteFromData['account'].'/'.$promoteToData['account'],'op_name'=>'编辑推广补链','url'=>U('Mend/edit',['id'=>$create['user_id']]),'menu'=>'推广员-推广员管理-推广补链-编辑推广补链']);
$this->success('补链成功', U('lists'), 2);
5 years ago
}else{
$this->error($res['msg']);
5 years ago
}
} else {
5 years ago
// echo 1;die();
$map['id'] = $id;
$data = M("user","tab_")->where($map)->find();
// $user = A('User', 'Event');
// $user_data = $user->user_entity($id);
// $user_data || $this->error("用户数据异常");
5 years ago
// var_dump($user_data);die;
5 years ago
$this->assign("data", $data);
5 years ago
$this->meta_title = '编辑推广补链';
5 years ago
$this->m_title = '推广补链';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'Mend/lists','status'=>1])->find());
5 years ago
$this->display();
}
}
private function checkOrderTime($order_time){
$sdefaultDate = date("Y-m-d");
$first=1;//周一开始
$w=date('w',strtotime($sdefaultDate));
$checktime=strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days'); //本周开始时间
if($order_time >= $checktime){
//在本周允许换绑
return false;
}
return true;
}
/**
* 2020.1.3 之后判断订单是否已经结算
*/
private function checkSpend($order_time,$account){
//获取所有涉及订单
$map = array(
"pay_status"=>1,
"user_account"=>$account,
5 years ago
"payed_time"=>array("EGT",$order_time)
);
$spendlist = M("Spend","tab_")->field("id,selle_status,pay_order_number")->where($map)->select();
if(count($spendlist) < 1){
//无流水可换绑
return false;
}
5 years ago
//获取结算方式
$c_id = M("User","tab_")
5 years ago
->alias('a')
->field("IFNULL(p.company_id,0) company_id")
->join('tab_promote p ON a.promote_id= p.id')
->where("a.account = '{$account}'")
->find();
5 years ago
if(empty($c_id) || $c_id['company_id'] == 0){
//官方渠道不结算,可换绑
return false;
}
5 years ago
$c_id = $c_id['company_id'];
$r = M("CompanyRelation","tab_")->where("(first_company_type = 2 AND first_company_id = '{$c_id}') OR (second_company_type = 2 AND second_company_id = '{$c_id}')")->find();
if(empty($r) || $r['settlement_type'] == 0){
//不结算的公司允许换绑
return false;
}
5 years ago
$checktime = 0;
if($r['settlement_type'] == 1){
//周结
$sdefaultDate = date("Y-m-d");
$first=1;
$w=date('w',strtotime($sdefaultDate));
$checktime=strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days'); //本周开始时间
}else{
//月结
$y = date("Y", time()); //年
$m = date("m", time()); //月
$checktime = mktime(0, 0, 0, $m, 1, $y); // 本月开始时间
}
if($order_time >= $checktime){
//未在结算期内,允许换绑
return false;
}
5 years ago
//其他情况不允许换绑
return true;
}
/**
* 2020.1.3 之前判断订单是否已经结算
*/
private function checkSettlement($order_time,$prmote_id)
{
//判断是否已经结算,后台只会对会长进行结算
//获取会长信息
$Promote = M('promote','tab_');
$prmotedata = $Promote->field('chain')->find($prmote_id);
$chain = trim($prmotedata['chain'], '/');
if ($chain == '') {
$prmote_id = $prmote_id;
} else {
$prmote_id = explode('/', $chain)[0];
}
$jsres = M("Settlement","tab_")->where(array(
"total_money"=>array("GT",0),
"starttime"=>array("ELT",$order_time),
"endtime"=>array("EGT",$order_time),
"promote_id"=>$prmote_id
))->find();
if($jsres) return true;
return false;
}
//判断是否跨推广员进行补链
private function checkPromote($order_time,$account)
{
$res = M("Spend","tab_")->field("promote_id")->where(["pay_time"=>array("EGT",$order_time),"user_account"=>$account])->group("promote_id")->select();
if(count($res)>1) return true;
return false;
}
//补链详情
public function shiftInfo()
{
$id = I('id');
$info = M("shift_task")->where("id = {$id} and status = 0")->find();
if(empty($info)){
$this->error("补链不存在或已处理");
}
5 years ago
$info['user_id'] = json_decode($info['shift_ids'])[0];
$info['order_time'] = date("Y-m-d",$info['order_time']);
$userid = $info['user_id'];
$info['account'] = M("User","tab_")->field("account")->where("id = '{$userid}'")->find()['account'];
$this->assign('data',$info);
$this->display();
}
//取消补链
public function cancelShift()
{
$id = I('id');
$status = M('ShiftTask')->where(['id' => $id,'status' => 0])->save(['status' => 2]);
if ($status) {
addOperationLog(['op_type'=>1,'key'=>$id,'op_name'=>'取消补链','url'=>U('Mend/shiftInfo',['id'=>$id]),'menu'=>'推广员-推广员管理-推广补链-取消补链']);
$this->ajaxReturn(array("status"=>1,"url"=> U('lists')));
} else {
$this->ajaxReturn(array("status"=>0,"url"=> U('lists')));
}
}
5 years ago
}