You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
5.3 KiB
151 lines
5.3 KiB
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\command;
|
|
|
|
use app\model\InvoiceHead;
|
|
use app\model\WechatPucode;
|
|
use app\service\invoice\InvoiceIssuanceService;
|
|
use app\service\user\UserService;
|
|
use app\service\webService\FeeService;
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\input\Argument;
|
|
use think\console\input\Option;
|
|
use think\console\Output;
|
|
use think\File;
|
|
|
|
class ExportExcel extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
// 指令配置
|
|
$this->setName('exportexcel')
|
|
->setDescription('the exportexcel command');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
|
|
set_time_limit(0); // 无时间限制
|
|
ini_set('memory_limit', '512M'); // 增加内存限制
|
|
$this->runData();
|
|
//$this->runHeadData();
|
|
// 指令输出
|
|
$output->writeln('exportexcel');
|
|
}
|
|
|
|
protected function runData()
|
|
{
|
|
$filename = 'export_data.xls';
|
|
$path = public_path() . '/' . $filename;
|
|
$file = new File($path);
|
|
|
|
$fileInfo = [];
|
|
//$fileInfo['name'] = $file->getOriginalName(); //上传文件名
|
|
//$fileInfo['type'] = $file->getOriginalMime(); //上传文件类型信息
|
|
$fileInfo['tmp_name'] = $file->getPathname();
|
|
//$fileInfo['size'] = $file->getSize();
|
|
$obj = \PHPExcel_IOFactory::createReader('Excel5');
|
|
$obj_PHPExcel = $obj->load($fileInfo['tmp_name']);
|
|
$excel_array = $obj_PHPExcel->getSheet(0)->toArray();
|
|
|
|
$error_array = [];
|
|
foreach ($excel_array as $key => $data) {
|
|
$key = $key + 1;
|
|
$phone = $data[0];
|
|
$email = $data[1] ?? '';
|
|
$pucode = $data[2];
|
|
$taxId = $data[3] ?? '';
|
|
$type = $data[4];
|
|
// 验证不能为空
|
|
if (empty($phone) || empty($pucode) || empty($type)) {
|
|
continue;
|
|
}
|
|
if (!preg_match('/^1[3-9]\d{9}$/', $phone)) {
|
|
$error_array[] = "第{$key}行:手机号格式不符合";
|
|
continue;
|
|
}
|
|
|
|
$FeeService = new FeeService($pucode);
|
|
$feeUserInfo = $FeeService->getUsers();
|
|
|
|
if ($feeUserInfo['UserCode'] != $pucode) {
|
|
$error_array[] = "第{$key}行:用户编号不存在";
|
|
continue;
|
|
}
|
|
if ($feeUserInfo['CellPhone'] != $phone) {
|
|
$error_array[] = "第{$key}行:手机号或用户编号错误";
|
|
continue;
|
|
}
|
|
if ($email) {
|
|
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
|
|
$error_array[] = "第{$key}行:邮箱格式不符合";
|
|
continue;
|
|
}
|
|
}
|
|
$typeArr = ['单位', '个人'];
|
|
if (!in_array($type, $typeArr)) {
|
|
$error_array[] = "第{$key}行:抬头类型不符合";
|
|
continue;
|
|
}
|
|
$type = array_search($type, $typeArr);
|
|
if ($taxId) {
|
|
if ($type === 1) {
|
|
$pattern = '/^\d{15}$|^\d{17}[\dXx]$/';
|
|
if (!preg_match($pattern, $taxId)) {
|
|
$error_array[] = "第{$key}行:纳税人编号格式不符合";
|
|
continue;
|
|
}
|
|
} else {
|
|
$str = '0-9A-HJ-NPQRTUWXY';
|
|
$pattern = '/^[' . $str . ']{2}\d{6}[' . $str . ']{10}$/';
|
|
if (!preg_match($pattern, $taxId)) {
|
|
$error_array[] = "第{$key}行:纳税人编号格式不符合";
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
UserService::addUser((int)$phone, $email, $pucode, $taxId, (int)$type);
|
|
}
|
|
|
|
if (!empty($error_array)) {
|
|
\think\facade\Log::info(json_encode($error_array));
|
|
}
|
|
}
|
|
|
|
protected function runHeadData()
|
|
{
|
|
$data = InvoiceHead::where('pucode','=','')->select()->toArray();
|
|
foreach ($data as $item) {
|
|
|
|
$wechatPucode = WechatPucode::where('wechat_user_id',$item['wechat_user_id'])->select()->toArray();
|
|
foreach ($wechatPucode as $pucodeItem) {
|
|
|
|
$pucode = $pucodeItem['pucode'];
|
|
try {
|
|
$feeUserInfo = (new InvoiceIssuanceService())->getFeeUserData($pucode);
|
|
} catch (\Exception $e) {
|
|
// 不存在跳过
|
|
continue;
|
|
}
|
|
$CertificateCode = $feeUserInfo['CertificateCode'] ?? '';
|
|
$UserName = $feeUserInfo['UserName'] ?? '';
|
|
if (empty($UserName) && empty($CertificateCode)) {
|
|
continue;
|
|
}
|
|
// 存在更新pucode
|
|
if ($CertificateCode == $item['tax_number'] || $UserName == $item['title']) {
|
|
$save = ['pucode' => $pucode];
|
|
if (empty($item['tax_number'])) {
|
|
$save['tax_number'] = $CertificateCode;
|
|
}
|
|
if (empty($item['title'])) {
|
|
$save['title'] = $UserName;
|
|
}
|
|
InvoiceHead::update($save,['id' => $item['id']]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|