InvoiceItem.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\admin\model;
  3. use think\model\concern\SoftDelete;
  4. class InvoiceItem extends \think\Model {
  5. use SoftDelete;
  6. protected $createTime="createTime";
  7. protected $updateTime="updateTime";
  8. protected $autoWriteTimestamp=true;
  9. protected $deleteTime="delete_time";
  10. public function OrderInfo(){
  11. return $this->hasMany(InvoiceOrder::class,"itemId","id");
  12. }
  13. public static function getNumAttr($val){
  14. return strval(floatval($val));
  15. }
  16. public static function setNumAttr($val){
  17. return floatval($val);
  18. }
  19. public static function onAfterUpdate($model){
  20. $code=$model->invoiceCode;
  21. $orderType=$model->order_type;
  22. $change = $model->getChangedData();
  23. if(in_array("status",$change) && ($model->status==1||$model->status==2)){
  24. $num = self::where(['invoiceCode'=>$code,'order_type'=>$orderType,'status'=>0])->count(1);
  25. if($num==0){
  26. if($orderType==1){
  27. $info= InvoicePool::where(['invNo'=>$code,'is_del'=>0])->findOrEmpty();
  28. if(!$info->isEmpty() && $info->status==10){
  29. $info->status=11;
  30. $info->save();
  31. }
  32. }
  33. if($orderType==2){
  34. $info= PayInvoice::where(['hpNo'=>$code,'is_del'=>0])->findOrEmpty();
  35. if(!$info->isEmpty()){
  36. $pay = Pay::where(['payNo'=>$info->payNo,'is_del'=>0])->findOrEmpty();
  37. if(!$pay->isEmpty() && $pay->status==2 &&$info->status==11){
  38. $info->status=12;
  39. $info->save();
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }
  46. public static function rmInvoice($code,$orderType){
  47. $items = self::where(['invoiceCode'=>$code,'order_type'=>$orderType])->select();
  48. if(!empty($items)){
  49. $orderItems=InvoiceOrder::whereIn('itemId',$items->column('id'))->select();
  50. if(!empty($orderItems)){
  51. InvoiceOrder::whereIn('itemId',$items->column('id'))->save(["status"=>3]);
  52. }
  53. self::where(['invoiceCode'=>$code,'order_type'=>$orderType])->save(["status"=>3]);
  54. }
  55. }
  56. public static function CopyItem($invNo,$hpNo){
  57. $info = self::where(['invoiceCode'=>$invNo,'order_type'=>1])->select();
  58. if(!$info->isEmpty()){
  59. foreach($info as $item){
  60. $temp = $item->toArray();
  61. $temp['invoiceCode']=$hpNo;
  62. $temp['order_type']=2;
  63. unset($temp['id']);
  64. $up = self::create($temp);
  65. if($up->id>0){
  66. $orders = InvoiceOrder::where(['itemId'=>$item->id])->select();
  67. if(!$orders->isEmpty()){
  68. InvoiceOrder::create(array_map(function ($items)use ($up){
  69. $items['itemId']=$up->id;
  70. unset($items['id']);
  71. return $item;
  72. },$orders->toArray()));
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }