MobileInfo.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. ];
  13. public function mobile(){
  14. return $this->belongsTo(Mobile::class);
  15. }
  16. protected static function init()
  17. {
  18. self::beforeWrite(function (self $info){
  19. if(isset($info['first_month_free']) && !is_numeric($info['first_month_free'])){
  20. $info['first_month_free']=Str::contains($info['first_month_free'],'是')?1:0;
  21. }
  22. });
  23. }
  24. public static function makeFreeApp(&$info){
  25. $a=[];
  26. if($info){
  27. $app=array_filter(explode('#',$info['free_app']));
  28. $existsApp=App::column('logo','name');
  29. foreach ($app as $name){
  30. $a[]=[
  31. 'name'=>$name,
  32. 'logo'=>$existsApp[$name]??self::defAppLogo()
  33. ];
  34. }
  35. }
  36. $info['free_app']=$a;
  37. }
  38. public static function defAppLogo(){
  39. return request()->domain().'/assets/img/app.png';
  40. }
  41. }