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.
126 lines
4.2 KiB
126 lines
4.2 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
|
// +----------------------------------------------------------------------
|
|
// | Author: 萤火科技 <admin@yiovo.com>
|
|
// +----------------------------------------------------------------------
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\model\user;
|
|
|
|
use app\api\model\Order;
|
|
use app\api\service\User as UserService;
|
|
use app\common\model\user\InvoiceOrder as InvoiceOrderModel;
|
|
use app\common\model\user\UserInvoice;
|
|
|
|
/**
|
|
* 用户余额变动明细模型
|
|
* Class BalanceLog
|
|
* @package app\api\model\user
|
|
*/
|
|
class InvoiceOrder extends InvoiceOrderModel
|
|
{
|
|
/**
|
|
* 隐藏字段
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'store_id',
|
|
];
|
|
|
|
public function getList($param = [])
|
|
{
|
|
// 当前用户ID
|
|
$userId = UserService::getCurrentLoginUserId();
|
|
// 获取列表数据
|
|
$query = $this->where('user_id', '=', $userId);
|
|
$list = $query->order(['created_at' => 'desc'])
|
|
->select();
|
|
return $list;
|
|
}
|
|
|
|
public function getDetail($id)
|
|
{
|
|
$info = $this->with(['order.goods'])->where(['id' => $id])->find()->toArray();
|
|
$info['invoice'] = UserInvoice::where(['id' => $info['invoice_id']])->find()->toArray();
|
|
return $info;
|
|
}
|
|
|
|
public function invoicingAdd($data)
|
|
{
|
|
// 当前用户ID
|
|
$userId = UserService::getCurrentLoginUserId();
|
|
$store_id = app()->request->storeId();
|
|
if (empty($data['invoice_id']) || empty($data['order_id'])) {
|
|
$this->error = '请补全信息';
|
|
return false;
|
|
}
|
|
//校验订单信息
|
|
$order = Order::where(['order_id' => $data['order_id'], 'user_id' => $userId])->find();
|
|
if ($order->order_status != 30 || $order->pay_price <= 0) {
|
|
$this->error = '订单状态异常,无法开票';
|
|
return false;
|
|
}
|
|
//校验是否已经打印过该订单
|
|
$has = $this->where(['order_id' => $data['order_id']])->find();
|
|
if ($has) {
|
|
$this->error = '请勿重复申请';
|
|
return false;
|
|
}
|
|
$invoice = UserInvoice::where(['id' => $data['invoice_id']])->find()->toArray();
|
|
$data['type'] = $data['type'] ?? $invoice['type'];
|
|
$data['source'] = $data['source'] ?? $invoice['source'];
|
|
$data['header'] = $data['header'] ?? $invoice['header'];
|
|
$data['order_no'] = $order->order_no;
|
|
$data['price'] = $order->pay_price;
|
|
|
|
return $this->save(array_merge($data, [
|
|
'user_id' => $userId,
|
|
'store_id' => $store_id,
|
|
'created_at' => time(),
|
|
]));
|
|
}
|
|
|
|
public function invoicingEdit($data)
|
|
{
|
|
if (empty($data['header']) || empty($data['id'])) {
|
|
$this->error = '请补全信息';
|
|
return false;
|
|
}
|
|
$userId = UserService::getCurrentLoginUserId();
|
|
$detail = self::get(['user_id' => $userId, 'id' => $data['id']]);
|
|
if (empty($detail)) {
|
|
$this->error = '未找到该抬头';
|
|
return false;
|
|
}
|
|
if ($detail->status == 1) {
|
|
$this->error = '已开票,无法修改';
|
|
return false;
|
|
}
|
|
return $detail->save([
|
|
'type' => $data['type'],
|
|
'source' => $data['source'],
|
|
'header' => $data['header'],
|
|
]) !== false;
|
|
}
|
|
|
|
public function invoicingDel($data) {
|
|
if(empty($data['id'])) {
|
|
$this->error = '参数异常';
|
|
return false;
|
|
}
|
|
|
|
$userId = UserService::getCurrentLoginUserId();
|
|
$detail = self::get(['user_id' => $userId, 'id' => $data['id']]);
|
|
empty($detail) && throwError('未找到该抬头');
|
|
return $detail->delete();
|
|
}
|
|
|
|
|
|
|
|
|
|
} |