UNIACID, 'card_id'=>$cardId, 'type'=>$type ])->delete(); if(!empty($goodsIds)){ foreach ($goodsIds as $id){ $data[] = [ 'uniacid'=>UNIACID, 'goods_id'=>$id, 'card_id'=>$cardId, 'type'=>$type, 'createtime'=>time() ]; } } self::insertAll($data); } /** * 获取批次包含的商品 * @return void */ public static function getPrivilegeGoods($cardId,$type){ return self::with('course')->where([ 'card_id'=>$cardId, 'card_privilege.type'=>$type ])->select(); } public function card() { return $this->belongsTo('Card', 'card_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function course() { return $this->belongsTo('app\admin\model\Course', 'goods_id', 'id', [], 'RIGHT')->setEagerlyType(0); } }