diff --git a/app/controller/api/InvoiceIssuance.php b/app/controller/api/InvoiceIssuance.php index cb457c3..b33b7a4 100644 --- a/app/controller/api/InvoiceIssuance.php +++ b/app/controller/api/InvoiceIssuance.php @@ -2,8 +2,10 @@ namespace app\controller\api; +use app\model\InvoiceHead; use app\model\InvoiceIssuance as InvoiceIssuanceModel; use app\util\ReturnCode; +use app\validate\InvoiceHeadValidate; use app\validate\InvoiceIssuanceValidate; class InvoiceIssuance extends Base @@ -35,9 +37,14 @@ class InvoiceIssuance extends Base throw new \Exception('当前开票项目已申请开票'); } - $data['expire_time'] = strtotime($params['expire_time']); - $data['mobile'] = strtotime($params['mobile']); - $data['email'] = strtotime($params['email']); + $data['expire_time'] = strtotime($params['expire_time']); + $data['mobile'] = $params['mobile']; + $data['email'] = $params['email']; + + //验证 、 新建抬头、获取抬头id + validate(InvoiceHeadValidate::class)->scene('type')->check($data); + validate(InvoiceHeadValidate::class)->scene('type'.$data['type'])->check($data); + $data['invoice_head_id'] = InvoiceHead::createHead($wechat_user_id,$data); if ($id) { validate(InvoiceIssuanceValidate::class)->scene('edit')->check($params); diff --git a/app/model/InvoiceHead.php b/app/model/InvoiceHead.php new file mode 100644 index 0000000..f26423a --- /dev/null +++ b/app/model/InvoiceHead.php @@ -0,0 +1,37 @@ + $data['type'], + 'title' => $data['title'], + 'tax_number' => $data['tax_number'], + 'wechat_user_id' => $wechat_user_id + ]; + + $id = self::where($param)->value('id'); + if ($id) { + return $id; + } + + $param['address'] = $data['address'] ?? ''; + $param['telephone'] = $data['telephone'] ?? ''; + $param['bank_name'] = $data['bank_name'] ?? ''; + $param['bank_account'] = $data['bank_account'] ?? ''; + $param['create_time'] = time(); + + + $model = self::create($param); + + return $model->where($param)->value('id'); + } + +} \ No newline at end of file diff --git a/app/validate/InvoiceHeadValidate.php b/app/validate/InvoiceHeadValidate.php new file mode 100644 index 0000000..ed705ec --- /dev/null +++ b/app/validate/InvoiceHeadValidate.php @@ -0,0 +1,45 @@ + 'require|in:1,2', + 'title|抬头名称' => 'require', + 'tax_number|税号' => 'require|alphaNum|length:18', + 'address|地址' => 'require', + 'telephone|电话' => 'require|alphaDash', + 'bank_name|开户行' => 'require', + 'bank_account|账户' => 'require' + ]; + + /** + * 提示消息. + */ + protected $message = [ + ]; + + /** + * 字段描述. + */ + protected $field = [ + ]; + + /** + * 验证场景. + */ + protected $scene = [ + 'type1' => ['title','tax_number','address','telephone','bank_name','bank_account'], + 'type2' => ['title','tax_number'], + 'type' => ['type'] + ]; + +} \ No newline at end of file