1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\common\model;
- use app\common\service\MobileComputer;
- use think\Model;
- /**
- * 配置模型
- */
- class Mobile extends Model
- {
- public function info(){
- return $this->hasOne(MobileInfo::class);
- }
- public static function init()
- {
- self::beforeWrite(function (self $mobile){
- $mobile['amount']=$mobile['amount_base']+$mobile['amount_charge'];
- $mobile->data(array_merge($mobile->getData(),MobileComputer::setMobile($mobile['no'])->filter()));
- });
- self::afterInsert(function (self $mobile){
- if(!$mobile->info()->find()){
- $mobile->info()->save([]);
- }
- });
- self::beforeInsert(function (self $mobile){
- $mobile['sort']=mt_rand(0,99999999);
- });
- }
- }
|