123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace app\common\model;
- use think\db\Query;
- use think\Model;
- /**
- * 配置模型
- * @method Query admin($adminId)
- */
- class MobileUserHistory extends Model
- {
- protected $type=[
- 'info'=>'json',
- ];
- protected $hidden=[
- 'info',
- ];
- protected $autoWriteTimestamp=true;
- /**
- *
- */
- public static function add($user,Mobile $mobile){
- if($user && $mobile['type']==$mobile::BEAUTI){
- $user->mobileHistory()->where('mobile_id',$mobile['id'])->delete();
- $user->mobileHistory()->save([
- 'mobile_id'=>$mobile['id'],
- 'no'=>$mobile['no'],
- 'amount'=>$mobile['amount'],
- 'network'=>$mobile['network'],
- 'province'=>$mobile['province'],
- 'city'=>$mobile['city'],
- 'info'=>$mobile->toArray(),
- ]);
- #删除50条之外的
- $ids=$user->mobileHistory()
- ->order('mobile_user_history_id','desc')
- ->limit(50)
- ->column('mobile_user_history_id');
- if(count($ids)==50){
- $id=end($ids);
- $user->mobileHistory()->where('mobile_user_history_id','<',$id)->delete();
- }
- }
- }
- }
|