MobileInfo.php 1.1 KB

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