Browse Source

申请开票,删除开票

master
wanghongjun 1 year ago
parent
commit
2d736ed8a2
  1. 80
      app/controller/api/InvoiceIssuance.php
  2. 2
      app/controller/wechat/Base.php
  3. 10
      app/model/InvoiceIssuance.php
  4. 43
      app/validate/InvoiceIssuanceValidate.php
  5. 7
      route/apiRoute.php

80
app/controller/api/InvoiceIssuance.php

@ -0,0 +1,80 @@
<?php
namespace app\controller\api;
use app\model\InvoiceIssuance as InvoiceIssuanceModel;
use app\util\ReturnCode;
use app\validate\InvoiceIssuanceValidate;
class InvoiceIssuance extends Base
{
public function add()
{
try {
$params = $this->request->post();
$id = $params['id'] ?? 0;
$wechat_user_id = $this->request->wechat_user_id;
$data = [
'wechat_user_id' => $wechat_user_id,
'project_id' => $params['project_id'],
'pucode_id' => $params['pucode_id'],
];
$where = [['status', '>', 0], ['delete_time', '=', 0]];
if ($id) {
$where[] = ['id', '!=', $id];
}
$query_id = InvoiceIssuanceModel::where($data)->where($where)->value('id');
if ($query_id) {
throw new \Exception('当前开票项目已申请开票');
}
$data['expire_time'] = strtotime($params['expire_time']);
$data['mobile'] = strtotime($params['mobile']);
$data['email'] = strtotime($params['email']);
if ($id) {
validate(InvoiceIssuanceValidate::class)->scene('edit')->check($params);
$data['update_time'] = time();
(new InvoiceIssuanceModel())->update($data, ['id' => $id]);
} else {
validate(InvoiceIssuanceValidate::class)->scene('add')->check($params);
$data['create_time'] = time();
$InvoiceModel = (new InvoiceIssuanceModel())->save($data);
if (!$InvoiceModel) {
throw new \Exception('申请失败');
}
}
return $this->buildSuccess();
} catch (\Exception $e) {
return $this->buildFailed(ReturnCode::INVALID, $e->getMessage());
}
}
public function delete()
{
try {
$params = $this->request->post();
validate(InvoiceIssuanceValidate::class)->scene('delete')->check($params);
$id = $params['id'];
(new InvoiceIssuanceModel())->update(['delete_time' => time()], ['id' => $id]);
return $this->buildSuccess();
} catch (\Exception $e) {
return $this->buildFailed(ReturnCode::INVALID, $e->getMessage());
}
}
}

2
app/controller/wechat/Base.php

@ -67,7 +67,7 @@ class Base extends BaseController {
"aud" => '', //面象的用户,可以为空
"iat" => time(), //签发时间
"nbf" => time() + 3, //在什么时候jwt开始生效 (这里表示生成100秒后才生效)
"exp" => time() + 7200, //token 过期时间
"exp" => 0,//time() + 7200, //token 过期时间
"data" => $data //记录的userid的信息,这里是自已添加上去的,如果有其它信息,可以再添加数组的键值对
);
return JWT::encode($token, $key, "HS384"); //根据参数生成了token,可选:HS256、HS384、HS512、RS256、ES256等

10
app/model/InvoiceIssuance.php

@ -0,0 +1,10 @@
<?php
namespace app\model;
use think\Model;
class InvoiceIssuance extends Model
{
}

43
app/validate/InvoiceIssuanceValidate.php

@ -0,0 +1,43 @@
<?php
namespace app\validate;
use think\Validate;
class InvoiceIssuanceValidate extends Validate
{
/**
* 验证规则.
*/
protected $rule = [
'project_id|开票项目' => 'require|number',
'merge|合并开票' => 'require|number',
'pucode_id|用户编号' => 'require|number',
'expire_time|到期时间' => 'require',
'mobile|手机号' => 'require|mobile',
'email|邮箱' => 'require|email',
'id|发票编号' => 'require|number'
];
/**
* 提示消息.
*/
protected $message = [
];
/**
* 字段描述.
*/
protected $field = [
];
/**
* 验证场景.
*/
protected $scene = [
'add' => ['project_id', 'merge', 'pucode_id', 'expire_time', 'mobile', 'email'],
'edit' => ['project_id', 'merge', 'pucode_id', 'expire_time', 'mobile', 'email', 'id'],
'delete' => ['id']
];
}

7
route/apiRoute.php

@ -7,7 +7,8 @@ use think\facade\Route;
Route::group('api', function() {
// 微信验证路由地址
Route::rule('Wx/verify', 'api.Wx/verify', 'get');
Route::rule('InvoiceIssuance/add', 'api.InvoiceIssuance/add', 'post')->middleware(\app\middleware\WechatAuth::class);
Route::rule('InvoiceIssuance/delete', 'api.InvoiceIssuance/delete', 'post')->middleware(\app\middleware\WechatAuth::class);
//MISS路由定义
Route::miss('api.Miss/index');
})->middleware(app\middleware\ApiResponse::class);
//Route::miss('api.Miss/index');
});//->middleware(app\middleware\ApiResponse::class)

Loading…
Cancel
Save