|
@@ -4,9 +4,15 @@
|
|
|
namespace app\cxinv\controller;
|
|
|
|
|
|
|
|
|
+use app\cxinv\model\InvoiceInfo;
|
|
|
use app\cxinv\model\InvoiceOrder;
|
|
|
use app\cxinv\model\InvoiceItem;
|
|
|
-use app\cxinv\model\PayReturn;use app\cxinv\model\RoleAction;use app\user\model\AccountCompany;use app\user\model\Business;use app\user\model\Headquarters;use think\App;
|
|
|
+use app\cxinv\model\PayReturn;
|
|
|
+use app\cxinv\model\RoleAction;
|
|
|
+use app\user\model\AccountCompany;
|
|
|
+use app\user\model\Business;
|
|
|
+use app\user\model\Headquarters;
|
|
|
+use think\App;
|
|
|
use think\facade\Validate;
|
|
|
class Invoice extends Base{
|
|
|
public function __construct(App $app) {
|
|
@@ -41,9 +47,15 @@ class Invoice extends Base{
|
|
|
"invoice_subtotal|发票税后金额"=>"float",
|
|
|
"check_code|校验码"=>"max:255"
|
|
|
]);
|
|
|
+ $number= array_column($param['list'],'invoice_number');
|
|
|
+ if (count($number)!=count(array_unique($number))) return error("发票号码重复");
|
|
|
+ $invoice = $this->model
|
|
|
+ ->whereIn("invoice_number", $number)
|
|
|
+ ->whereIn("status",[0,1,2,3,4])->column("invoice_number");
|
|
|
foreach ($param['list'] as $k=>$v){
|
|
|
if(!$valid->check($v)) return error($valid->getError());
|
|
|
validate_invoice_info($v,$return);
|
|
|
+ if(!empty( $invoice) && in_array($v['invoice_number'],$invoice)) return error($v['invoice_number'].":发票已存在");
|
|
|
if($return['code']!=0) return error($v['invoice_number'].":".$return['message']);
|
|
|
$param['list'][$k]['InvCode']=makeNo("FP",str_pad($k,4,"0",STR_PAD_RIGHT));
|
|
|
$param['list'][$k]['apply_id']=$this->uid;
|
|
@@ -54,7 +66,7 @@ class Invoice extends Base{
|
|
|
}
|
|
|
public function save(){
|
|
|
$param= $this->request->param([
|
|
|
- "InvCode"=>"",
|
|
|
+ "id"=>"",
|
|
|
"invoice_code"=>"",
|
|
|
"invoice_number"=>"",
|
|
|
"invoice_type"=>"",
|
|
@@ -90,6 +102,12 @@ class Invoice extends Base{
|
|
|
$invoice->open_date=$param['open_date'];
|
|
|
$invoice->invoice_subtotal=$param['invoice_subtotal'];
|
|
|
$invoice->check_code=$param['check_code'];
|
|
|
+ $bool = $this->model
|
|
|
+ ->whereIn('invoice_number', $param['invoice_number'])
|
|
|
+ ->whereIn('status',[0,1,2,3,4])
|
|
|
+ ->where('id', '<>', $invoice->id)
|
|
|
+ ->findOrEmpty();
|
|
|
+ if(!$bool->isEmpty()) return error("发票号码与{$bool->InvCode}重复");
|
|
|
}
|
|
|
if($param['status']==1){
|
|
|
$invoice->companyNo=$param['companyNo'];
|
|
@@ -125,7 +143,7 @@ class Invoice extends Base{
|
|
|
(new InvoiceOrder)->saveAll($param['ItemRemark']);
|
|
|
};
|
|
|
}
|
|
|
- if(in_array($param['status'],[6,7])){
|
|
|
+ if(in_array($param['status'],[5,6,7])){
|
|
|
InvoiceItem::rmInvoice($param['hpNo']);
|
|
|
}
|
|
|
$this->model->commit();
|
|
@@ -157,6 +175,7 @@ class Invoice extends Base{
|
|
|
if(!$valide->check($param)) return error($valide->getError());
|
|
|
$info=$this->model->with(["items"])->where("InvCode",$param['InvCode'])->findOrEmpty();
|
|
|
if($info->isEmpty()) return error("回票编号不存在");
|
|
|
+ $info['ticket'] = InvoiceInfo::where("hpNo",$param['InvCode'])->findOrEmpty();
|
|
|
return success("获取成功",$info);
|
|
|
}
|
|
|
|