MobileInfo.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\common\model;
  3. use app\admin\model\App;
  4. use app\service\EsMobileService;
  5. use think\Model;
  6. use Yansongda\Supports\Str;
  7. /**
  8. * 配置模型
  9. */
  10. class MobileInfo extends Model
  11. {
  12. protected $type=[
  13. 'flow_images'=>'json',
  14. ];
  15. public function mobile(){
  16. return $this->belongsTo(Mobile::class);
  17. }
  18. protected static function init()
  19. {
  20. self::beforeWrite(function (self $info){
  21. if(isset($info['first_month_free']) && !is_numeric($info['first_month_free'])){
  22. $info['first_month_free']=Str::contains($info['first_month_free'],'是')?1:0;
  23. }
  24. });
  25. self::afterInsert(function (self $info){
  26. EsMobileService::addMobile($info['mobile']);
  27. });
  28. }
  29. public static function makeFreeApp(&$info){
  30. $a=[];
  31. if($info){
  32. $app=array_filter(explode('#',$info['free_app']));
  33. $existsApp=App::column('logo','name');
  34. foreach ($app as $name){
  35. $a[]=[
  36. 'name'=>$name,
  37. 'logo'=>$existsApp[$name]??self::defAppLogo()
  38. ];
  39. }
  40. }
  41. $info['free_app']=$a;
  42. }
  43. public static function defAppLogo(){
  44. return request()->domain().'/assets/img/app.png';
  45. }
  46. }