|
|
@ -3,6 +3,8 @@ |
|
|
namespace app\controller\admin; |
|
|
namespace app\controller\admin; |
|
|
|
|
|
|
|
|
use app\model\WechatPucode; |
|
|
use app\model\WechatPucode; |
|
|
|
|
|
use app\service\invoice\InvoiceIssuanceService; |
|
|
|
|
|
use app\util\ReturnCode; |
|
|
use think\Response; |
|
|
use think\Response; |
|
|
use app\model\InvoiceHead as InvoiceHeadModel; |
|
|
use app\model\InvoiceHead as InvoiceHeadModel; |
|
|
use app\model\WechatUser as WechatUserModel; |
|
|
use app\model\WechatUser as WechatUserModel; |
|
|
@ -25,8 +27,7 @@ class InvoiceHead extends Base |
|
|
$where = []; |
|
|
$where = []; |
|
|
|
|
|
|
|
|
if (isset($param['pucode']) && !empty($param['pucode'])) { |
|
|
if (isset($param['pucode']) && !empty($param['pucode'])) { |
|
|
$wechat_user_ids = WechatPucode::where([['pucode', 'like', "%{$param['pucode']}%"]])->column('wechat_user_id'); |
|
|
$where[] = ['pucode', 'in', explode(',',$param['pucode'])]; |
|
|
$where[] = ['wechat_user_id', 'in', $wechat_user_ids]; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$InvoiceHead = new InvoiceHeadModel(); |
|
|
$InvoiceHead = new InvoiceHeadModel(); |
|
|
@ -40,8 +41,8 @@ class InvoiceHead extends Base |
|
|
if ($WechatUser) { |
|
|
if ($WechatUser) { |
|
|
$item['wechat_user_name'] = $WechatUser['nickname']; |
|
|
$item['wechat_user_name'] = $WechatUser['nickname']; |
|
|
$item['headimgurl'] = $WechatUser['headimgurl']; |
|
|
$item['headimgurl'] = $WechatUser['headimgurl']; |
|
|
|
|
|
$item['phone'] = $WechatUser['phone']; |
|
|
} |
|
|
} |
|
|
$item['pucode'] = WechatPucode::where('wechat_user_id', $item['wechat_user_id'])->value('pucode'); |
|
|
|
|
|
unset($item['wechat_user_id']); |
|
|
unset($item['wechat_user_id']); |
|
|
})->toArray(); |
|
|
})->toArray(); |
|
|
$listInfo = $listObj['data']; |
|
|
$listInfo = $listObj['data']; |
|
|
@ -52,4 +53,110 @@ class InvoiceHead extends Base |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function save(): Response |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
$params = $this->request->post(); |
|
|
|
|
|
$id = $params['id'] ?? ''; |
|
|
|
|
|
$phone = $params['phone']; |
|
|
|
|
|
$pucode = $params['pucode']; |
|
|
|
|
|
$type = $params['type']; |
|
|
|
|
|
$tax_number = $params['tax_number']; |
|
|
|
|
|
$title = $params['title']; |
|
|
|
|
|
|
|
|
|
|
|
// 数据验证 |
|
|
|
|
|
$tax_number_str = $type == 1 ? '身份证号' :'纳税识别号'; |
|
|
|
|
|
$tax_number_rule = $type == 1 ? 'idCard' :'alphaNum'; |
|
|
|
|
|
$rule = [ |
|
|
|
|
|
'phone|手机号' => 'require|mobile', |
|
|
|
|
|
'type|抬头类型' => 'require|number|in:0,1', |
|
|
|
|
|
'title|抬头' => 'require', |
|
|
|
|
|
"tax_number|{$tax_number_str}" => "require|{$tax_number_rule}|length:18" |
|
|
|
|
|
]; |
|
|
|
|
|
validate()->rule($rule)->check($params); |
|
|
|
|
|
|
|
|
|
|
|
if ($type != 1) { |
|
|
|
|
|
// 验证纳税识别号 |
|
|
|
|
|
$str = '0-9A-HJ-NPQRTUWXY'; |
|
|
|
|
|
$pattern = '/^[' . $str . ']{2}\d{6}[' . $str . ']{10}$/'; |
|
|
|
|
|
if (!preg_match($pattern, $tax_number)) { |
|
|
|
|
|
throw new \Exception('纳税人编号格式不符合', ReturnCode::PARAM_INVALID); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$wechat_user_id = (new WechatUserModel())->where(['phone' => $phone, 'delete_time' => 0])->value('id'); |
|
|
|
|
|
|
|
|
|
|
|
if (!$wechat_user_id) { |
|
|
|
|
|
throw new \Exception('当前手机号用户不存在', ReturnCode::RECORD_NOT_FOUND); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$feeUserInfo = (new InvoiceIssuanceService())->getFeeUserData($pucode); |
|
|
|
|
|
$address = isset($feeUserInfo['MaillingAddress']) && !empty($feeUserInfo['MaillingAddress']) ? $feeUserInfo['MaillingAddress']: ''; |
|
|
|
|
|
$telephone = isset($feeUserInfo['Telephone']) && !empty($feeUserInfo['Telephone']) ? $feeUserInfo['Telephone']: ''; |
|
|
|
|
|
$bank_name = isset($feeUserInfo['BankName']) && !empty($feeUserInfo['BankName']) ? $feeUserInfo['BankName']: ''; |
|
|
|
|
|
$bank_account = isset($feeUserInfo['BankAccountCode']) && !empty($feeUserInfo['BankAccountCode']) ? $feeUserInfo['BankAccountCode']: ''; |
|
|
|
|
|
|
|
|
|
|
|
// 验证手机号和用户编号是否有关联 |
|
|
|
|
|
if ($telephone) { |
|
|
|
|
|
$telephoneArr = explode(',', $telephone); |
|
|
|
|
|
if (!in_array($phone, $telephoneArr)) { |
|
|
|
|
|
throw new \Exception('当前手机号未关联输入的用户编号', ReturnCode::RECORD_NOT_FOUND); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 保存操作 |
|
|
|
|
|
$query = [ |
|
|
|
|
|
'pucode' => $pucode, |
|
|
|
|
|
'wechat_user_id' => $wechat_user_id, |
|
|
|
|
|
]; |
|
|
|
|
|
$InvoiceHeadId = (new InvoiceHeadModel())->where($query)->value('id'); |
|
|
|
|
|
if (!$id && $InvoiceHeadId) $id = $InvoiceHeadId; |
|
|
|
|
|
|
|
|
|
|
|
if ($id) { |
|
|
|
|
|
if (!is_numeric($id)) { |
|
|
|
|
|
throw new \Exception('编号数据错误', ReturnCode::RECORD_NOT_FOUND); |
|
|
|
|
|
} |
|
|
|
|
|
$InvoiceHeadData = (new InvoiceHeadModel())->where(['id' => $id])->find(); |
|
|
|
|
|
if (!$InvoiceHeadData) { |
|
|
|
|
|
throw new \Exception('数据不存在', ReturnCode::RECORD_NOT_FOUND); |
|
|
|
|
|
} |
|
|
|
|
|
// 更新 |
|
|
|
|
|
$InvoiceHeadData->pucode = $pucode; |
|
|
|
|
|
$InvoiceHeadData->type = $type; |
|
|
|
|
|
$InvoiceHeadData->title = $title; |
|
|
|
|
|
$InvoiceHeadData->tax_number = $tax_number; |
|
|
|
|
|
if (!$InvoiceHeadData->address) { |
|
|
|
|
|
$InvoiceHeadData->address = $address; |
|
|
|
|
|
} |
|
|
|
|
|
if (!$InvoiceHeadData->telephone) { |
|
|
|
|
|
$InvoiceHeadData->telephone = $telephone; |
|
|
|
|
|
} |
|
|
|
|
|
if (!$InvoiceHeadData->bank_name) { |
|
|
|
|
|
$InvoiceHeadData->bank_name = $bank_name; |
|
|
|
|
|
} |
|
|
|
|
|
if (!$InvoiceHeadData->bank_account) { |
|
|
|
|
|
$InvoiceHeadData->bank_account = $bank_account; |
|
|
|
|
|
} |
|
|
|
|
|
$InvoiceHeadData->save(); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 新增 |
|
|
|
|
|
$data['type'] = $type; |
|
|
|
|
|
$data['title'] = $title; |
|
|
|
|
|
$data['tax_number'] = $tax_number; |
|
|
|
|
|
$data['address'] = $address; |
|
|
|
|
|
$data['telephone'] = $telephone; |
|
|
|
|
|
$data['bank_name'] = $bank_name; |
|
|
|
|
|
$data['bank_account'] = $bank_account; |
|
|
|
|
|
$data['wechat_user_id'] = $wechat_user_id; |
|
|
|
|
|
$data['create_time'] = time(); |
|
|
|
|
|
$data['pucode'] = $pucode; |
|
|
|
|
|
InvoiceHeadModel::create($data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $this->buildSuccess(); |
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
return $this->buildFailed($e->getCode(), $e->getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |