// +----------------------------------------------------------------------
namespace Home\Controller;
use OT\DataDictionary;
use function Sodium\add;
use User\Api\PromoteApi;
use User\Api\UserApi;
use Org\WeixinSDK\Weixin;
use Org\JubaobarSDK\Jubaobar;
use Org\JtpaySDK\Jtpay;
use Org\HeepaySDK\HeepaySDK;
use Org\GoldPig\GoldPig;
use Org\SwiftpassSDK\Swiftpass;
use Com\Wechat;
use Com\WechatAuth;
use Home\Model\UserPlayModel;
use Home\Model\PromoteModel;
use Base\Service\PromoteService;
use Base\Service\ApplyService;
/**
* 前台首页控制器
* 主要获取首页聚合数据
*/
class PromoteController extends BaseController
{
//系统首页
public function index($p=1)
{
header("Content-type:text/html;charset=utf-8");
$user = D('Promote')->isLogin();
if (empty($user)) {
$this->redirect("Home/Index/index");
}
$quick_menu_list = M("quick_menu qmn","tab_")
->join("tab_promote_quick_menu as pqmn on qmn.id=pqmn.quick_menu_id and promote_id=".get_pid())
->field("qmn.*")
->where("qmn.status=0")
->order("create_time desc")
->limit("0,10")
->select();
$game_list = M("game","tab_")->field("id,game_name")->order("id desc")->select();
$gg_list = M("document","sys_")->limit('0,5')->where("category_id=56 and status=1")->order("update_time desc")->select(); //游戏公告
$zx_list = M("document","sys_")->limit('0,5')->where("category_id=51 and status=1")->order("update_time desc")->select(); //游戏咨询
$xx_list = null;
$today_start = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$today_end = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
$today_open_server_list = M("server as sv","tab_")->where(
array("sv.start_time"=>array("BETWEEN", array($today_start, $today_end)),
"sv.show_status"=>1))
->join("left join tab_game gm on gm.id=sv.game_id")
->field('sv.*,gm.icon')
->order("sv.start_time desc")
//->page(1, 20)
->select();
$user_count = M("user","tab_")->where("promote_id=".get_pid())->count();
$total_money = $this->pay_total(0,0);
$today_add_user_money = $this->pay_total(1);
$month_add_user_money = $this->pay_total(3);
$yesterday_start = mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'));
$yesterday_end = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$yesterday_user_regist_count = M("user","tab_")->where(
array("promote_id"=>get_pid(),
"register_time"=>array("BETWEEN", array($yesterday_start, $yesterday_end))))
->count();
$yesterday_total_money = $this->pay_total(5,0);
$yesterday_regist_user_count = M("user","tab_")
->where(array("promote_id"=>get_pid(),
"register_time"=>array("BETWEEN", array($yesterday_start, $yesterday_end))))
->count();
$yesterday_total_money = $this->pay_total(1,0);
$this->assign("user_count",$user_count);
$this->assign("total_money", $total_money);
$this->assign("today_add_user_money", $today_add_user_money);
$this->assign("month_add_user_money", $month_add_user_money);
$this->assign("yesterday_user_regist_count",$yesterday_user_regist_count);
$this->assign("yesterday_total_money",$yesterday_total_money);
$this->assign("yesterday_regist_user_count",$yesterday_regist_user_count);
$this->assign("yesterday_total_money",$yesterday_total_money);
$this->assign("menu_list", $quick_menu_list);
$this->assign("gg_list", $gg_list);
$this->assign("zx_list", $zx_list);
$this->assign("xx_list", $xx_list);
$this->assign("today_open_server_list", $today_open_server_list);
$this->assign("game_list",$game_list);
$this->meta_title = "首页";
$this->display();
}
private function pay_total($type=0,$newadd=1)
{
if ($_REQUEST['promote_id'] === null || $_REQUEST['promote_id'] === '0') {
$map['parent_id'] = get_pid();
$map['grand_id'] = get_pid();
$map['_logic'] = 'or';
$ids = M('Promote', 'tab_')->where($map)->getfield("id", true);
if (empty($ids)) {
$ids = array(get_pid());
}
array_unshift($ids, get_pid());
} else {
$ids = array($_REQUEST['promote_id']);
}
$where['spend.promote_id'] = array('in', $ids);
$where['spend.pay_status'] = 1;
$where['spend.is_check'] = array('NEQ', 2);
switch ($type) {
case 1: { // 今天
$start = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$end = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
};
break;
case 3: {
// 本月
$start = mktime(0, 0, 0, date('m'), 1, date('Y'));
$end = mktime(0, 0, 0, date('m') + 1, 1, date('Y')) - 1;
};
break;
case 4: {
// 本年
$start = mktime(0, 0, 0, 1, 1, date('Y'));
$end = mktime(0, 0, 0, 1, 1, date('Y') + 1) - 1;
};
break;
case 5: { // 昨天
$start = mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'));
$end = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
};
break;
case 6:{
$start = mktime(0,0,0,date('m')-1,1,date('Y'));
$end = mktime(0,0,0,date('m'),1,date('Y'))-1;
};break;
case 9: { // 前七天
$start = mktime(0, 0, 0, date('m'), date('d') - 6, date('Y'));
$end = mktime(date('H'), date('m'), date('s'), date('m'), date('d'), date('Y'));
};
break;
default:
;
}
if (isset($start) && isset($end)) {
$where['spend.pay_time'] = array("BETWEEN", array($start, $end));
if($newadd==1){
$where['user.register_time'] = array("BETWEEN", array($start, $end));
}
}
if($newadd==1){
$total = M('spend as spend', "tab_")->field("SUM(spend.pay_amount) as amount")->join("right join tab_user user on user.id=spend.user_id")->where($where)->select();
}else{
$total = M('spend as spend', "tab_")->field("SUM(spend.pay_amount) as amount")->where($where)->select();
}
$total = $this->huanwei($total[0]['amount']);
return $total;
}
private function huanwei($total)
{
$total = empty($total) ? '0' : trim($total . ' ');
$len = strlen($total) - 3;
if ($len > 16) {
// 兆
$len = $len - 20;
$total = $len > 0 ? ($len > 4 ? ($len > 8 ? round(($total / 1e28), 4) . '万亿兆' : round(($total / 1e24), 4) . '亿兆') : round(($total / 1e20), 4) . '万兆') : round(($total / 1e16), 4) . '兆';
} else if ($len > 8) {
// 亿
$len = $len - 12;
$total = $len > 0 ? (round(($total / 1e12), 4) . '万亿') : round(($total / 1e8), 4) . '亿';
} else if ($len > 4) {
// 万
$total = (round(($total / 10000), 4)) . '万';
}
return $total;
}
public function home_read_data(){
$type = I("type","0");
$game_id = I("game_id");
$start = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$end = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
if($game_id){
$map['game_id'] = $game_id;
}
if($type>0){
$map['sv.start_time']=array("GT", $end);
}else{
$map['sv.start_time']=array("BETWEEN", array($start, $end));
}
$map['sv.show_status'] = 1;
$open_server_list = M("server as sv","tab_")->where($map)
->join("left join tab_game gm on gm.id=sv.game_id")
->field('sv.*,gm.icon')
->order("sv.start_time desc")
//->page(1, 20)
->select();;
foreach ($open_server_list as $key => $server){
$open_server_list[$key]['icon']=get_cover($server['icon'],'path');
if($server['pay_type']==1){
$open_server_list[$key]['pay_type']='安卓';
}elseif ($server['pay_type']==1){
$open_server_list[$key]['pay_type']='iOS';
}else{
$open_server_list[$key]['pay_type']='安卓、iOS';
}
$open_server_list[$key]['pay_type'];
$open_server_list[$key]['start_time'] = date('Y-m-s h:i',$server['start_time']);
}
$this->ajaxReturn(['status'=>1,'info'=>'调用成功','data'=>$open_server_list],"JSON");
}
public function quick_menu_list(){
$data_list = M("quick_menu qmn","tab_")
->join("left join tab_promote_quick_menu as pqmn on qmn.id=pqmn.quick_menu_id and promote_id=".get_pid())
->field("qmn.*,pqmn.id as exist_id")
->where("qmn.status=0")
->order("qmn.id asc")
->select();
$this->assign("data_list",$data_list);
$this->meta_title = "快捷菜单";
$this->display();
}
public function quick_menu_set(){
$menu_id = I("menu_id");
$info = M("promote_quick_menu ","tab_")
->where(
array("quick_menu_id"=>$menu_id,
"promote_id"=>get_pid())
)
->find();
if($info){
M("promote_quick_menu ","tab_")->where(
array("quick_menu_id"=>$menu_id,
"promote_id"=>get_pid())
)->delete();
$this->ajaxReturn(['status'=>1,'info'=>'移除成功'],"JSON");
}else{
M("promote_quick_menu ","tab_")->add(
array("quick_menu_id"=>$menu_id,
"promote_id"=>get_pid(),
"create_time"=>time())
);
$this->ajaxReturn(['status'=>1,'info'=>'添加成功'],"JSON");
}
}
// 消息列表
public function msg_list($type=56,$p=0){
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$page = $p ? $p : 1; //默认显示第一页数据
if($type==51){
$data_list = M("document","sys_")->where("category_id=51 and status=1")->order("update_time desc") ->page($page, $row)->select(); //游戏咨询
$count = M("document","sys_")->where("category_id=51 and status=1")->count();
}elseif ($type==50){
$data_list = null;
$count = 0;
}else{
$data_list = M("document","sys_")->limit('0,50')->where("category_id=56 and status=1")->order("update_time desc")->page($page, $row)->select(); //游戏公告
$count = M("document","sys_")->where("category_id=56 and status=1")->count();
}
$parameter['p'] = I('get.p', 1);
$parameter['row'] = I('get.row');
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
$this->meta_title = "公告列表";
$this->assign("type", $type);
$this->assign("data_list", $data_list);
$this->display();
}
/* public function page_show($model,$map,$p=1)
{
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$this->meta_title = "平台币充值";
$page = $p ? $p : 1; //默认显示第一页数据
$data = M($model, 'tab_')
->where($map)
->order('id DESC')
->page($page, $row)
->select();
$count = M($model, "tab_")->where($map)->count();
$parameter = $map;
$parameter['p'] = I('get.p', 1);
$parameter['row'] = I('get.row');
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
$this->assign("data_list", $data);
$this->display();
}*/
/**
* 我的基本信息
*/
public function base_info()
{
if (IS_POST) {
$type = $_REQUEST['type'];
$map['id'] = get_pid();
$se = array();
foreach ($_REQUEST as $key => $value) {
$_REQUEST[$key] = trim($value);
}
switch ($type) {
case 0:
//if (empty($_REQUEST['nickname']) ) {
// $this->error('请输入昵称', U('Promote/base_info'));
// exit();
//}
if ( empty($_REQUEST['real_name']) ) {
$this->error('请输入联系人姓名', U('Promote/base_info'));
exit();
}
$pattern = "/^[\x{4e00}-\x{9fa5}]+$/u";
if(!preg_match($pattern,$_REQUEST['real_name'])){
$this->error('联系人姓名错误', U('Promote/base_info'));
exit();
}
if ( empty($_REQUEST['email'])) {
$this->error('请输入电子邮箱', U('Promote/base_info'));
exit();
}
$pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
if ( !preg_match( $pattern, $_REQUEST['email'] ) ){
$this->error('邮箱地址错误', U('Promote/base_info'));exit;
}
// if (empty($_REQUEST['alipay_account']) ) {
// $this->error('请输入支付宝账号', U('Promote/base_info'));
// exit();
// }
$se['nickname'] = $_REQUEST['nickname'];
$se['real_name'] = $_REQUEST['real_name'];
$se['email'] = $_REQUEST['email'];
$se['alipay_account'] = $_REQUEST['alipay_account'];
break;
case 1:
if(empty($_REQUEST['mobile_phone']) ){
$this->error('结算手机号不能为空', U('Promote/base_info'));
return false;
}
$pattern = "/^1[3|5|7|8]\\d{9}$/i";
if ( !preg_match( $pattern, $_REQUEST['mobile_phone'] ) ){
$this->error('您输入的手机号码格式不合法', U('Promote/base_info'));
}
if ($_REQUEST['s_county'] === "市、县级市") {
$this->error('开户城市填写不完整', U('Promote/base_info'));
return false;
exit();
}
if(empty($_REQUEST['account_openin']) ){
$this->error('开户网点不能为空', U('Promote/base_info'));
return false;
}
$account_openin_pattern = "/^[\x{4e00}-\x{9fa5}]{2,}$/u";
if(!preg_match($account_openin_pattern,$_REQUEST['account_openin'])){
$this->error('开户网点错误', U('Promote/base_info'));
exit();
}
if(empty($_REQUEST['bank_name']) ){
$this->error('收款银行不能为空', U('Promote/base_info'));
return false;
}
if(empty($_REQUEST['bank_card']) ){
$this->error('银行卡号不能为空', U('Promote/base_info'));
return false;
}
if(!is_numeric($_REQUEST['bank_card'])){
$this->error('卡号格式错误', U('Promote/base_info'));
return false;
}
$bank_card_pattern = "/^\d{10,19}$/u";
if(!preg_match($bank_card_pattern,$_REQUEST['bank_card'])){
$this->error('卡号格式错误', U('Promote/base_info'));
exit();
}
if(empty($_REQUEST['bank_account']) ){
$this->error('银行户名不能为空', U('Promote/base_info'));
return false;
}
$bank_account_pattern = "/^[\x{4e00}-\x{9fa5}]{2,}$/u";
if(!preg_match($bank_account_pattern,$_REQUEST['bank_account'])){
$this->error('银行卡开户人姓名错误', U('Promote/base_info'));
exit();
}
if(empty($_REQUEST['idcard']) ){
$this->error('证件号码不能为空', U('Promote/base_info'));
exit();
}
if(!is_idcard($_REQUEST['idcard'])) {
$this->error('证件号码错误', U('Promote/base_info'));
exit();
}
$se['mobile_phone'] = $_REQUEST['mobile_phone'];
$se['bank_name'] = $_REQUEST['bank_name'];
$se['bank_card'] = $_REQUEST['bank_card'];
$se['bank_account'] = $_REQUEST['bank_account'];
$se['account_openin'] = $_REQUEST['account_openin'];
$se['bank_area'] = $_REQUEST['s_province'] . ',' . $_REQUEST['s_city'] . ',' . $_REQUEST['s_county'];
$se['idcard'] = $_REQUEST['idcard'];
break;
case 2:
if($_REQUEST['old_password'] !="0" && empty($_REQUEST['old_password']) ){
$this->error('旧密码不能为空', U('Promote/base_info'));
return false;
}
if(strlen($_REQUEST['old_password']) <6 ){
$this->error('旧密码不正确', U('Promote/base_info'));
return false;
}
if($_REQUEST['password'] != "0" && empty($_REQUEST['password']) ){
$this->error('新密码不能为空', U('Promote/base_info'));
return false;
}
if(strlen($_REQUEST['password']) <6 ){
$this->error('新密码最短6位', U('Promote/base_info'));
return false;
}
if( empty($_REQUEST['confirm_password'])){
$this->error('确认密码不能为空', U('Promote/base_info'));
return false;
}
if(strlen($_REQUEST['confirm_password'])<6 ){
$this->error('确认密码最短6位', U('Promote/base_info'));
return false;
}
$prp = M("promote", "tab_")->where($map)->find();
$ue = new UserApi();
if($_REQUEST['password'] !== $_REQUEST['confirm_password']){
$this->error('新密码和确认密码不一致', U('Promote/base_info'));
return false;
} else {
$se['password'] = $this->think_ucenter_md5($_REQUEST['confirm_password'], UC_AUTH_KEY);
}
if($this->think_ucenter_md5($_REQUEST['old_password'], UC_AUTH_KEY) !== $prp['password']) {
$this->error('请输入正确的旧密码', U('Promote/base_info'));
return false;
exit();
}
break;
case 3:
$prp = M("promote", "tab_")->where($map)->find();
$ue = new UserApi();
if($_REQUEST['old_second_pwd'] != "0" && empty($_REQUEST['old_second_pwd']) && !empty($prp['second_pwd'])){
$this->error('旧二级密码不能为空', U('Promote/base_info'));
return false;
}
if(strlen($_REQUEST['old_second_pwd']) <6 && !empty($prp['second_pwd'])){
$this->error('旧二级密码不正确', U('Promote/base_info'));
return false;
}
if($_REQUEST['second_pwd'] !="0" && empty($_REQUEST['second_pwd']) ){
$this->error('新二级密码不能为空', U('Promote/base_info'));
return false;
}
if(strlen($_REQUEST['second_pwd']) <6 ){
$this->error('新二级密码长度不能小于6', U('Promote/base_info'));
return false;
}
if (empty($_REQUEST['confirm_second_pwd'])){
$this->error('请输入确认密码', U('Promote/base_info'));
return false;
}
if ($_REQUEST[''] != $_REQUEST['']){
$this->error('新耳机密码和确认密码不一致', U('Promote/base_info'));
return false;
}
if ($this->think_ucenter_md5($_REQUEST['old_second_pwd'], UC_AUTH_KEY) != $prp['second_pwd']) {
$this->error('旧二级密码错误', U('Promote/base_info'));
return false;
exit();
} else if ($_REQUEST['second_pwd'] !== $_REQUEST['confirm_second_pwd']) {
$this->error('新二级密码和确认密码不一致', U('Promote/base_info'));
return false;
} else {
$se['second_pwd'] = $this->think_ucenter_md5($_REQUEST['confirm_second_pwd'], UC_AUTH_KEY);
}
break;
default:
$se['nickname'] = $_REQUEST['nickname'];
$se['real_name'] = $_REQUEST['real_name'];
$se['email'] = $_REQUEST['email'];
break;
}
$res = M("promote", "tab_")->where($map)->save($se);
if ($res !== false) {
$this->success("修改成功", U('Promote/base_info?type=' . $type));
} else {
$this->error('修改失败', U('Promote/base_info'));
}
} else {
$model = M('Promote', 'tab_');
$data = $model->find(session("promote_auth.pid"));
$data['bank_area'] = explode(',', $data['bank_area']);
$this->meta_title = "基本信息";
$this->assign("data", $data);
$this->wxQrcode($data);
$user = D('Promote')->isLogin();
if (empty($user)) {
$this->redirect("Home/Index/index");
}
$promoteUrl = "https://m.wmtxkj.com/mobile.php?s=Ssg/login/promote_id/".$user['pid'];
$this->assign("promote_url", $promoteUrl);
$this->display();
}
}
public function think_ucenter_md5($str, $key = 'ThinkUCenter')
{
return '' === $str ? '' : md5(sha1($str) . $key);
}
/**
*子账号
*/
public function mychlid($p = 0)
{
$account = I('account', '');
$idcard = I('idcard', '');
$mobile = I('mobile', '');
$realName = I('real_name', '');
$status = I('status', 'all');
$promoteId = session("promote_auth.pid");
$model = new PromoteModel();
$promotes = $model->field(['id', 'account'])->where('parent_id=' . $promoteId)->select();
$subPromotes = $model->field(['id', 'account'])->where('parent_id='. $promoteId . ' or grand_id=' . $promoteId . ' or id=' . $promoteId)->select();
$map = [];
if ($account) {
$map['account'] = ['like', '%' . $account . '%'];
}
if ($mobile) {
$map['mobile_phone'] = ['like', '%' . $mobile . '%'];
}
if ($idcard) {
$map['idcard'] = ['like', '%' . $idcard . '%'];
}
if ($realName) {
$map['real_name'] = ['like', '%' . $realName . '%'];
}
if ($status != 'all') {
$map['status'] = ['eq', $status];
}
$map['parent_id'] = session("promote_auth.pid");
$appendCallback = function($data) {
$promote = new PromoteModel();
$player = new UserPlayModel();
$ids = array_column($data, 'id');
$parentIds = array_column($data, 'parent_id');
if (count($ids) == 0) {
return [
'hasChildList' => [],
'hasPlayerList' => [],
'hasShiftList' => [],
'hasShiftPlayerList' => [],
'parentPromotes' => [],
];
}
$parentList = $promote->field(['id', 'account'])->where(['id' => ['in', $parentIds]])->select();
$parentPromotes = [];
foreach($parentList as $parent) {
$parentPromotes[$parent['id']] = $parent['account'];
}
$countList = $promote->field(['count(*)' => 'count', 'parent_id' => 'parent_id'])->where(['parent_id' => ['in', $ids]])->group('parent_id')->select();
$playerList = $player->field(['count(*)' => 'count', 'promote_id' => 'promote_id'])->where(['promote_id' => ['in', $ids]])->group('promote_id')->select();
$shiftList = M('ShiftTask')->field(['count(*)' => 'count', 'from_promote_id' => 'from_promote_id'])->where(['status' => 0, 'type' => 1, 'promote_id' => ['in', $ids]])->group('from_promote_id')->select();
$shiftPlayerList = M('ShiftTask')->field(['count(*)' => 'count', 'from_promote_id' => 'from_promote_id'])->where(['status' => 0, 'type' => 2, 'promote_id' => ['in', $ids]])->group('from_promote_id')->select();
return [
'hasChildList' => array_column($countList, 'parent_id'),
'hasPlayerList' => array_column($playerList, 'promote_id'),
'hasShiftList' => array_column($shiftList, 'from_promote_id'),
'hasShiftPlayerList' => array_column($shiftPlayerList, 'from_promote_id'),
'parentPromotes' => $parentPromotes,
];
};
$this->assign('subPromotes', $subPromotes);
$this->assign('promotes', $promotes);
parent::lists("Promote", $p, $map, $appendCallback);
}
/**
*子账号
*/
public function mygrand($p = 0)
{
$account = I('account', '');
$idcard = I('idcard', '');
$mobile = I('mobile', '');
$realName = I('real_name', '');
$status = I('status', 'all');
$promoteId = session("promote_auth.pid");
$model = new PromoteModel();
$promotes = $model->field(['id', 'account'])->where('parent_id=' . $promoteId)->select();
$subPromotes = $model->field(['id', 'account'])->where('parent_id='. $promoteId . ' or grand_id=' . $promoteId . ' or id=' . $promoteId)->select();
$map = [];
if ($account) {
$map['account'] = ['like', '%' . $account . '%'];
}
if ($mobile) {
$map['mobile_phone'] = ['like', '%' . $mobile . '%'];
}
if ($idcard) {
$map['idcard'] = ['like', '%' . $idcard . '%'];
}
if ($realName) {
$map['real_name'] = ['like', '%' . $realName . '%'];
}
if ($status != 'all') {
$map['status'] = ['eq', $status];
}
$promote = D('promote')->where(['id' => session('promote_auth.pid')])->find();
$isGrand = false;
if ($promote['parent_id'] == 0 && $promote['grand_id'] == 0) {
$map['grand_id'] = session("promote_auth.pid");
$isGrand = true;
} else {
$map['parent_id'] = session("promote_auth.pid");
}
$appendCallback = function($data) use($promote) {
$promoteModel = new PromoteModel();
$player = new UserPlayModel();
$ids = array_column($data, 'id');
$parentIds = array_column($data, 'parent_id');
if (count($ids) == 0) {
return [
'hasPlayerList' => [],
'hasShiftList' => [],
'hasShiftPlayerList' => [],
'parentPromotes' => [],
];
}
$parentList = $promoteModel->field(['id', 'account'])->where(['id' => ['in', $parentIds]])->select();
$parentPromotes = [];
foreach($parentList as $parent) {
$parentPromotes[$parent['id']] = $parent['account'];
}
$list = [];
foreach($data as $key => $item) {
if ($promote['parent_id'] > 0 && $promote['grand_id'] == 0) {
$item['idcard'] = hideStar($item['idcard'], 4, 10);
$item['mobile_phone'] = hideStar($item['mobile_phone'], 3, 4);
}
$list[$key] = $item;
}
$playerList = $player->field(['count(*)' => 'count', 'promote_id' => 'promote_id'])->where(['promote_id' => ['in', $ids]])->group('promote_id')->select();
$shiftList = M('ShiftTask')->field(['count(*)' => 'count', 'from_promote_id' => 'from_promote_id'])->where(['status' => 0, 'type' => 1, 'promote_id' => ['in', $ids]])->group('from_promote_id')->select();
$shiftPlayerList = M('ShiftTask')->field(['count(*)' => 'count', 'from_promote_id' => 'from_promote_id'])->where(['status' => 0, 'type' => 2, 'promote_id' => ['in', $ids]])->group('from_promote_id')->select();
return [
'list_data' => $list,
'hasPlayerList' => array_column($playerList, 'promote_id'),
'hasShiftList' => array_column($shiftList, 'from_promote_id'),
'hasShiftPlayerList' => array_column($shiftPlayerList, 'from_promote_id'),
'parentPromotes' => $parentPromotes,
];
};
$this->assign('isGrand', $isGrand);
$this->assign('subPromotes', $subPromotes);
$this->assign('promotes', $promotes);
parent::lists("Promote", $p, $map, $appendCallback);
}
public function add_chlid()
{
if (IS_POST) {
$parentId = 0;
if (isset($_POST['promote_type']) && $_POST['promote_type'] == 2 && isset($_POST['parent_id'])) {
if ($_POST['parent_id'] == 0) {
$this->ajaxReturn(array('status'=>-1,'msg'=>'请选择上级渠道'));
}
$parentId = $_POST['parent_id'];
} else {
$parentId = session('promote_auth.pid');
}
$user = new PromoteApi();
$promote = D('promote')->where(['id' => $parentId])->find();
$status = promoteCan(session('promote_auth.pid'), function($level) use ($promote) {
if ($level == 1) {
return true;
} elseif ($level == 2) {
return true;
} elseif ($level == 3) {
return false;
}
});
if (!$status) {
$this->ajaxReturn(array('status'=>-1, 'msg'=>'无权限操作'));
}
$_POST['ba_id'] = $promote['ba_id'];
$_POST['parent_id'] = $parentId;
$_POST['parent_account'] = $promote['account'];
//三级渠道
if($promote['parent_id']>0){
$_POST['grand_id'] = $promote['parent_id'];
$_POST['grand_account'] = $promote['promote_account'];
}
if (isset($_POST['mobile_phone'])) {
if(!preg_match("/^1[3456789]{1}\d{9}$/", $_POST['mobile_phone'])){
$this->ajaxReturn(array('status'=>-1,'msg'=>'手机号格式错误'));
}
}
if (isset($_POST['idcard'])) {
if(!$this->isIdcard($_POST['idcard'])){
$this->ajaxReturn(array('status'=>-1,'msg'=>'身份证格式错误'));
}
}
$res = $user->promote_add($_POST);
if (is_numeric($res)) {
$ba = new \Admin\Model\BusinessAffairsModel();
$ba->add_child($_POST['ba_id'],$res);
$this->ajaxReturn(array('status'=>1,'msg'=>"添加成功"));
} else {
$msg = $res =="渠道账号已存在"?"子渠道账号已存在":$res;
$this->ajaxReturn(array('status'=>-1,'msg'=>$msg));
}
} else {
$type = I('type', 0);
$status = promoteCan(session('promote_auth.pid'), function($level) use ($type) {
if ($level == 1) {
return true;
} elseif ($level == 2) {
if ($type == 1) {
return false;
}
return true;
} elseif ($level == 3) {
return false;
}
});
if (!$status) {
$this->error('无权限操作');
}
$model = new PromoteModel();
$promotes = $model->field(['id', 'account'])->where('parent_id=' . session("promote_auth.pid"))->select();
$this->assign('promotes', $promotes);
$this->meta_title = "添加子渠道";
$this->display();
}
}
public function resetPassword()
{
$promoteId = I('promote_id', 0);
if ($promoteId == 0) {
$this->ajaxReturn(['status'=>0,'msg'=>"参数错误"]);
}
$promoteService = new PromoteService();
if ($password = $promoteService->resetPassword($promoteId)) {
$this->ajaxReturn(['status'=>1, 'msg'=> '重置密码成功', 'data' => ['password' => $password]]);
} else {
$this->ajaxReturn(['status'=>0, 'msg'=> '重置密码失败']);
}
}
public function froze()
{
$promoteId = I('promote_id', 0);
if ($promoteId == 0) {
$this->ajaxReturn(['status'=>0,'msg'=>"参数错误"]);
}
$promoteService = new PromoteService();
if ($promoteService->froze($promoteId)) {
$this->ajaxReturn(['status'=>1, 'msg'=> '冻结成功']);
} else {
$this->ajaxReturn(['status'=>0, 'msg'=> '冻结失败']);
}
}
public function unfreeze()
{
$promoteId = I('promote_id', 0);
if ($promoteId == 0) {
$this->ajaxReturn(['status'=>0,'msg'=>"参数错误"]);
}
$promoteService = new PromoteService();
if ($promoteService->unfreeze($promoteId)) {
$this->ajaxReturn(['status'=>1, 'msg'=> '解冻成功']);
} else {
$this->ajaxReturn(['status'=>0, 'msg'=> '解冻失败']);
}
}
public function edit_chlid($id = 0)
{
if (IS_POST) {
$type = $_REQUEST['type'];
$map['id'] = $id;
$se = array();
foreach ($_REQUEST as $key => $value) {
$_REQUEST[$key] = trim($value);
}
switch ($type) {
case 0:
if (empty($_REQUEST['nickname']) ) {
$this->error('子账号昵称不能为空', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',0))));
exit();
}
if ($_POST['password'] != "0" && empty($_POST['password'])) {
unset($_POST['password']);
}else{
if(strlen($_REQUEST['password'])<6 ){
$this->error('登录密码不能小于6位字符', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',0))));
return false;
}
}
if ( empty($_REQUEST['real_name']) ) {
$this->error('联系人姓名不能为空', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',0))));
exit();
}
$pattern = "/^[\x{4e00}-\x{9fa5}]+$/u";
if(!preg_match($pattern,$_REQUEST['real_name'])){
$this->error('您输入的联系人姓名格式不正确', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',0))));
exit();
}
if(empty($_REQUEST['mobile_phone']) ){
$this->error('手机号不能为空', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',0))));
return false;
}
$pattern = "/^1[3|5|7|8]\\d{9}$/i";
if ( !preg_match( $pattern, $_REQUEST['mobile_phone'] ) ){
$this->error('您输入的手机号码格式不合法', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',0))));
}
if(empty($_REQUEST['email']) ){
$this->error('电子邮箱不能为空', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',0))));
return false;
}
$pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
if ( !preg_match( $pattern, $_REQUEST['email'] ) ){
$this->error('您输入的电子邮箱地址不合法', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',0))));
};
$user = new PromoteApi();
$res = $user->edit($_POST);
if ($res !== false) {
$this->success("子账号修改成功", U('Promote/mychlid'));
} else {
$this->error("修改子账号失败");
}
break;
case 1:
if ($_REQUEST['s_county'] === "市、县级市") {
$this->error('开户城市填写不完整',U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',1))));
return false;
exit();
}
if(empty($_REQUEST['account_openin']) ){
$this->error('开户网点不能为空', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',1))));
return false;
}
if(empty($_REQUEST['bank_name']) ){
$this->error('收款银行不能为空', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',1))));
return false;
}
if(empty($_REQUEST['bank_card']) ){
$this->error('银行卡号不能为空', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',1))));
return false;
}
if(!is_numeric($_REQUEST['bank_card']) ){
$this->error('请输入正确的银行卡号', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',1))));
return false;
}
if(empty($_REQUEST['bank_account']) ){
$this->error('银行户名不能为空', U('Promote/edit_chlid',array('id'=>$id,'type'=>I('type',1))));
return false;
}
$se['mobile_phone'] = $_REQUEST['mobile_phone'];
$se['bank_name'] = $_REQUEST['bank_name'];
$se['bank_card'] = $_REQUEST['bank_card'];
$se['bank_account'] = $_REQUEST['bank_account'];
$se['account_openin'] = $_REQUEST['account_openin'];
$se['bank_area'] = $_REQUEST['s_province'] . ',' . $_REQUEST['s_city'] . ',' . $_REQUEST['s_county'];
$res = M("promote", "tab_")->where($map)->save($se);
if ($res !== false) {
$this->success("修改成功", U('Promote/edit_chlid',array('id'=>$id,'type'=>$type)));
} else {
$this->error('修改失败', U('Promote/edit_chlid',array('id'=>$id,'type'=>$type)));
}
break;
}
} else {
$promote = A('Promote', 'Event');
$this->meta_title = '子帐号';
$promote->baseinfo('edit_chlid', $id);
}
}
/**
* @param int $level
* @param int $size
*/
public function qrcode($level=3,$size=4,$url=""){
Vendor('phpqrcode.phpqrcode');
$errorCorrectionLevel =intval($level) ;//容错级别
$matrixPointSize = intval($size);//生成图片大小
//生成二维码图片
ob_clean();
$object = new \QRcode();
echo $object->png(base64_decode(base64_decode($url)), false, $errorCorrectionLevel, $matrixPointSize, 2);
}
public function checkAccount($account){
$user = get_promote_entity($account, true);
if($user){
$this->ajaxReturn(array('status'=>1));
}else{
$this->ajaxReturn(array('status'=>0));
}
}
public function balance() {
if (IS_POST) {
$real_amount = $amount = I('amount');
if(!is_numeric($amount)){
$res_msg = '充值金额不是数字';
$this->show_balance();
echo ";
return false;";
$this->redirect('balance', array('status'=>1), 3, '');
}
if($amount<0) {
$res_msg = '充值金额不正确';
$this->show_balance();
echo ";
return false;";
$this->redirect('balance', array('status'=>1), 3, '');
}
$amount = abs($amount);
// $amount = 0.01;//测试金额
if (empty($_REQUEST['account'])) {
$user = get_promote_entity(PID);
} else {
$user = get_promote_entity($_REQUEST['account'], true);
}
$order_no = "TB_" . date('Ymd') . date('His') . sp_random_string(4);
$create['amount'] = $amount;
$create['pay_order_number'] = $order_no;
$vo = new \Think\Pay\PayVo();
$vo->setBody("账户余额")
->setFee($amount)//支付金额
->setTitle("余额充值")
->setOrderNo($order_no)
->setSignType("MD5")
->setPayMethod("direct_tb")
->setTable("balance")
->setUserId($user['id'])
->setAccount($user['account'])
->setPromoteId(PID)
->setPromoteName(PROMOTE_ACCOUNT)
->setMoney($user['balance_coin']);
switch (I('pay_type')) {
case 'swiftpass':
//判断是否开启微信充值
if (pay_set_status('wei_xin') == 0 && pay_set_status('weixin') == 0) {
$this->error("网站未开启微信充值", '', 1);
exit();
}
if (get_wx_type() == 0) {
$weixn = new Weixin();
$is_pay = json_decode($weixn->weixin_pay("余额充值", $order_no, $real_amount), true);
if ($is_pay['status'] === 1) {
$json_['out_trade_no'] = $order_no;
$json_['amount'] = $amount;
$json_['pay_money'] = $real_amount;
$json_['code_img_url'] = U('qrcode', array('level' => 3, 'size' => 4, 'url' => base64_encode(base64_encode($is_pay['url']))));
}
$create['pay_way'] = 2;
$this->add_balance($user, $create);
$this->show_balance();
echo "";
} else {
$vo->setService("pay.weixin.native")
->setPayWay(2);
$pay = new \Think\Pay('swiftpass', C('weixin'));
$all = $pay->buildRequestForm($vo);
$all['amount'] = $vo->getMoney();
$this->show_balance();
echo "";
}
break;
case 'goldpig':
if (pay_set_status('goldpig') == 0) {
$this->error("网站未开启金猪充值", '', 1);
exit();
}
if(empty(C('goldpig.partner'))||empty(C('goldpig.wooolid'))) {
$this->error("网站未配置金猪充值", '', 1);
exit();
}
if($amount<1) {
$this->error("单笔金额不小于1", '', 1);
exit();
}
$sign=think_encrypt(md5($real_amount.$order_no));
$create['pay_way'] = 8;
$this->add_balance($user, $create);
file_put_contents("./Application/Home/OrderNo/".$order_no.'.txt',json_encode($create));
redirect(U('goldpig_pay',array('userid'=>$user['id'],'account' =>$user['account'],'pay_amount'=>$real_amount,'sign'=>$sign,'pay_order_number'=>$order_no)));
break;
default:
//判断是否开启支付宝充值
if (pay_set_status('alipay') == 0) {
$this->error("网站未开启支付宝充值", '', 1);
exit();
}
$vo->setService("create_direct_pay_by_user")
->setPayWay(1);
$pay = new \Think\Pay('alipay', C('alipay'));
echo $pay->buildRequestForm($vo);
break;
}
} else {
$model = M('Promote', 'tab_');
$data = $model->find(session("promote_auth.pid"));
$data['bank_area'] = explode(',', $data['bank_area']);
$this->assign('data',$data);
$this->meta_title = '账户余额';
$this->display();
}
}
public function balance_recharge() {
if (IS_POST) {
$real_amount = $amount = I('amount',0,'intval');
//$real_amount = $amount = 0.01;
if(!is_numeric($amount)){
$this->ajaxReturn(['status'=>0,'info'=>'充值金额不是数字']);
}
if($amount<0){
$this->ajaxReturn(['status'=>0,'info'=>'充值金额错误']);
}
if (empty($_REQUEST['account'])) {
$user = get_promote_entity(PID);
} else {
$user = get_promote_entity($_REQUEST['account'], true);
}
$order_no = "TB_" . date('Ymd') . date('His') . sp_random_string(4);
$create['amount'] = $amount;
$create['pay_order_number'] = $order_no;
$vo = new \Think\Pay\PayVo();
$vo->setBody("账户余额")
->setFee($amount)//支付金额
->setTitle("余额充值")
->setOrderNo($order_no)
->setSignType("MD5")
->setPayMethod("direct_tb")
->setTable("balance")
->setUserId($user['id'])
->setAccount($user['account'])
->setPromoteId(PID)
->setPromoteName(PROMOTE_ACCOUNT)
->setMoney($user['balance_coin']);
switch (I('pay_type')) {
case 'swiftpass':
//判断是否开启微信充值
if (pay_set_status('wei_xin') == 0 && pay_set_status('weixin') == 0) {
$this->ajaxReturn(['status'=>0,'info'=>'网站未开启微信充值']);
}
if (get_wx_type() == 0) {
$weixn = new Weixin();
$is_pay = json_decode($weixn->weixin_pay("余额充值", $order_no, $real_amount), true);
if ($is_pay['status'] === 1) {
$json_['out_trade_no'] = $order_no;
$json_['amount'] = $amount;
$json_['pay_money'] = $real_amount;
$json_['code_img_url'] = U('qrcode', array('level' => 3, 'size' => 4, 'url' => base64_encode(base64_encode($is_pay['url']))));
}
$create['pay_way'] = 2;
$this->add_balance($user, $create);
$this->ajaxReturn(['status'=>1,'info'=>'','data'=>$json_]);
} else {
$vo->setService("pay.weixin.native")
->setPayWay(2);
$pay = new \Think\Pay('swiftpass', C('weixin'));
$all = $pay->buildRequestForm($vo);
$all['amount'] = $vo->getMoney();
$this->ajaxReturn(['status'=>1,'info'=>'','data'=>$all]);
}
break;
default:
//判断是否开启支付宝充值
if (pay_set_status('alipay') == 0) {
$this->ajaxReturn(['status'=>0,'info'=>'网站未开启支付宝充值']);
}
$vo->setService("create_direct_pay_by_user")
->setPayWay(1);
$pay = new \Think\Pay('alipay', C('alipay'));
$url = $pay->buildRequestForm($vo);
$this->ajaxReturn(['status'=>1,'info'=>'','url'=>$url]);
}
} else {
$this->ajaxReturn(['status'=>0,'info'=>'请求有误']);
}
}
/**
* 金猪支付
* @return [type] [description]
* @author cb <[email address]>
*/
public function goldpig_pay(){
if(IS_POST){
SafeFilter($_POST);
$msign=think_encrypt(md5($_POST['amount'].$_POST['pay_order_number']));
if($msign!==$_POST['sign']){
$this->error('验证失败',U('promote/balance'));exit;
}
if($_POST['amount']<=0){
$this->error('金额有误');
}
$url="./Application/Home/OrderNo/".$_POST['pay_order_number'].'.txt';
if(!file_exists($url) ){
$this->error('操作有误',U('promote/balance'));exit;
}
$user = M('Promote','tab_')->field('id,account')->where(['account'=>$_POST['UserName']])->find();
if (empty($user)) {
$this->error("账号不存在");
exit();
}
$baseurl = 'http://api.357p.com/?';
$url = $baseurl . "UserName={$_POST['UserName']}&Price={$_POST['amount']}&shouji={$_POST['shouji']}&PayID={$_POST['PayID']}&userid={$_POST['userid']}&wooolID={$_POST['wooolID']}&jinzhua={$_POST['pay_order_number']}&jinzhub={$_POST['jinzhub']}&jinzhuc={$_POST['jinzhuc']}&jinzhue={$_POST['pay_order_number']}";
redirect($url);exit;
}else{
$this->display();
}
}
public function show_balance() {
$model = M('Promote', 'tab_');
$data = $model->find(session("promote_auth.pid"));
$data['bank_area'] = explode(',', $data['bank_area']);
$this->assign('data',$data);
$this->meta_title = '账户余额';
$this->display('balance');
}
public function checkOrder($order_number){
$map['pay_order_number'] = $order_number;
$data = M('Balance','tab_')
->where($map)
->field('pay_status')
->find();
if ($data['pay_status'] == 1){
$this->success('支付成功');
}else{
$this->error('暂未支付');
}
}
public function add_balance($promote,$data){
$balance = M("Balance","tab_");
$balance_data['order_number'] = "";
$balance_data['pay_order_number'] = $data['pay_order_number'];
$balance_data['money'] = $data['amount'];
$balance_data['balance'] = $promote['balance_coin'];
$balance_data['pay_status'] = 0;
$balance_data['recharge_type'] = $data['pay_way'];
$balance_data['create_time'] = time();
$balance_data['recharge_id'] = $promote['id'];
$balance_data['recharge_account'] = $promote['account'];
$balance_data['promote_id'] = PID;
$balance_data['promote_account'] = PROMOTE_ACCOUNT;
$balance->create($balance_data);
$result = $balance->add();
return $result;
}
public function wxQrcode($promote='') {
if (C('wechat.status')>0) {
$appid = C('wechat.appid');
$appsecret = C('wechat.appsecret');
$token = session("token");
if($token){
$auth = new WechatAuth($appid, $appsecret, $token);
} else {
$auth = new WechatAuth($appid, $appsecret);
$token = $auth->getAccessToken();
session(array('expire' => $token['expires_in']));
session("token", $token['access_token']);
}
if (empty($promote)) {
$promote = D('promote')->detail();
}
$sign = $promote['weixin_openid_sign']?$promote['weixin_openid_sign']:rand(1,99999);
$ticket = $auth->qrcodeCreate($sign,604800);
$this->assign('wxQrcodeUrl',$ticket['url']);
} else {
$this->assign('wxQrcodeUrl',null);
}
}
public function wxQrcodeRedirect() {
$xml_str = $GLOBALS['HTTP_RAW_POST_DATA'];
$this->logger($xml_str);
if(!empty($xml_str)){
libxml_disable_entity_loader(true);
$request_xml = simplexml_load_string($xml_str, 'SimpleXMLElement', LIBXML_NOCDATA);
switch ($request_xml->MsgType){
case 'event':
$this->_setOpenid($request_xml);
break;
}
} else {
die('');
}
}
public function _setOpenid($data,$type) {
$event = strtolower($data->Event);
$openid = $data->FromUserName; // 用户
$auth = new WechatAuth(C('wechat.appid'), C('wechat.appsecret'));
$model = D('Promote');
$promote = $model->detail();
$data = array('id'=>$promote['id']);
$user = $auth->userInfo($openid);
switch($event) {
case 'subscribe':{
// 关注事件
if (!empty($promote['weixin_openid'])) {
$auth->setText($openid,date('Y-m-d H:i:s').' 请先解绑微信');exit;
}
if (str_replace('qrscene_', '', $data['EventKey']) != $promote['weixin_openid_sign']) {
$auth->setText($openid,date('Y-m-d H:i:s').' 页面错误,请刷新页面重试');exit;
}
$data['weixin_account']=emoji_encode($user['nickname']);
$data['weixin_openid']=$openid;
$res = $model->update($data);
if ($res) {
$auth->sendText($openid,date('Y-m-d H:i:s').' 微信绑定成功');
} else {
$auth->sendText($openid,date('Y-m-d H:i:s').' 微信绑定失败');
}
};break;
case 'scan':{
// 关注以后
if ($user['subscribe'] != 1) {$auth->setText($openid,date('Y-m-d H:i:s').' 你未关注微信');exit;}
if (empty($promote['weixin_openid'])) {
$auth->setText($openid,date('Y-m-d H:i:s').' 请先绑定微信');exit;
}
};break;
case 'unsubscribe':{
// 取消关注
if ($promote['weixin_openid'] != $openid) {
$auth->setText($openid,date('Y-m-d H:i:s').' 对不起,你没有权限');exit;
}
if (str_replace('qrscene_', '', $data['EventKey']) != $promote['weixin_openid_sign']) {
$auth->setText($openid,date('Y-m-d H:i:s').' 页面错误,请刷新页面重试');exit;
}
if (empty($promote['weixin_openid'])) {
$auth->setText($openid,date('Y-m-d H:i:s').' 暂未绑定微信');exit;
}
$data['weixin_account']='';
$data['weixin_openid']='';
$res = $model->update($data);
if ($res) {
$auth->sendText($openid,date('Y-m-d H:i:s').' 微信解绑成功');
} else {
$auth->sendText($openid,date('Y-m-d H:i:s').' 微信解绑失败');
}
};break;
}
}
public function logger($log_content) {
$fg_str="\n============================================================\n";
$max_size = 500000;
$log_filename = __ROOT__."/Uploads/Logs/log".date('Ymd').".xml";
if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){
unlink($log_filename);
}
if(is_array($log_content)){
file_put_contents($log_filename, date('Y-m-d H:i:s')."\n".json_encode($log_content).$fg_str, FILE_APPEND);
}else{
file_put_contents($log_filename, date('Y-m-d H:i:s')."\n".$log_content.$fg_str, FILE_APPEND);
}
}
public function promoteList($p=1){
switch ($_GET['type']) {
case '':
case 1:
$this->promoteLists($p);
break;
default:
$this->siteApplyList($p);
break;
}
}
// 推广员列表
const model_name = 'Promote';
public function promoteLists($p){
$map = [];
$map['_string'] = 'id='. session('promote_auth.pid')
. ' or parent_id=' . session('promote_auth.pid')
. ' or grand_id=' . session('promote_auth.pid');
$selectMap = $map;
if(isset($_REQUEST['promote_id'])){
$promoteid = $_REQUEST['promote_id'];
unset($_REQUEST['promote_id']);
if(isset($_REQUEST['parent_id'])) {
$parent_id = $_REQUEST['parent_id'];
unset($_REQUEST['parent_id']);
if($promoteid == $parent_id) {
$map['id'] = $promoteid;
} else {
$maps['parent_id'] = $parent_id;
$maps['grand_id'] = $parent_id;
$maps['_logic'] = 'or';
$pro = M('promote','tab_')->field('id,account')->where([array('id'=>$promoteid),$maps])->select();
if (!empty($pro_ids)){
$map['id'] = array('eq',-1);
}
}
} else {
$map['id'] = $promoteid;
/* $maps['parent_id'] = $promoteid;
$maps['grand_id'] = $promoteid;
$maps['_logic'] = 'or';
$pro = M('promote','tab_')->field('id,account')->where($maps)->select();
$pro_ids = array_column($pro,'id');
$pro_ids[] = $promoteid;
if (!empty($pro_ids)){
$map['id'] = ['in',$pro_ids];
}else{
$map['id'] = array('eq',-1);
} */
}
} else {
if (isset($_REQUEST['parent_id'])) {
if ($_REQUEST['parent_id']=='全部') {
unset($_REQUEST['parent_id']);
}
$zid=get_zi_promote_id($_REQUEST['parent_id']);
if($zid){
$zid=$zid.','.$_REQUEST['parent_id'];
}else{
$zid=$_REQUEST['parent_id'];
}
$map['id']=array('in',$zid);
unset($_REQUEST['parent_id']);
}
}
if(isset($_REQUEST['admin_id'])){
if($_REQUEST['admin_id']=="全部"){
unset($_REQUEST['admin']);
}else{
$map['ba_id']=$_REQUEST['admin_id'];
}
}
if(I('promote_level') == 1){
$map['parent_id'] = 0;
}elseif(I('promote_level') == 2){
$map['parent_id'] = ['neq',0];
$map['grand_id'] = 0;
}elseif (I('promote_level') == 3) {
$map['parent_id'] = ['neq',0];
$map['grand_id'] = ['neq',0];
}
$model = new PromoteModel();
$promotes = $model->field(['id', 'account'])->where($selectMap)->select();
$this->assign('promotes', $promotes);
self::order_lists(self::model_name, $p, $map);
}
/**
* [数组分页,二维数组字段排序]
* @param [type] $model [description]
* @param integer $p [description]
* @param array $extend_map [description]
* @return [type] [description]
* @author [yyh] <[email address]>
*/
public function order_lists($model = null, $p = 0,$extend_map = array()){
$model || $this->error('模型名标识必须!');
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$arraypage = $page; //默认显示第一页数据
//获取模型信息
$model = M('Model')->getByName($model);
$model || $this->error('模型不存在!');
//解析列表规则
$fields = array();
$grids = preg_split('/[;\r\n]+/s', trim($model['list_grid']));
foreach ($grids as &$value) {
if(trim($value) === ''){
continue;
}
// 字段:标题:链接
$val = explode(':', $value);
// 支持多个字段显示
$field = explode(',', $val[0]);
$value = array('field' => $field, 'title' => $val[1]);
if(isset($val[2])){
// 链接信息
$value['href'] = $val[2];
// 搜索链接信息中的字段信息
preg_replace_callback('/\[([a-z_]+)\]/', function($match) use(&$fields){$fields[]=$match[1];}, $value['href']);
}
if(strpos($val[1],'|')){
// 显示格式定义
list($value['title'],$value['format']) = explode('|',$val[1]);
}
foreach($field as $val){
$array = explode('|',$val);
$fields[] = $array[0];
}
}
$fields[] = 'grand_id';
// 过滤重复字段信息
$fields = array_unique($fields);
// 关键字搜索
$map = $extend_map;
$key = $model['search_key']?$model['search_key']:'title';
if(isset($_REQUEST[$key])){
$map[$key] = array('like','%'.$_GET[$key].'%');
unset($_REQUEST[$key]);
}
// 条件搜索
foreach($_REQUEST as $name=>$val){
if(in_array($name,$fields)){
$map[$name] = $val;
}
}
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
//读取模型数据列表
if($model['extend']){
$name = get_table_name($model['id']);
$parent = get_table_name($model['extend']);
$fix = C("DB_PREFIX");
$key = array_search('id', $fields);
if(false === $key){
array_push($fields, "{$fix}{$parent}.id as id");
} else {
$fields[$key] = "{$fix}{$parent}.id as id";
}
/* 查询记录数 */
$count = D($parent)->join("INNER JOIN {$fix}{$name} ON {$fix}{$parent}.id = {$fix}{$name}.id")->where($map)->count();
// 查询数据
$data = D($parent)
->join("INNER JOIN {$fix}{$name} ON {$fix}{$parent}.id = {$fix}{$name}.id")
/* 查询指定字段,不指定则查询所有字段 */
->field(empty($fields) ? true : $fields)
// 查询条件
->where($map)
/* 默认通过id逆序排列 */
->order("{$fix}{$parent}.id DESC")
/* 数据分页 */
// ->page($page, $row) 需要查询所有数据 后面用数组分页,原因: 页面要排序
/* 执行查询 */
->select();
} else {
if($model['need_pk']){
in_array('id', $fields) || array_push($fields, 'id');
}
$name = parse_name(get_table_name($model['id']), true);
$data = D($name)
/* 查询指定字段,不指定则查询所有字段 */
->field(empty($fields) ? true : $fields)
// 查询条件
->where($map)
/* 默认通过id逆序排列 */
->order(empty($map['order'])?"id desc":$map['order'])
/* 数据分页 */
// ->page($page, $row)//需要查询所有数据 后面用数组分页,原因: 页面要排序
/* 执行查询 */
->select();
/* 查询记录总数 */
$count = count($data);
}
//分页
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$data = $this->parseDocumentList($data,$model['id']);
if(isset($extend_map['for_show_pic_list'])){
if($extend_map['for_show_pic_list']=='icon'){
foreach ($data as $key => $value) {
$data[$key]['pic_path']=get_cover($value['icon'],'path');
}
}
if($extend_map['for_show_pic_list']=='novice'){
foreach ($data as $key => $value) {
$data[$key]['novice']=arr_count($value['novice']);
}
}
}
if($_REQUEST['data_order']!=''){
$data_order=reset(explode(',',$_REQUEST['data_order']));
$data_order_type=end(explode(',',$_REQUEST['data_order']));
$this->assign('userarpu_order',$data_order);
$this->assign('userarpu_order_type',$data_order_type);
}
$data=my_sort($data,$data_order_type,(int)$data_order);
$size=$row;//每页显示的记录数
$pnum = ceil(count($data) / $size); //总页数,ceil()函数用于求大于数字的最小整数
//用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度)
$data = array_slice($data, ($arraypage-1)*$size, $size);
$this->assign('model', $model);
$this->assign('list_grids', $grids);
$this->assign('list_data', $data);
$this->meta_title = $model['title'].'列表';
$this->display($model['template_list']);
}
/**
* 处理文档列表显示
* @param array $list 列表数据
* @param integer $model_id 模型id
*/
protected function parseDocumentList($list,$model_id=null){
$model_id = $model_id ? $model_id : 1;
$attrList = get_model_attribute($model_id,false,'id,name,type,extra');
// 对列表数据进行显示处理
if(is_array($list)){
foreach ($list as $k=>$data){
foreach($data as $key=>$val){
if(isset($attrList[$key])){
$extra = $attrList[$key]['extra'];
$type = $attrList[$key]['type'];
if('select'== $type || 'checkbox' == $type || 'radio' == $type || 'bool' == $type) {
// 枚举/多选/单选/布尔型
$options = parse_field_attr($extra);
if($options && array_key_exists($val,$options)) {
$data[$key] = $options[$val];
}
}elseif('date'==$type){ // 日期型
$data[$key] = date('Y-m-d',$val);
}elseif('datetime' == $type){ // 时间型
$data[$key] = date('Y-m-d H:i:s',$val);
}
}
}
$data['model_id'] = $model_id;
$list[$k] = $data;
}
}
return $list;
}
public function shift()
{
$promoteService = new PromoteService();
$result = $promoteService->addShiftTask($_POST);
$this->ajaxReturn($result);
}
public function cancelShift()
{
$promoteService = new PromoteService();
$result = $promoteService->cancelShift($_POST);
$this->ajaxReturn($result);
}
public function downGame()
{
$gameId = $_POST['game_id'];
$promoteId = $_POST['promote_id'];
$applyService = new ApplyService();
$applyService->cancelGame($gameId, $promoteId);
$this->ajaxReturn(['status' => true, 'msg' => '下架成功']);
}
public function isIdcard($id)
{
$id = strtoupper($id);
$regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
$arr_split = array();
if(!preg_match($regx, $id)) {
return false;
}
if (15==strlen($id)) {
$regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";
@preg_match($regx, $id, $arr_split);
//检查生日日期是否正确
$dtm_birth = "19".$arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
if(!strtotime($dtm_birth))
{
return false;
} else {
return true;
}
} else {
$regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
@preg_match($regx, $id, $arr_split);
$dtm_birth = $arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
if(!strtotime($dtm_birth)) {
return false;
} else {
//检验18位身份证的校验码是否正确。
//校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
$arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
$arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
$sign = 0;
for ( $i = 0; $i < 17; $i++ ) {
$b = (int) $id{$i};
$w = $arr_int[$i];
$sign += $b * $w;
}
$n = $sign % 11;
$val_num = $arr_ch[$n];
if ($val_num != substr($id,17, 1)) {
return false;
} else {
return true;
}
}
}
}
}