InvoiceOrder.php 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\admin\model;
  3. use think\model\concern\SoftDelete;
  4. class InvoiceOrder extends \think\Model{
  5. use SoftDelete;
  6. protected $createTime='createTime';
  7. protected $updateTime='updateTime';
  8. protected $autoWriteTimestamp=true;
  9. protected $deleteTime='delete_time';
  10. protected $append=["merge_code","short_name","cat_code","cat_name","tax","inv_good_name"];
  11. public function ItemInfo(){
  12. return $this->hasOne('InvoiceItem',"id",'itemId');
  13. }
  14. public static function getInvoiceOrderTotalFee($code){
  15. $banance = (new InvoiceOrder)->where(['code'=>$code,'status'=>[1,2]])->field('sum(ifnull(total_amount-balance_amount,0)) as total_amount')->find();
  16. return $banance['total_amount']??"0";
  17. }
  18. public function getMergeCodeAttr($value,$data){
  19. return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("merge_code","");
  20. }
  21. public function getShortNameAttr($value,$data){
  22. return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("short_name","");
  23. }
  24. public function getCatCodeAttr($value,$data){
  25. return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("cat_code","");
  26. }
  27. public function getCatNameAttr($value,$data){
  28. return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("cat_name","");
  29. }
  30. public function getTaxAttr($value,$data){
  31. return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("tax","");
  32. }
  33. public function getInvGoodNameAttr($value,$data){
  34. return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("inv_good_name","");
  35. }
  36. public static function getNumAttr($val){
  37. return strval(floatval($val));
  38. }
  39. public static function setDiffInfoAttr($val){
  40. return json_encode($val,JSON_UNESCAPED_UNICODE);
  41. }
  42. public static function getDiffInfoAttr($val){
  43. return json_decode($val,true);
  44. }
  45. public static function getOrderInfo($code,$orderCode,$type){
  46. if($type==1){
  47. $info=InvoiceGood::alias('a')
  48. ->join('qrd_info b','a.orderCode=b.sequenceNo','left')
  49. ->join('order_category c','b.sequenceNo=c.code and b.goodNo=c.spuCode and c.order_type=1','left')
  50. ->where(["invNo"=>$code,"a.orderCode"=>$orderCode])
  51. ->where([['a.goodNum','>',0],['a.is_del','=',0]])
  52. ->field('b.sequenceNo,b.goodNo,b.goodName,a.goodNum,a.goodPrice,a.totalPrice,c.merge_code,c.cat_code,c.cat_name,c.short_name,c.tax,c.inv_good_name')
  53. ->findOrEmpty();
  54. } else{
  55. $payNo = PayInvoice::where(['hpNo'=>$code])->value("payNo","");
  56. $info = PayInfo::alias('a')
  57. ->join('cgd_info b','a.cgdNo=b.sequenceNo','left')
  58. ->join('order_category c','b.sequenceNo=c.code and b.goodNo=c.spuCode and c.order_type=2','left')
  59. ->where([['a.status','=',1],['a.is_del','=',0],['a.payNo',"=",$payNo ],['a.cgdNo',"=",$orderCode]])
  60. ->field('b.sequenceNo,b.goodNo,b.goodName,(b.goodNum-thNum) as goodNum,b.goodPrice,b.totalPrice,
  61. c.merge_code,c.cat_code,c.cat_name,c.short_name,c.tax,c.inv_good_name')
  62. ->findOrEmpty();
  63. }
  64. if(!$info->isEmpty())$info['balance_amount']= bcsub($info['totalPrice'],InvoiceOrder::getInvoiceOrderTotalFee($info['sequenceNo']),2);
  65. return $info;
  66. }
  67. public static function CheckOrder($code,&$data){
  68. $InvoiceOrder = InvoiceOrder::with(['ItemInfo'])->where(['code'=>$code,'status'=>[1,2]])->select();
  69. if(!$InvoiceOrder->isEmpty()){
  70. $hpinfo=[];
  71. foreach ($InvoiceOrder as $item){
  72. if(isset($hpinfo[$item->ItemInfo->invoiceCode]))continue;
  73. $hpinfo[$item->ItemInfo->invoiceCode] = $item->ItemInfo->invoiceCode;
  74. $hp = PayInvoice::with(["invoice"])->where(['hpNo'=>$item->ItemInfo->invoiceCode])->findOrEmpty();
  75. $data[]=['type'=>'发票池关联采购单','username'=> $hp['apply_name'],'orderCode'=>$hp['hpNo'],'companyName'=>$hp['companyName']];
  76. }
  77. }
  78. }
  79. }