|
|
|
@ -12,8 +12,10 @@ 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; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 用户余额变动明细模型 |
|
|
|
@ -41,15 +43,40 @@ class InvoiceOrder extends InvoiceOrderModel |
|
|
|
|
return $list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function add($data) |
|
|
|
|
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['header']) || empty($data['duty_no'])) { |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
return $this->save(array_merge($data, [ |
|
|
|
|
'user_id' => $userId, |
|
|
|
|
'store_id' => $store_id, |
|
|
|
@ -57,25 +84,26 @@ class InvoiceOrder extends InvoiceOrderModel |
|
|
|
|
])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function edit($data) |
|
|
|
|
public function invoicingEdit($data) |
|
|
|
|
{ |
|
|
|
|
if (empty($data['header']) || empty($data['duty_no'])) { |
|
|
|
|
if (empty($data['header']) || empty($data['id'])) { |
|
|
|
|
$this->error = '请补全信息'; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$userId = UserService::getCurrentLoginUserId(); |
|
|
|
|
$detail = self::get(['user_id' => $userId, 'id' => $data['id']]); |
|
|
|
|
empty($detail) && throwError('未找到该抬头'); |
|
|
|
|
|
|
|
|
|
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'], |
|
|
|
|
'duty_no' => $data['duty_no'], |
|
|
|
|
'bank_name' => $data['bank_name'] ?? '', |
|
|
|
|
'bank_no' => $data['bank_no'] ?? '', |
|
|
|
|
'address' => $data['address'] ?? '', |
|
|
|
|
'phone' => $data['phone'] ?? '', |
|
|
|
|
]) !== false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|