Assoc.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\model;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class Assoc extends Model
  9. {
  10. protected $createTime="addtime";
  11. protected $updateTime="updatetime";
  12. public static function subOrder($invNo)
  13. {
  14. $list = self::where(["viceCode"=>$invNo,"status"=>1,"type"=>"1"])->field("id,orderCode,cancel_fee")->select();
  15. if(!$list->isEmpty()){
  16. $order= QrdInfo::whereIn("sequenceNo",$list->column("orderCode"))
  17. ->column("id,sequenceNo,winv_fee,inv_fee,ainv_fee,invtime,inv_status,status,pay_status","sequenceNo");
  18. foreach ($list as $k=>$v){
  19. if(!isset($order[$v['orderCode']])) throw new \Exception("订单{$v['orderCode']}未找到数据");
  20. if($v['cancel_fee']>0){
  21. if($v['cancel_fee']>$order[$v['orderCode']]['inv_fee']){
  22. throw new \Exception("订单{$v['orderCode']}开票金额{$v['cancel_fee']}超过实际开票中金额{$order[$v['orderCode']]['inv_fee']}");
  23. }
  24. $order[$v['orderCode']]['inv_fee']-=$v['cancel_fee'];
  25. $order[$v['orderCode']]['ainv_fee']+=$v['cancel_fee'];
  26. $order[$v['orderCode']]['invtime']=date("Y-m-d H:i:s");
  27. $order[$v['orderCode']]['inv_status']= $order[$v['orderCode']]['winv_fee']==0 &&$order[$v['orderCode']]['inv_fee']==0 ? 3 : 2;
  28. $order[$v['orderCode']]['status']= $order[$v['orderCode']]['pay_status']==0 &&$order[$v['orderCode']]['inv_status']==0 ? 0 : 1;
  29. }
  30. }
  31. (new QrdInfo())->saveAll($order);
  32. self::where(["id"=>$list->column('id')])->save(['status'=>2,'assoc_time'=>date("Y-m-d H:i:s")]);
  33. }
  34. }
  35. public static function addOrder($invNo)
  36. {
  37. $list = self::where(["viceCode"=>$invNo,"status"=>1,"type"=>"1"])->field('id,orderCode,cancel_fee')->select();
  38. if(!$list->isEmpty()){
  39. $order= QrdInfo::whereIn('sequenceNo',$list->column('orderCode'))
  40. ->column('id,sequenceNo,winv_fee,inv_fee,ainv_fee,invtime,inv_status,status,pay_status','sequenceNo');
  41. foreach ($list as $k=>$v){
  42. if(!isset($order[$v['orderCode']])) throw new \Exception("订单{$v['orderCode']}未找到数据");
  43. if($v['cancel_fee']>0){
  44. if($v['cancel_fee']>$order[$v['orderCode']]['inv_fee']){
  45. throw new \Exception("订单{$v['orderCode']}开票金额{$v['cancel_fee']}超过实际开票中金额{$order[$v['orderCode']]['inv_fee']}");
  46. }
  47. $order[$v['orderCode']]['inv_fee']-=$v['cancel_fee'];
  48. $order[$v['orderCode']]['winv_fee']+=$v['cancel_fee'];
  49. $order[$v['orderCode']]['inv_status']= $order[$v['orderCode']]['ainv_fee']==0 &&$order[$v['orderCode']]['inv_fee']==0 ? 1 : 2;
  50. $order[$v['orderCode']]['status']= $order[$v['orderCode']]['pay_status']==0 &&$order[$v['orderCode']]['inv_status']==0 ? 0 : 1;
  51. }
  52. }
  53. (new QrdInfo())->saveAll($order);
  54. self::where(['id'=>$list->column('id')])->save(['status'=>3]);
  55. InvoiceGood::where(['is_del' => 0,'invNo' => $invNo,'orderCode' => $list->column('orderCode')])->save(["goodNum"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
  56. }
  57. }
  58. //开票流程已走完 取消发票 从已开票中直接扣除到未开票中
  59. public static function addOrderWinv($invNo)
  60. {
  61. $list = self::where(['viceCode'=>$invNo,'status'=>2,'type'=>'1'])->field('id,orderCode,cancel_fee')->select();
  62. if(!$list->isEmpty()){
  63. $order= QrdInfo::whereIn('sequenceNo',$list->column('orderCode'))
  64. ->column('id,sequenceNo,winv_fee,inv_fee,ainv_fee,invtime,inv_status,status,pay_status','sequenceNo');
  65. foreach ($list as $k=>$v){
  66. if(!isset($order[$v['orderCode']])) throw new \Exception("订单{$v['orderCode']}未找到数据");
  67. if($v['cancel_fee']>0){
  68. if($v['cancel_fee']>$order[$v['orderCode']]['ainv_fee']){
  69. throw new \Exception("订单{$v['orderCode']}开票金额{$v['cancel_fee']}超过实际开票金额{$order[$v['orderCode']]['ainv_fee']}");
  70. }
  71. $order[$v['orderCode']]['ainv_fee']-=$v['cancel_fee'];
  72. $order[$v['orderCode']]['winv_fee']+=$v['cancel_fee'];
  73. $order[$v['orderCode']]['inv_status']= $order[$v['orderCode']]['ainv_fee']==0 &&$order[$v['orderCode']]['inv_fee']==0 ? 1 : 2;
  74. $order[$v['orderCode']]['status']= $order[$v['orderCode']]['pay_status']==0 &&$order[$v['orderCode']]['inv_status']==0 ? 0 : 1;
  75. }
  76. }
  77. (new QrdInfo())->saveAll($order);
  78. self::where(['id'=>$list->column('id')])->save(['status'=>3]);
  79. InvoiceGood::where(['is_del' => 0,'invNo' => $invNo,'orderCode' => $list->column('orderCode')])->save(['goodNum'=>0,'updatetime'=>date('Y-m-d H:i:s')]);
  80. }
  81. }
  82. public static function CheckQrd($orderCode,&$data)
  83. {
  84. $asscoinfo =self::where(['orderCode'=>$orderCode,'status'=>[1,2],'is_del'=>0])->column
  85. ('viceCode','type');
  86. if(isset($asscoinfo[1])){
  87. $pool = InvoicePool::where('invNo',$asscoinfo[1])->findOrEmpty();
  88. $temp=['type'=>'结算销售单开票申请','username'=> $pool->apply_name,'orderCode'=>$asscoinfo[1],'companyName'=>$pool->inv_company];
  89. $data[]=$temp;
  90. }
  91. if(isset($asscoinfo[2])){
  92. $pool = TradePool::with(["company"])->where('logNo',$asscoinfo[2])->findOrEmpty();
  93. $temp=['type'=>'结算销售单资金认领','username'=> $pool->apply_name,'orderCode'=>$asscoinfo[2],'companyName'=>$pool->companyName];
  94. $data[]=$temp;
  95. }
  96. }
  97. }