123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace App\Observers;
- use App\Models\ContractDistribution;
- use App\Servers\BroadcastServer;
- use App\Servers\CommonServer;
- class ContractDistributionObserver
- {
- /**
- * 获取到模型实例后触发
- */
- public function retrieved()
- {
- }
- /**
- * 插入到数据库前触发
- */
- public function creating()
- {
- }
- /**
- * 插入到数据库后触发
- * @param ContractDistribution $distribution
- */
- public function created(ContractDistribution $distribution)
- {
- if($distribution->{'status'}==1){
- if($distribution->{'nbn_money'}>0 && $distribution->{'to_address'}){
- //需要清分的账户进行转换
- if($distribution->{'nbn_money'}-$distribution->{'service_money'}>0){
- if($distribution->{'type'}==9){
- $sysAddress=CommonServer::creatServer()->getConfigValue('common_address');
- $sysPrivate=CommonServer::creatServer()->getConfigValue('common_private');
- }else{
- $sysAddress=CommonServer::creatServer()->getConfigValue('sys_address');
- $sysPrivate=CommonServer::creatServer()->getConfigValue('sys_private');
- }
- $broadcastId= BroadcastServer::addBroadcast(1,$distribution->{'nbn_money'}-$distribution->{'service_money'},$sysAddress,$sysPrivate,$distribution->{'to_address'},0,$distribution->{'id'},$distribution->{'type'});
- if($broadcastId){
- $distribution->update(['broadcast_id' => $broadcastId]);
- }
- }
- }
- }
- }
- /**
- * 更新到数据库前触发
- */
- public function updating()
- {
- }
- /**
- * 更新到数据库后触发
- */
- public function updated()
- {
- }
- /**
- * 保存到数据库前触发(插入/更新之前,无论插入还是更新都会触发)
- */
- public function saving()
- {
- }
- /**
- * 保存到数据库后触发(插入/更新之后,无论插入还是更新都会触发)
- */
- public function saved()
- {
- }
- /**
- * 从数据库删除记录前触发
- */
- public function deleting()
- {
- }
- /**
- * 从数据库删除记录后触发
- */
- public function deleted()
- {
- }
- /**
- * 恢复软删除记录前触发
- */
- public function restoring()
- {
- }
- /**
- * 恢复软删除记录后触发
- */
- public function restored()
- {
- }
- }
|