ContractDistributionObserver.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Observers;
  3. use App\Models\ContractDistribution;
  4. use App\Servers\BroadcastServer;
  5. use App\Servers\CommonServer;
  6. class ContractDistributionObserver
  7. {
  8. /**
  9. * 获取到模型实例后触发
  10. */
  11. public function retrieved()
  12. {
  13. }
  14. /**
  15. * 插入到数据库前触发
  16. */
  17. public function creating()
  18. {
  19. }
  20. /**
  21. * 插入到数据库后触发
  22. * @param ContractDistribution $distribution
  23. */
  24. public function created(ContractDistribution $distribution)
  25. {
  26. if($distribution->{'status'}==1){
  27. if($distribution->{'nbn_money'}>0 && $distribution->{'to_address'}){
  28. //需要清分的账户进行转换
  29. if($distribution->{'nbn_money'}-$distribution->{'service_money'}>0){
  30. if($distribution->{'type'}==9){
  31. $sysAddress=CommonServer::creatServer()->getConfigValue('common_address');
  32. $sysPrivate=CommonServer::creatServer()->getConfigValue('common_private');
  33. }else{
  34. $sysAddress=CommonServer::creatServer()->getConfigValue('sys_address');
  35. $sysPrivate=CommonServer::creatServer()->getConfigValue('sys_private');
  36. }
  37. $broadcastId= BroadcastServer::addBroadcast(1,$distribution->{'nbn_money'}-$distribution->{'service_money'},$sysAddress,$sysPrivate,$distribution->{'to_address'},0,$distribution->{'id'},$distribution->{'type'});
  38. if($broadcastId){
  39. $distribution->update(['broadcast_id' => $broadcastId]);
  40. }
  41. }
  42. }
  43. }
  44. }
  45. /**
  46. * 更新到数据库前触发
  47. */
  48. public function updating()
  49. {
  50. }
  51. /**
  52. * 更新到数据库后触发
  53. */
  54. public function updated()
  55. {
  56. }
  57. /**
  58. * 保存到数据库前触发(插入/更新之前,无论插入还是更新都会触发)
  59. */
  60. public function saving()
  61. {
  62. }
  63. /**
  64. * 保存到数据库后触发(插入/更新之后,无论插入还是更新都会触发)
  65. */
  66. public function saved()
  67. {
  68. }
  69. /**
  70. * 从数据库删除记录前触发
  71. */
  72. public function deleting()
  73. {
  74. }
  75. /**
  76. * 从数据库删除记录后触发
  77. */
  78. public function deleted()
  79. {
  80. }
  81. /**
  82. * 恢复软删除记录前触发
  83. */
  84. public function restoring()
  85. {
  86. }
  87. /**
  88. * 恢复软删除记录后触发
  89. */
  90. public function restored()
  91. {
  92. }
  93. }