<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 判断是否VIP
 */
namespace app\allwin\model;
use think\Model;

class VipCard extends Model{
    
    protected $pk     = 'id';
    protected $table  = 'ai_allwin_vipcard';
    protected $autoWriteTimestamp = true;
    protected $createTime = false;


    //添加或编辑
    public static function edit($param,int $id = 0){
        if($id){
            return self::where(['id' => $id])->update($param);
        }else{
            $param['update_time'] = time();
            return self::insert($param);
        }
    }

    //编辑创客的关联的优惠券
    public static function editCoupon(int $vip_id,$coupon_ids){
        $info = self::where(['id' => $vip_id])->find();
        if(empty($info->coupon_ids)){
            $info->coupon_ids = implode(',',$coupon_ids);
        }else{
            $coupon_ida = explode(',',$info->coupon_ids);
            $ida        = array_merge($coupon_ida,$coupon_ids);
            $info->coupon_ids = implode(',',$ida);
        }
        return $info->save();
    }
}