5 changed files with 138 additions and 4 deletions
@ -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()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
<?php |
|||
|
|||
namespace app\model; |
|||
|
|||
use think\Model; |
|||
|
|||
class InvoiceIssuance extends Model |
|||
{ |
|||
|
|||
} |
|||
@ -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'] |
|||
]; |
|||
|
|||
} |
|||
Loading…
Reference in new issue