ContractDistributionObserver.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. $sysAddress=CommonServer::creatServer()->getConfigValue('sys_address');
  31. $sysPrivate=CommonServer::creatServer()->getConfigValue('sys_private');
  32. $broadcastId= BroadcastServer::addBroadcast(1,$distribution->{'nbn_money'}-$distribution->{'service_money'},$sysAddress,$sysPrivate,$distribution->{'to_address'},0,$distribution->{'id'},$distribution->{'type'});
  33. if($broadcastId){
  34. $distribution->update(['broadcast_id' => $broadcastId]);
  35. }
  36. }
  37. }
  38. }
  39. }
  40. /**
  41. * 更新到数据库前触发
  42. */
  43. public function updating()
  44. {
  45. }
  46. /**
  47. * 更新到数据库后触发
  48. */
  49. public function updated()
  50. {
  51. }
  52. /**
  53. * 保存到数据库前触发(插入/更新之前,无论插入还是更新都会触发)
  54. */
  55. public function saving()
  56. {
  57. }
  58. /**
  59. * 保存到数据库后触发(插入/更新之后,无论插入还是更新都会触发)
  60. */
  61. public function saved()
  62. {
  63. }
  64. /**
  65. * 从数据库删除记录前触发
  66. */
  67. public function deleting()
  68. {
  69. }
  70. /**
  71. * 从数据库删除记录后触发
  72. */
  73. public function deleted()
  74. {
  75. }
  76. /**
  77. * 恢复软删除记录前触发
  78. */
  79. public function restoring()
  80. {
  81. }
  82. /**
  83. * 恢复软删除记录后触发
  84. */
  85. public function restored()
  86. {
  87. }
  88. }