ThData.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\listener;
  4. use app\admin\model\OrderReturn;use app\admin\model\SaleReturn;class ThData
  5. {
  6. /**
  7. * 事件监听处理
  8. *
  9. * @return mixed
  10. */
  11. public function handle($event)
  12. {//
  13. \app\admin\model\ThData::create($event);
  14. $data=[];
  15. switch ($event['th_type']){
  16. case 1:
  17. $data=$this->beforeOrder($event);
  18. break;
  19. case 2:
  20. $data=$this->afterOrder($event);
  21. break;
  22. case 3:
  23. case 4:
  24. break;
  25. }
  26. if(empty($data)==false)\app\admin\model\ThStock::create($data);
  27. }
  28. //售后退货 供应商不同意退货
  29. protected function afterOrder($event){
  30. $model =new OrderReturn();
  31. $info =$model->where(["returnCode"=>$event['thCode']])->findOrEmpty();
  32. if($info->isEmpty())return[];
  33. if($info->status==5 && $info->return_tag==2){
  34. $data=[
  35. "thCode"=>$info->returnCode,
  36. "th_type"=>2,
  37. "order_type"=>$info->order_type,
  38. "supplierNo"=>$info->supplierNo,
  39. "supplierName"=>$info->supplierName,
  40. "companyNo"=>$info->companyNo,
  41. "companyName"=>$info->companyName,
  42. "customerNo"=>$info->customer_code,
  43. "customerName"=>$info->customer_name,
  44. "th_num"=>$info->error_num,
  45. "th_cgd_price"=>$event['sale_price'],
  46. "th_sale_price"=>$event['cgd_price'],
  47. "good_code"=>$info->good_code,
  48. "good_name"=>$info->good_name,
  49. "orderCode"=>$info->orderCode,
  50. 'cgdCode'=>$event['cgdNo'],
  51. "apply_id"=>$info->apply_id,
  52. "apply_name"=>$info->apply_name,
  53. ];
  54. }else $data=[];
  55. return $data;
  56. }
  57. //售前退货 供应商不同意退货
  58. protected function beforeOrder($event){
  59. $model =new SaleReturn();
  60. $info =$model->where(['returnCode'=>$event['thCode']])->findOrEmpty();
  61. if($info->isEmpty())return[];
  62. if($info->status==4 && $info->is_th==0){
  63. $data=[
  64. 'thCode'=>$info->returnCode,
  65. 'th_type'=>1,
  66. 'order_type'=>$info->order_type,
  67. 'supplierNo'=>$info->supplierNo,
  68. 'supplierName'=>$info->supplierName,
  69. 'companyNo'=>$info->companyNo,
  70. 'companyName'=>$info->companyName,
  71. 'customerNo'=>$info->customer_code,
  72. 'customerName'=>$info->customer_name,
  73. 'th_num'=>$info->num,
  74. 'th_cgd_price'=>$event['sale_price'],
  75. 'th_sale_price'=>$event['cgd_price'],
  76. 'good_code'=>$info->good_code,
  77. 'good_name'=>$info->good_name,
  78. 'orderCode'=>$info->orderCode,
  79. 'cgdCode'=>$event['cgdNo'],
  80. 'apply_id'=>$info->apply_id,
  81. 'apply_name'=>$info->apply_name,
  82. ];
  83. }else $data=[];
  84. return $data;
  85. }
  86. }