Mobile.php 833 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\common\model;
  3. use app\common\service\MobileComputer;
  4. use think\Model;
  5. /**
  6. * 配置模型
  7. */
  8. class Mobile extends Model
  9. {
  10. public function info(){
  11. return $this->hasOne(MobileInfo::class);
  12. }
  13. public static function init()
  14. {
  15. self::beforeWrite(function (self $mobile){
  16. $mobile['amount']=$mobile['amount_base']+$mobile['amount_charge'];
  17. $mobile->data(array_merge($mobile->getData(),MobileComputer::setMobile($mobile['no'])->filter()));
  18. });
  19. self::afterInsert(function (self $mobile){
  20. if(!$mobile->info()->find()){
  21. $mobile->info()->save([]);
  22. }
  23. });
  24. self::beforeInsert(function (self $mobile){
  25. $mobile['sort']=mt_rand(0,99999999);
  26. });
  27. }
  28. }