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.

195 lines
6.9 KiB
PHTML

2 years ago
<?php
namespace Admin\Event;
use Think\Controller;
/**
* 后台事件控制器
* @author 王贺
*/
class SendEvent extends Controller
{
/*
*自选
*/
public function add1()
{
$account = trim($_POST['account']);
$amount = $_POST['amount'];
if ($account == "") {
$this->error("玩家账号不能为空", U('Deposit/send_lists'));
}
if(!is_check_account($account)){
$this->error("账号不存在", U('Deposit/send_lists'));
}
if (!is_numeric($amount) || $amount <= 0 || !preg_match('/^[1-9](\d+)?$/',$amount)) {
$this->error("请输入大于0的整数", U("Deposit/send_lists"));
return false;
}
$add['order_number'] = "ZF_" . build_order_no();
$add['pay_order_number'] = build_order_no();
$add['user_id'] = get_user_id($account);
$add['user_account'] = $account;
$add['amount'] = $amount;
$add['status'] = 0;
$add['op_id'] = UID;
$add['op_account'] = session("user_auth.username");
$add['create_time'] = NOW_TIME;
$prov = M("provide_user", "tab_")->add($add);
$this->success("提交成功", U("Deposit/lists_sen",['type'=>2]));
}
/**
* 多用户
*/
public function add2()
{
$account = $_POST['pay_names'];
$amount = $_POST['amountt'];
if (empty($account)) {
$this->error("充值人员不能为空");
}
if ($amount <= 0 || !preg_match('/^[1-9](\d+)?$/',$amount)) {
$this->error("请输入大于0的整数");
}
$namearr = explode("\n", $account);
static $a = 0;
for ($i = 0; $i < count($namearr); $i++) {
$uid = check_account_is_existence(str_replace(array("\r\n", "\r", "\n"), "", $namearr[$i]));
if($uid>0){
$add['pay_order_number'] = build_order_no();
$add['order_number'] = "ZF_" . build_order_no();
$add['user_account'] = $namearr[$i];
$add['user_id'] = $uid;
$add['amount'] = $amount;
$add['status'] = 0;
$add['op_id'] = UID;
$add['op_account'] = session("user_auth.username");
$add['create_time'] = NOW_TIME;
$prov = M("provide_user", "tab_")->add($add);
if ($prov) {
$a++;
}
}
}
$b = count($namearr) - $a;
$this->success("成功"."{$a}"."失败"."{$b}",U("Deposit/lists_sen/type/2"));
}
/**
* 内充管理---导入Excel
* @author 顽皮蛋 <shf_l@163.com>
*/
public function add3()
{
header("Content-Type:text/html;charset=utf-8");
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3145728;// 设置附件上传大小
$upload->exts = array('xls', 'xlsx');// 设置附件上传类
$upload->rootPath = './Uploads/'; // 设置附件上传目录
$upload->savePath = 'excel/'; // 设置附件上传目录
// 上传文件
$info = $upload->uploadOne($_FILES['excelData']);
$filename = './Uploads/' . $info['savepath'] . $info['savename'];
$exts = $info['ext'];
if (!$info) {// 上传错误提示错误信息
if ($upload->getError() != "非法上传文件!"){
$this->error($upload->getError());
}
} else {// 上传成功
$this->charge_import($filename, $exts);
}
}
//导入数据方法
protected function charge_import($filename, $exts = 'xls')
{
//导入PHPExcel类库因为PHPExcel没有用命名空间只能inport导入
//import("Org.Util.PHPExcel");
vendor("PHPExcel.PHPExcel");
//创建PHPExcel对象注意不能少了\
$PHPExcel = new \PHPExcel();
//如果excel文件后缀名为.xls导入这个类
if ($exts == 'xls') {
//import("Org.Util.PHPExcel.Reader.Excel5");
$PHPReader = new \PHPExcel_Reader_Excel5();
} else if ($exts == 'xlsx') {
//import("Org.Util.PHPExcel.Reader.Excel2007");
$PHPReader = new \PHPExcel_Reader_Excel2007();
}
//载入文件
$PHPExcel = $PHPReader->load($filename);
//获取表中的第一个工作表如果要获取第二个把0改为1依次类推
$currentSheet = $PHPExcel->getSheet(0);
//获取总列数
$allColumn = $currentSheet->getHighestColumn();
//获取总行数
$allRow = $currentSheet->getHighestRow();
//循环获取表中的数据,$currentRow表示当前行从哪行开始读取数据索引值从0开始
for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {
//从哪列开始A表示第一列
for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
//数据坐标
$address = $currentColumn . $currentRow;
//读取到的数据,保存到数组$arr中
$data[$currentRow][$currentColumn] = $currentSheet->getCell($address)->getValue();
}
}
$this->save_import($data);
}
//保存导入数据并返回错误信息
public function save_import($data)
{
unset($data[1]);
$errorNum = 0;
$succNum = 0;
$errorList = array();//存储错误数据;
foreach ($data as $k => $v) {
$errorList[$errorNum]['A'] = $v['A'];
$errorList[$errorNum]['B'] = $v['B'];
if (!is_check_account($v['A'])) {//用户名不存在
$errorList[$errorNum]['D'] = '用户名不存在';
$errorNum++;
continue;
}
if ($v['B'] <= 0 || !preg_match('/^[1-9](\d+)?$/',$v['B'])) {//金额有问题
$errorList[$errorNum]['D'] = '金额必须是大于0的整数';
$errorNum++;
continue;
}
$succNum++;
$arr['user_account'] = $v['A'];
$arr['op_id'] = UID;
$arr['op_account'] = session("user_auth.username");
$arr['user_nickname'] = get_user_nickname($v['A']);
$arr['user_id'] = get_user_id($v['A']);
$arr['pay_order_number'] = build_order_no();
$arr['order_number'] = "ZF_" . build_order_no();
$arr['amount'] = $v['B'];
$arr['create_time'] = NOW_TIME;
M('provide_user','tab_')->add($arr);
}
$a = json_encode($errorList);
$json = urlencode(json_encode($errorList));
$this->assign('errorNum', $errorNum);
$this->assign('succNum', $succNum);
$this->assign('status', 1);
$this->assign('json', $json);
$this->success('成功:' . $succNum . ';失败:' . $errorNum, U('Deposit/lists_sen/type/2'));
}
}