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 顽皮蛋 */ 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')); } }