Assoc.php 6.1 KB

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