InvoiceItem.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\cxinv\model;
  3. use think\facade\Log;
  4. use think\model\concern\SoftDelete;
  5. class InvoiceItem extends Base{
  6. use SoftDelete;
  7. protected $createTime="createTime";
  8. protected $updateTime="updateTime";
  9. protected $autoWriteTimestamp=true;
  10. protected $deleteTime="delete_time";
  11. public function OrderInfo(){
  12. return $this->hasMany(InvoiceOrder::class,"itemId","id")->whereIn('status', [1, 2]);
  13. }
  14. public static function getNumAttr($val){
  15. return strval(floatval($val));
  16. }
  17. public static function setNumAttr($val){
  18. return floatval($val);
  19. }
  20. public static function onAfterUpdate($model){
  21. $code=$model->invoiceCode;
  22. $orderType=$model->order_type;
  23. $change = $model->getChangedData();
  24. Log::info("修改发票明细状态:".json_encode($change,JSON_UNESCAPED_UNICODE));
  25. Log::info("跟后数据:".json_encode($model->toArray(),JSON_UNESCAPED_UNICODE));
  26. if(isset($change['status'])&&in_array($change["status"],[0,1,2])){
  27. Log::info('跟后数据:'.json_encode($model->toArray(),JSON_UNESCAPED_UNICODE));
  28. $num = self::where(['invoiceCode'=>$code,'order_type'=>$orderType,'status'=>0])->count();
  29. if($orderType==2 && $num==0){
  30. $info= PayInvoice::where(['hpNo'=>$code,"status"=>11])->findOrEmpty();
  31. Log::info('跟后数据:'.json_encode( $info->toArray(),JSON_UNESCAPED_UNICODE));
  32. if(!$info->isEmpty()){
  33. $info->status=12;
  34. $info->save();
  35. }
  36. }
  37. }
  38. }
  39. //流程结束
  40. public static function rmInvoice($code,$orderType=2){
  41. $items = self::where(['invoiceCode'=>$code,'order_type'=>$orderType])->select();
  42. if(!empty($items)){
  43. $orderItems=InvoiceOrder::whereIn('itemId',$items->column('id'))->select();
  44. if(!empty($orderItems)){
  45. InvoiceOrder::whereIn('itemId',$items->column('id'))->save(["status"=>3]);
  46. }
  47. self::where(['invoiceCode'=>$code,'order_type'=>$orderType])->save(["status"=>3]);
  48. }
  49. }
  50. //退票申请
  51. public static function refund($invNo){
  52. $info = self::where(['invoiceCode'=>$invNo,'order_type'=>2])->select();
  53. if(!$info->isEmpty()){
  54. $orderItems=InvoiceOrder::whereIn('itemId',$info->column('id'))->where(["status"=>[1,2]])->select();
  55. if(!$orderItems->isEmpty()){
  56. InvoiceOrder::whereIn('itemId',$info->column('id'))->where(['status'=>[1,2]])->save(["status"=>4]);
  57. }
  58. self::where(['invoiceCode'=>$invNo,'order_type'=>2])->save(["status"=>3]);
  59. }
  60. }
  61. }