12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace app\common\model;
- use app\admin\model\App;
- use think\Model;
- use Yansongda\Supports\Str;
- /**
- * 配置模型
- */
- class MobileInfo extends Model
- {
- protected $type=[
- ];
- public function mobile(){
- return $this->belongsTo(Mobile::class);
- }
- protected static function init()
- {
- self::beforeWrite(function (self $info){
- if(isset($info['first_month_free']) && !is_numeric($info['first_month_free'])){
- $info['first_month_free']=Str::contains($info['first_month_free'],'是')?1:0;
- }
- });
- }
- public static function makeFreeApp(&$info){
- $a=[];
- if($info){
- $app=array_filter(explode('#',$info['free_app']));
- $existsApp=App::column('logo','name');
- foreach ($app as $name){
- $a[]=[
- 'name'=>$name,
- 'logo'=>$existsApp[$name]??self::defAppLogo()
- ];
- }
- }
- $info['free_app']=$a;
- }
- public static function defAppLogo(){
- return request()->domain().'/assets/img/app.png';
- }
- }
|