InvoiceItem.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\cxinv\model;
  3. use think\facade\Log;
  4. use think\Model;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 $model){
  21. $code=$model->invoiceCode;
  22. $orderType=$model->order_type;
  23. $change = $model->getChangedData();
  24. Log::info("InvoiceItem修改发票明细:onAfterUpdate:".json_encode($change,JSON_UNESCAPED_UNICODE));
  25. Log::info("InvoiceItem数据:onAfterUpdate:".json_encode($model->toArray(),JSON_UNESCAPED_UNICODE));
  26. if(isset($change['status'])&&in_array($change["status"],[0,1,2])){
  27. Log::info('InvoiceItem数据:onAfterUpdate:'.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('InvoiceItem数据:onAfterUpdate:'.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. foreach ($orderItems as $key=>$val){
  46. $val->save(['status'=>3]);
  47. }
  48. }
  49. self::where(['invoiceCode'=>$code,'order_type'=>$orderType])->save(["status"=>3]);
  50. }
  51. }
  52. //退票申请
  53. public static function refund($invNo){
  54. $info = self::where(['invoiceCode'=>$invNo,'order_type'=>2])->select();
  55. Log::info("退票申请:".json_encode($info->toArray(),JSON_UNESCAPED_UNICODE));
  56. if(!$info->isEmpty()){
  57. $orderItems=InvoiceOrder::whereIn('itemId',$info->column('id'))->where(["status"=>[1,2]])->select();
  58. Log::info("退票申请:".json_encode($orderItems->toArray(),JSON_UNESCAPED_UNICODE));
  59. if(!$orderItems->isEmpty()){
  60. foreach ($orderItems as $key=>$val){
  61. $val->save(["status"=>4]);
  62. }
  63. Log::info("caigou:".InvoiceOrder::getLastSql());
  64. }
  65. self::where(['invoiceCode'=>$invNo,'order_type'=>2])->save(["status"=>3]);
  66. }
  67. }
  68. }