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.
yanzong/app/api/model/user/InvoiceOrder.php

110 lines
3.8 KiB

11 months ago
<?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;
11 months ago
use app\api\model\Order;
11 months ago
use app\api\service\User as UserService;
use app\common\model\user\InvoiceOrder as InvoiceOrderModel;
11 months ago
use app\common\model\user\UserInvoice;
11 months ago
/**
* 用户余额变动明细模型
* 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;
}
11 months ago
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)
11 months ago
{
// 当前用户ID
$userId = UserService::getCurrentLoginUserId();
$store_id = app()->request->storeId();
11 months ago
if (empty($data['invoice_id']) || empty($data['order_id'])) {
11 months ago
$this->error = '请补全信息';
return false;
}
11 months ago
//校验订单信息
$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;
11 months ago
return $this->save(array_merge($data, [
'user_id' => $userId,
'store_id' => $store_id,
'created_at' => time(),
]));
}
11 months ago
public function invoicingEdit($data)
11 months ago
{
11 months ago
if (empty($data['header']) || empty($data['id'])) {
11 months ago
$this->error = '请补全信息';
return false;
}
$userId = UserService::getCurrentLoginUserId();
$detail = self::get(['user_id' => $userId, 'id' => $data['id']]);
11 months ago
if (empty($detail)) {
$this->error = '未找到该抬头';
return false;
}
if ($detail->status == 1) {
$this->error = '已开票,无法修改';
return false;
}
11 months ago
return $detail->save([
'type' => $data['type'],
'source' => $data['source'],
'header' => $data['header'],
]) !== false;
}
}